Skip to content

Fix the JIT instantiation of the NAX head-dim split attention kernel - #48

Merged
Gajesh2007 merged 1 commit into
mainfrom
hotfix/0.10.2-jit-nax-dsplit
Oct 26, 2026
Merged

Gajesh2007 merged 1 commit into
mainfrom
hotfix/0.10.2-jit-nax-dsplit

Conversation

@jonathan308

Copy link
Copy Markdown

Summary

get_steel_attention_nax_kernel passed bv to both attention_nax and attention_nax_dsplit. attention_nax gained a BV template parameter in the upstream merge (#38); attention_nax_dsplit has none (its value head dim is BD). With bv in the list, every later argument shifts by one, an integer lands in the MaskType slot, and the runtime compile always fails:

[metal::Device] Unable to build metal library from source
steel_attention_nax.h:950: error: explicit instantiation of 'attention_nax_dsplit' does not refer to a function template ...

JIT builds (mlx-swift, and so Darkbloom provider 0.10.2) compile this kernel at runtime on NAX GPUs (M5) for full attention with head dim 256 or 512 and at least 1,024 query tokens. The error trapped the process, and provider 0.10.2 crashed on M5 Macs serving Gemma 4 and Qwen 3.5/3.6/3.8. Builds that use the precompiled metallib were unaffected, because steel_attention_nax.metal instantiates the split kernel without bv.

The fix passes the split kernel the same arguments as its metallib instantiation. The non-split kernel is unchanged.

Before and after

flowchart LR
  subgraph Before
    A1["get_steel_attention_nax_kernel(split_d)"] --> B1["attention_nax_dsplit<T, bq, bk, bd, bv, wm, wn, mask>"] --> C1["compile error -> throw -> process trap"]
  end
  subgraph After
    A2["get_steel_attention_nax_kernel(split_d)"] --> B2["attention_nax_dsplit<T, bq, bk, bd, wm, wn, mask>"] --> C2["library + pipeline built"]
  end
Loading

Validation

  • Runtime compile of the exact JIT source (metal::utils() + metal::steel_attention_nax() + template definition, language 4.1), on an M3 Ultra and an M5 Ultra: the shipped dsplit instantiations for head dim 256 and 512 fail with the error above; the fixed ones compile, and on the M5 their pipelines build (256 threads, 16 KB threadgroup memory).
  • End to end on an M5 Ultra (mlx-swift eedca444, real MLXFast.scaledDotProductAttention, bf16, against a float32 reference):
    • before: Trace/BPT trap: 5 with the error above on the first head-dim-256 call;
    • after: 6 of 6 shapes pass (max abs error ≤ 0.0089): D256 causal 1024, D256 GQA 16/4 causal 2048, D256 causal 1024 after 512 cached keys, D256 array mask 1024, D512 GQA 16/8 causal 2048, D512 causal 1024 × 32 heads.
  • This repository's CI builds without JIT, so it does not compile jit_kernels.cpp; mlx-swift and d-inference CI do.

Pinned for the provider hotfix from branch hotfix/0.10.2-jit-nax-dsplit (31f550af, on ff4bb35b); this PR brings the same commit to main.

get_steel_attention_nax_kernel passed bv to both attention_nax and
attention_nax_dsplit. attention_nax gained a BV parameter in the upstream
merge (#38); attention_nax_dsplit has none (its value head dim is BD). With
bv in the list, every later argument shifts by one, an integer lands in the
MaskType slot, and the library fails to compile:

  explicit instantiation of 'attention_nax_dsplit' does not refer to a
  function template ...

JIT builds (mlx-swift) compile this kernel at runtime for full attention
with head dim 256 or 512 and at least 1,024 query tokens on NAX GPUs, so the
compile error surfaced as "Unable to build metal library from source" and
the caller's process exited. Builds that use the precompiled metallib were
unaffected, because steel_attention_nax.metal instantiates the split kernel
without bv.

Pass the split kernel the same arguments as its metallib instantiation. The
non-split kernel is unchanged.
@Gajesh2007
Gajesh2007 merged commit 6bc9de5 into main Oct 26, 2026
16 of 17 checks passed
@Gajesh2007
Gajesh2007 deleted the hotfix/0.10.2-jit-nax-dsplit branch October 26, 2026 22:59
@jonathan308
jonathan308 restored the hotfix/0.10.2-jit-nax-dsplit branch October 26, 2026 23:00
jonathan308 added a commit that referenced this pull request Oct 27, 2026
…nto the JACCL guard branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 27, 2026
…ce-ordering branch

Main's head-dim split NAX attention JIT fix (#48) and this branch's ce21a37 fix the same bug; get_steel_attention_nax_kernel now reads exactly as main's (main's comment and argument list), so the branch no longer differs from main there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit that referenced this pull request Oct 27, 2026
main's #48 changed mlx/backend/metal/jit_kernels.cpp without a fork.yaml section, so the fork.yaml gate failed on main and on every PR based on it. The new section explains the change: the JIT source passes attention_nax_dsplit the same template arguments as its metallib instantiation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jonathan308 added a commit to Layr-Labs/d-inference that referenced this pull request Oct 28, 2026
…ares

Layr-Labs/mlx-swift-lm#368 was squash-merged as 2beb401f, so this branch's
former SDK pin 76ff231b (#368's head) is not on SDK main. Every gitlink now
points at a commit on its fork's main:

- libs/mlx-swift-lm 76ff231b -> 2beb401f, the tip of SDK main and the #368
  squash. Merging 76ff231b into the previous main (25bcd63f) gives exactly
  2beb401f's tree, so #368 (demandedLatestCheckpointMinimumTokens) is
  unchanged. The pin also brings what SDK main gained since master's
  aee6ebb6: the tensor-parallel engine (#308), Qwen tensor batching (#352)
  and the optional stop-string scope (#369).
- libs/mlx-swift 4926d3d9 -> c633d221, the revision 2beb401f's Package.swift
  declares; mlx-swift main (52c36f86) has the same tree. SDK main calls
  mlx-swift APIs that 4926d3d9 lacks (MLXArray.sharingArray, the
  fencedInputs argument of MLXFast.metalKernel). The nested mlx-c moves
  from 004c735f to 2ac897e3 with it.
- libs/mlx 31f550af -> 72dffa2d, the nested copy that Cmlx compiles at
  c633d221 (Source/Cmlx/mlx); mlx main (f24d7e63) has the same tree.
  72dffa2d keeps the 0.10.3 M5 NAX head-dim split JIT fix: 31f550af is not
  its ancestor, but that fix's squash on mlx main (6bc9de5b, Layr-Labs/mlx#48,
  identical patch ID) is, and its jit_kernels.cpp change is intact.

#1645 pins the same mlx-swift and mlx commits.

Provider follow-ups for the SDK's new enum cases, identical to #1645's
(46f7ae9 and 2185dfe) so the two branches merge without conflicts:
- MLXServerGenerationEvent.logprobs is token metadata. The GLM and JSON
  answer-format observers and seven test helpers treat it like .info. No SDK
  engine or provider bridge emits it today; the provider sends logprobs
  through EngineV2LogprobsChannel.
- MLXOpenAIServiceError.responseFormatCutOffByMaxTokens, which the SDK split
  from invalidResponseFormatOutput for a structured answer cut off by
  max_tokens, keeps that case's 422 and retryable classification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gajesh2007 pushed a commit to Layr-Labs/d-inference that referenced this pull request Oct 29, 2026
…prompt end (−16.5% follow-up TTFT) (#1643)

* perf(provider): restore dense Qwen conversations from just below the prompt end

A dense Qwen 3.5/3.8 request served alone prefills in 4,096-token
stripes, so its deepest SSD checkpoint was the last full stripe end, up
to 4,095 tokens before the prompt end. The next turn of the
conversation re-prefilled that gap.

With its paged complete store, the engine now sets the SDK's
demandedLatestCheckpointMinimumTokens to the store floor. A request the
store would write then also ends a prefill range at the deepest
256-aligned boundary at least 64 tokens below its prompt end, when that
saves at least the floor. Busy providers, which prefill in 512-token
chunks beside decoding requests, keep the ordinary geometry.

Six-turn conversation from 30K to 55K tokens, Qwen3.5-9B, M3 Ultra, two
runs per arm: the mean summed time to first token of the five follow-up
turns fell from 57.38 s to 47.88 s (-16.5%), with outputs identical to
master on every turn. SSD bytes rose 2.6% (2.71 GB to 2.78 GB) for the
same 7 files.

Requires mlx-swift-lm 05c7ca7e (feat/demanded-latest-checkpoint).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(provider): pin mlx-swift-lm 76ff231b (docs for the end-of-prompt boundary)

The SDK change adds demandedLatestCheckpointMinimumTokens to the
retention doc and shortens its code comments. No code changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Repin the SDK to the merged #368 (2beb401f) and the MLX stack it declares

Layr-Labs/mlx-swift-lm#368 was squash-merged as 2beb401f, so this branch's
former SDK pin 76ff231b (#368's head) is not on SDK main. Every gitlink now
points at a commit on its fork's main:

- libs/mlx-swift-lm 76ff231b -> 2beb401f, the tip of SDK main and the #368
  squash. Merging 76ff231b into the previous main (25bcd63f) gives exactly
  2beb401f's tree, so #368 (demandedLatestCheckpointMinimumTokens) is
  unchanged. The pin also brings what SDK main gained since master's
  aee6ebb6: the tensor-parallel engine (#308), Qwen tensor batching (#352)
  and the optional stop-string scope (#369).
- libs/mlx-swift 4926d3d9 -> c633d221, the revision 2beb401f's Package.swift
  declares; mlx-swift main (52c36f86) has the same tree. SDK main calls
  mlx-swift APIs that 4926d3d9 lacks (MLXArray.sharingArray, the
  fencedInputs argument of MLXFast.metalKernel). The nested mlx-c moves
  from 004c735f to 2ac897e3 with it.
- libs/mlx 31f550af -> 72dffa2d, the nested copy that Cmlx compiles at
  c633d221 (Source/Cmlx/mlx); mlx main (f24d7e63) has the same tree.
  72dffa2d keeps the 0.10.3 M5 NAX head-dim split JIT fix: 31f550af is not
  its ancestor, but that fix's squash on mlx main (6bc9de5b, Layr-Labs/mlx#48,
  identical patch ID) is, and its jit_kernels.cpp change is intact.

#1645 pins the same mlx-swift and mlx commits.

Provider follow-ups for the SDK's new enum cases, identical to #1645's
(46f7ae9 and 2185dfe) so the two branches merge without conflicts:
- MLXServerGenerationEvent.logprobs is token metadata. The GLM and JSON
  answer-format observers and seven test helpers treat it like .info. No SDK
  engine or provider bridge emits it today; the provider sends logprobs
  through EngineV2LogprobsChannel.
- MLXOpenAIServiceError.responseFormatCutOffByMaxTokens, which the SDK split
  from invalidResponseFormatOutput for a structured answer cut off by
  max_tokens, keeps that case's 422 and retryable classification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: jonathan308 <5055076+jonathan308@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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