Skip to content

chore(release): v0.6.9 — Gemma 4 batched-attention NaN fix - #354

Merged
Gajesh2007 merged 1 commit into
masterfrom
chore/v0.6.9-ragged-batch-fix
Jun 15, 2026
Merged

Gajesh2007 merged 1 commit into
masterfrom
chore/v0.6.9-ragged-batch-fix

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Cuts v0.6.9, advancing the `libs/mlx-swift-lm` submodule to ee2a921 (mlx-swift-lm#38) and bumping the provider version 0.6.8 → 0.6.9.

The bug it fixes

`gemma-4-26b` produced token-salad / repetition garbage on some responses under concurrent load — e.g. "I's a marathon, but I's a marathon, just a marathon…" or collapsing into a repeated token. Reproduced on the live fleet (targeted at a busy provider) and isolated to batched decoding: it survives greedy, top-k/top-p, and repetition_penalty because the logits are NaN before sampling.

Root cause: continuous batching co-prefills requests of different prompt lengths in one forward pass; the cache left-pads the short rows and the attention mask blocks their padding slots, making those rows' padding-position queries fully masked. The hand-rolled `gemma4AttentionFallback` softmaxed an all-`-inf` row to NaN, and `0 * NaN = NaN` in the value matmul propagated NaN into every row of the batch → all-NaN logits → garbage. Measured: a left-padded row's prefill logits were 1024/1024 NaN before, 0 after.

The submodule PR maps post-softmax NaN→0 (matching `MLXFast.scaledDotProductAttention`, used by the decode path and mlx-lm). No behavior change for solo / uniform-length batches.

Verification (in mlx-swift-lm#38)

  • New CI regression test (`raggedBatchGreedyParityTinyModel`, tiny random-weight model, no download): fails pre-fix (NaN → token 0), passes after; verified to fail when the fix is reverted.
  • Real `gemma-4-26b`: before = garbage on left-padded rows; after = coherent text, batched rows match solo decode.
  • All existing MTP / batched parity suites (B=2/4) pass.

Notes

  • Coordinator-only change is not required; this is a provider-side inference fix that takes effect as the fleet rolls to 0.6.9.
  • The bug predates bug: Benchmark fails for every model #35, so a submodule pin rollback would not have fixed it.

Release: after merge, tag `v0.6.9` on master to trigger the Swift release workflow.

🤖 Generated with Claude Code


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

- Advance libs/mlx-swift-lm to ee2a921 (mlx-swift-lm#38): NaN-guard fully-masked
  query rows in gemma4AttentionFallback. When continuous batching co-prefills
  requests of different lengths, short rows are left-padded and their padding
  queries become fully masked; the manual batched-attention fallback softmaxed
  those all-`-inf` rows to NaN and `0 * NaN` in the value matmul propagated NaN
  into every row -> all-NaN logits -> token-salad / repetition on some responses
  under concurrent load. Decode path and solo/uniform batches were unaffected.
- Bump provider version 0.6.8 -> 0.6.9.
@vercel

vercel Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
d-inference Ready Ready Preview Jun 15, 2026 4:59pm
d-inference-console-ui-dev Ready Ready Preview Jun 15, 2026 4:59pm
d-inference-landing Ready Ready Preview Jun 15, 2026 4:59pm

Request Review

@ethenotethan ethenotethan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review — Layr-Labs/d-inference#

Verdict: COMMENT

Security — ✅ No issues found

Performance — ✅ No issues found

Type_diligence — ✅ No issues found

Additive_complexity — ✅ No issues found

✅ All four passes clean. No issues found.

🤖 Automated review by Centaur · DAR-186

@github-actions

Copy link
Copy Markdown
Contributor

No directly modeled files changed; two files fall outside current threat model coverage — review recommended before merge.


Trust boundaries touched

None of the changed files are listed under affected_files in any threat model entry. However, both files are functionally adjacent to TB-007 (Provider Inference Engine) and TB-003 (Provider Operator vs. Process).


Threat coverage

Threat Assessment
T-028 (GPU residual data) ℹ️ libs/mlx-swift-lm is the MLX inference library; changes here are directly adjacent but not formally covered. Any change to buffer allocation, KV-cache management, or activation tensor lifecycle could affect GPU-side residual data exposure.
T-027 / T-012 (weight hash) ℹ️ libs/mlx-swift-lm owns model-weight loading at the lowest layer. Changes to how safetensors/npz/bin files are read or cached could silently affect what WeightHasher.swift actually hashes vs. what gets executed.
T-008 (plaintext SSE fallback) ℹ️ ProviderCore.swift is the top-level module entry point. Changes here could reorder initialization (e.g. PT_DENY_ATTACH, SIP check, persistent SE key setup) in ways that open a startup window before security controls are active.

New attack surface not covered by an existing threat

  1. libs/mlx-swift-lm (submodule or vendored library) — If this is a Git submodule bump or a local fork of mlx-swift, the diff reviewer cannot see what changed inside the library from this PR alone. MLX controls:

    • GPU buffer allocation and reuse between requests (T-028, open: no Metal memset between tenants).
    • Tokenizer and weight-file I/O (T-027).
    • Any new Python/Swift bridging or network calls introduced in an upstream bump would represent entirely new, unmodeled attack surface (e.g. a model-loading RPC or hub-download path added upstream).
    • Recommendation: treat a submodule bump to libs/mlx-swift-lm as requiring explicit diff review of upstream changes, and add libs/mlx-swift-lm to the affected_files lists for T-027, T-028, and T-007 in the threat model.
  2. ProviderCore.swift module initializer ordering — If this file bootstraps the inference pipeline, any reordering of security-control initialization (anti-debug, SIP check, SE key load, prefix-cache setup) before the first WebSocket frame is sent could widen the startup window described under T-013 and T-034. This file should be added to affected_files for T-013, T-014, T-015, and T-034.


Threat model update recommended

The following additions should be made to keep the threat model current:

# Add to T-027, T-028, T-007 affected_files:
- libs/mlx-swift-lm

# Add to T-013, T-014, T-015, T-034 affected_files:
- provider-swift/Sources/ProviderCore/ProviderCore.swift

No existing SEC-* findings are resolved by this PR. No existing mitigations appear to be weakened based on the file paths alone, but the libs/mlx-swift-lm change cannot be fully assessed without inspecting its contents — if it is a submodule bump, the upstream delta must be reviewed before approval.


🔐 Threat model: docs/threat-model.yaml · Updates on each push to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48163349f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// propagated into every row -> token-salad/repetition under concurrent load.
// Fixed in mlx-swift-lm#38 (gemma4AttentionFallback NaN-guard); submodule
// pin advanced to ee2a921.
public static let version = "0.6.9"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bump the coordinator fallback version with the provider release

This version bump leaves coordinator/api/server.go hardcoded at LatestProviderVersion = "0.6.4", and handleVersion uses that value whenever no release record is registered. In dev/in-memory coordinators, an installed 0.6.8 provider will therefore be told the latest version is still 0.6.4 and will not auto-update to this 0.6.9 NaN fix, so concurrent Gemma 4 experiments can keep running on the buggy submodule. Please update the fallback alongside this provider version bump.

Useful? React with 👍 / 👎.

jonathan308 added a commit that referenced this pull request Oct 24, 2026
…SDK main)

Pins libs/mlx-swift-lm to Layr-Labs/mlx-swift-lm#356's head efd38585:
#342 + #354 + #353 + #355 merged with SDK main 755bdf67, which carries
#339 (upstream sync 2026-10-22), #349 and #348. The SDK pins mlx-swift
6c31f9f1 (#349: compiled traces keyed by the task's default stream), so
libs/mlx-swift moves 67dc7528 -> 6c31f9f1 (nested mlx 83dbdb04, mlx-c
cb19abf6) and libs/mlx moves ad4745a2 -> 83dbdb04 in lockstep; the
provider links the local mlx-swift, and scripts/fetch-metallib.sh builds
the metallib from its nested mlx (ca34a2e8..., was 156f2624...).
provider-swift/Package.resolved is unchanged.

API adaptations, each the minimal change to the upstream API:
- MLXLLM.Gemma4AssistantDraftModel: upstream added an MLXVLM type of the
  same name; the provider keeps the fork's MLXLLM drafter it always used
  (EngineV2MTPAssistant, ProviderBenchmark BackendParityHarness and
  MTPProductionSession).
- LanguageModel.prepare(_:cache:state:prefill:) replaces
  prepare(_:cache:windowSize:): GLM5NextProtectedModel forwards the new
  arguments to its root (no provider caller; serving runs through the
  native steppable), and 25 test stubs take the new signature.
- newCache(parameters:) throws: GLM5NextProtectedModel forwards with try;
  ThroughputSweep's default caches use try? (nil parameters cannot fail
  validation, as the SDK's own probes do).
- UserInput.Image and UserInput.Video are structs with a source enum:
  MediaIngest's realized-extent check and the MiMo encoded-media ingress
  match on .source; 9 test patterns likewise.
- Qwen35Model.sanitize(weights:) throws: EngineV2VLMTextExtraction.
  reKeyedQwenTargetWeights propagates it (its caller already throws).
- Generation gained .rejectedToolCall: ModelBenchmark ignores it, as it
  ignores .toolCall.
- GatedDeltaPrefill moved from MLXLLM to MLXLMCommon: the LaunchAgent
  passthrough test imports MLXLMCommon @testable; LaunchAgent's comment
  names the new module; four docs cite
  Libraries/MLXLMCommon/GatedDelta.swift (docs-check follows the pin).

This branch had an error being deployed

1 failed and 3 active deployments
Preview – d-inference-console-ui-dev — 48163349 Deployed Jun 15, 2026 by vercel[bot]
Preview – d-inference — 48163349 Deployed Jun 15, 2026 by vercel[bot]
Preview – d-inference-landing — 48163349 Deployed Jun 15, 2026 by vercel[bot]
benchmarks — 48163349 Deployed Jun 15, 2026 by Gajesh2007 via E2E Benchmarks #941
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants