Repository navigation
Document the Qwen GDN prompt kernels and forward their rollback to launchd - #1536
Conversation
Qwen3.5/3.6/3.8 and Bonsai 2 prompt windows of 16 or more unmasked positions run their Gated DeltaNet recurrence on four-row kernels that reproduce the stock gated_delta_step bit for bit, so outputs and recurrent checkpoints do not change. On M5 Ultra the recurrence is 1.64x (9B and 35B-A3B geometry) and 1.70x (27B geometry) faster per layer at a 4,096-token chunk. The first prompt window of each kernel instantiation checks bit parity on the GPU and keeps the stock kernel where no candidate matches. DARKBLOOM_TTFT_GDN_BLOCKED=0 restores the stock kernel; the configuration reference and the inference architecture page describe the switch and the check. The SDK commit sits on mlx-swift-lm main, which already carries mlx-swift-lm #316 and the Nemotron Super stack (mlx-swift-lm #312, #315, #317). Its Package.swift requires mlx-swift 81f58d79, whose GPU.CommandBufferLimits (mlx-swift #57) MLXLMCommon uses, so libs/mlx-swift moves to that commit and libs/mlx to its nested MLX 71271f08 (mlx #36). That MLX change is host-side only: mlx.metallib built from it is byte-identical to the current one (SHA-256 fb1ba8f9...). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves libs/mlx-swift-lm from 1c9c255e to 1ec827e0. The two added SDK commits change only comments and the formatting of one string literal (format Qwen4ExpGDNBlocked.swift; correct two GDN kernel-selection comments), so no code or kernel changes. docs/architecture/inference.md: the Gated DeltaNet paragraph now follows the native Qwen3.5 vision paragraph instead of separating it from the Bonsai adapter paragraph it was written with, and says that the probe tries the candidates in order. The changelog fragment gives the cold time-to-first-token saving as the estimate it is, and says that a new kernel runs only where the GPU check finds it bit-exact. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves libs/mlx-swift-lm from 1ec827e0 to 2debb5e8. The added SDK commit gives the prompt-kernel dispatch the value head width once instead of twice and adds a test of the bit comparator that the probe relies on. The kernel sources, the probe and every dispatch decision are unchanged. docs/architecture/inference.md now names the two kernels the probe tries (packed, then rows), says that every process probes each kernel instantiation once, and says which kernels the switch can force. docs/reference/configuration.md moves the DARKBLOOM_TTFT_GDN_BLOCKED row after DARKBLOOM_GEMMA4_PREFILL_CHUNK_EVAL, the other model-specific prefill control, so that it no longer splits the MTP rows. The row's text is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Refresh before review. master (#1519) now pins mlx-swift 67dc7528 and MLX ad4745a2; keep those, and pin libs/mlx-swift-lm to the SDK branch's merge of main (f4be1ba1), which carries the GDN kernels on top of the SDK commit master pins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Threat model review — advisoryReviewed head Reviewers: anthropic/claude-sonnet-5.5: first pass completed; anthropic/claude-opus-5.5: selected depth completed (17 batches); openai/gpt-6.1-sol: not needed by escalation policy No actionable findings in the reviewed text. This is not a security approval. Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging. Scan completed; human review required. Coverage: 51/51 source units; cross-file integration complete. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned. Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 7 reused batch(es), 0 provider cache-hit tokens. Saved findings and earlier report · Historical findings are not confirmed resolved. Bedrock: 28 request(s), 1342576 uncached + 0 cache-read + 0 cache-write input / 19466 output tokens; 0 request(s) with unknown usage. OpenRouter backup used 0 time(s). Dollar amounts above cover OpenRouter only; AWS billing is reconciled separately. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e28b8573b
ℹ️ 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".
Layr-Labs/mlx-swift-lm#324 squash-merged as 921bfa69 ("Run Qwen GDN prompt windows on bit-exact four-row kernels (#324)"). Move the gitlink from the PR branch head f4be1ba1 to that commit on SDK main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refresh before review: master moved (Nemotron Super and SDK pin updates; it now pins SDK 0351444e, mlx-swift 67dc7528 and MLX ad4745a2). Keep master's mlx-swift and MLX pins and pin libs/mlx-swift-lm to 921bfa69 (the paired SDK PR head). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refresh before review: master moved (Nemotron Super and SDK pin updates; it now pins SDK 889fe3cc, mlx-swift 67dc7528 and MLX ad4745a2). Keep master's mlx-swift and MLX pins and pin libs/mlx-swift-lm to . Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK keeps a four-row Qwen GDN prompt kernel wherever its parity probe finds it bit-exact on the GPU; the probe compares bits, not speed. Where a kept kernel is slower, DARKBLOOM_TTFT_GDN_BLOCKED=0 is the recovery, but launchd does not inherit the installing shell, so the export reached only a foreground provider: the background provider job kept probing, and restarts and watchdog recovery reuse its saved plist. Add the key to LaunchAgent.inferencePassthroughEnvKeys so darkbloom start persists it into the provider plist. The watchdog plist stays without it: it never runs inference. The key is spelled out because its SDK reader (GatedDeltaPrefill.mode) is internal to MLXLLM. The new LaunchAgentEnvironmentTests case reads the SDK's own key and parser through @testable import MLXLLM: for unset, empty, 0, " OFF ", packed, rows and an unknown value, the provider plist resolves the same mode as the foreground shell, so renaming the key fails it. Docs: the configuration row says the key is forwarded and that the probe does not compare speed; the CLI reference lists it among the forwarded variables; the changelog fragment no longer says the LaunchAgent does not receive it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/AGENTS.md section 7 has native-inference changes move architecture/hardware-support.md with architecture/inference.md and record an external capacity compatibility review; this PR only touched inference.md. Add a "GDN prompt kernels by GPU" section after "Cross-repository agreement": - Qualification: no chip list selects the kernel. In each process the first eligible window of each kernel instantiation compares the candidates with gated_delta_step on a fixed 32-position window on that GPU and keeps the first bit-exact one, or the stock kernel (GatedDeltaPrefill.probe), so every chip keeps the stock kernel's bits. The probe does not compare speed, which is what DARKBLOOM_TTFT_GDN_BLOCKED restores. - Measured: M5 Ultra per-layer recurrence 1.45-1.70x faster, with packed kept at the 9B, 27B and 35B-A3B head geometries; M3 Ultra Qwen3.5-9B cold prefill 1.1-1.3% less time at 2K/8K/32K (A/B/A on one binary). Every other GPU is unmeasured; GatedDeltaPrefillTests prints per-layer timings with DARKBLOOM_GDN_PREFILL_BENCH=1. - Capacity: the selected kernel has the stock kernel's inputs, outputs and fp32 state; the probe is transient, once per instantiation and process, at most about 16 MiB at Qwen3.8-27B (four 3 MiB fp32 states and a 32-position window). No full-load quotation, activation floor, KV grant or reported capacity field changes, so platform admission needs no change. The changelog fragment's "Speed on M1-M4 GPUs is unmeasured" now records the M3 Ultra measurement. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 251202f41d
ℹ️ 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".
The GDN rollback forwarding and the hardware-support GPU qualification were committed at 2026-10-22T01:10:38Z, but the pages they edit still said 2026-10-21. Restamp them with `make docs-stamp` (today, UTC): - docs/architecture/hardware-support.md - docs/provider/cli-reference.md - docs/reference/configuration.md docs/architecture/inference.md keeps 2026-10-21. This branch last edited it at 2026-10-21T23:11:14Z; the later merges from master changed it only by bringing in master's own content, with no hand edits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
The bit-exact Qwen GDN prompt kernels (Layr-Labs/mlx-swift-lm#324) already reached
masterthrough #1535, whoselibs/mlx-swift-lmpin889fe3cccontains #324. After the rebase this PR moves no submodule. It documents the kernels thatmasternow runs, and it forwards their rollback switch to the launchd provider job.The kernels: gated DeltaNet prompt windows of at least 16 unmasked positions in
qwen3_5,qwen3_5_moeandprism_hadamard_qwen35models run a four-row recurrence kernel, 1.45-1.70x faster per layer on M5 Ultra. The first such window of each kernel instantiation checks on the GPU that the kernel reproduces the stockgated_delta_stepbit for bit, and otherwise keeps the stock kernel. Outputs and recurrent checkpoint state do not change.DARKBLOOM_TTFT_GDN_BLOCKEDto the launchd provider job, sodarkbloom startcarries the stock-kernel rollback (0) into the background providerprovider-swift/Sources/ProviderCore/Service/LaunchAgent.swiftGatedDeltaPrefill.Modeparserprovider-swift/Tests/ProviderCoreTests/Service/LaunchAgentRestartTests.swiftdocs/architecture/inference.mddocs/architecture/hardware-support.mdDARKBLOOM_TTFT_GDN_BLOCKEDrows: values, default, reading symbol, LaunchAgent forwardingdocs/reference/configuration.md,docs/provider/cli-reference.mdchangelog.d/qwen-gdn-prompt-kernel.mdBefore
flowchart TB subgraph PB["Behavior on master since #1535"] direction LR ob["Operator exports<br/>DARKBLOOM_TTFT_GDN_BLOCKED=0<br/>then runs darkbloom start"]:::input --> lb["LaunchAgent plist<br/>key not forwarded"]:::gap lb --> jb["launchd provider job<br/>four-row GDN kernels stay on"]:::gap fb["Foreground darkbloom<br/>or benchmark"]:::input --> sb["SDK GatedDeltaPrefill.mode<br/>reads the switch: stock kernel"]:::code end subgraph QB["Code and docs"] direction LR kb["LaunchAgent.inferencePassthroughEnvKeys<br/>no GDN key"]:::gap db["No docs or changelog<br/>for the GDN prompt kernels"]:::gap end PB ~~~ QB style PB fill:#f8fafc,stroke:#64748b,color:#0f172a style QB fill:#f8fafc,stroke:#64748b,color:#0f172a classDef input fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a classDef code fill:#e0e7ff,stroke:#4338ca,color:#1e1b4b classDef gap fill:#fee2e2,stroke:#b91c1c,color:#7f1d1dAfter
flowchart TB subgraph PA["Behavior with this PR"] direction LR oa["Operator exports<br/>DARKBLOOM_TTFT_GDN_BLOCKED=0<br/>then runs darkbloom start"]:::input --> la["LaunchAgent plist<br/>carries the key"]:::new la --> ja["launchd provider job<br/>SDK reads the switch: stock kernel"]:::new fa["Foreground darkbloom<br/>or benchmark"]:::input --> sa["SDK GatedDeltaPrefill.mode<br/>reads the switch: stock kernel"]:::code end subgraph QA["Code and docs"] direction LR ka["LaunchAgent.inferencePassthroughEnvKeys<br/>+ DARKBLOOM_TTFT_GDN_BLOCKED"]:::new --> ta["Test: forwarded value parses with<br/>the SDK's GatedDeltaPrefill.Mode"]:::new da["inference.md, hardware-support.md,<br/>configuration.md, cli-reference.md,<br/>changelog.d fragment"]:::new end PA ~~~ QA style PA fill:#f8fafc,stroke:#64748b,color:#0f172a style QA fill:#f8fafc,stroke:#64748b,color:#0f172a classDef input fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a classDef code fill:#e0e7ff,stroke:#4338ca,color:#1e1b4b classDef new fill:#dcfce7,stroke:#15803d,color:#14532dLegend: blue is operator input, indigo is unchanged code, red is the gap on
master, green is what this PR adds. The kernel behavior itself (probe, four-row kernel, unchanged checkpoint bits) is already onmasterand is described in the sections below.Measured effect (M5 Ultra, 80-core GPU)
Context for the documented kernels, which
masteralready runs. These measurements were taken when this PR still carried the pin bump.Measured by the implementer on the pre-rebase build: SDK
a405b61eon14661d9b. The kernel, dispatch and probe code in1c9c255eis byte-identical. The three later SDK commits change comments, the indentation of one string literal whose value is unchanged (1c511d29,1ec827e0), and one parameter of the dispatch helper plus a test (2debb5e8). The kernel sources, the probe and every dispatch decision are unchanged.--teacher-forced-input)masterbuild, stock kernelplainTop1tokens; only the executable hash and memory counters differ--runtime-generation)DARKBLOOM_TTFT_GDN_BLOCKED=0--scheduler-prefill, 1 iteration per arm, one GPU ticket, shared GPU)=0(stock)The end-to-end runs are single samples on a GPU shared with other jobs. Run 1 disagrees with run 2 in both directions. The 3-4% claim rests on the per-layer measurement and the estimate; run 2 agrees with it.
Side effects, verified in code
The Metal library and carried-change rows describe the pins
mastertook with #1535; this PR no longer changes them.scripts/fetch-metallib.shbuiltmlx.metallibfrom nested MLX71271f08. It is byte-identical to thecb77239blibrary: SHA-256fb1ba8f90b9f1cc346246b7240c3986771464bd977c67f0ef03186811f16c85cfor both. The MLX bump only moves host C++ (mlx/backend/metal/device.cpp,device.h,command_buffer_limits.h).chunkPartitionsCarryStateBitwisecovers partitions that mix stock-kernel and prompt-kernel chunks. As with any new provider build, the complete-checkpoint identity changes because it hashes the binary and the loaded metallib (provider-swift/Sources/ProviderCore/Inference/PrefixCache/PrefixCachePolicy+CheckpointIdentity.swift,buildID).DARKBLOOM_TTFT_GDN_BLOCKED=0once per process, on first use (GatedDeltaPrefill.mode). This PR adds it toLaunchAgent.inferencePassthroughEnvKeys, so it now reaches the launchd provider job as well as a foregrounddarkbloomprocess or benchmark. Any non-empty value is forwarded, including the A/B-only forcedpacked/rowsmodes.os.Loggernotice per instantiation records dtype, head counts, value head width and the selected kernel.GPU.deviceInfo()fields.Validation
On the current head
e73cfaa2b, CI is green: Provider Unit Tests (includingforwardsGDNPromptKernelRollbackToProviderJob), Provider Tests, Provider SDK Tests, Provider Prompt Parity, Docs Lint, Docs Impact, Release Integrity and Commit Signatures. The local runs below were made when the PR still carried the pin bump.Run on M5 Ultra in the work clone. Toolchain: Apple Swift 6.4 (Command Line Tools), XCTest and the Metal toolchain from Xcode 27.1, macOS SDK 27.0. The SDK tree that was built and tested is identical to
1c9c255e; only its commit message changed after the runs. Rows marked refactor pass ran on the final pins (libs/mlx-swift-lm2debb5e8, commit9282c7532).cd provider-swift && nice -n 15 swift buildlibs/mlx-swift81f58d79andlibs/mlx-swift-lm1c9c255e./scripts/fetch-metallib.sh "$(cd provider-swift && swift build --show-bin-path)"mlx.metallibfrom nested MLX71271f08: SHA-256fb1ba8f90b9f1cc346246b7240c3986771464bd977c67f0ef03186811f16c85c, byte-identical to thecb77239blibrary. The refactor pass rebuilt it from source and got the same hashcd provider-swift && nice -n 15 swift build --build-testscd provider-swift && nice -n 15 swift build, thenswift build --build-testslibs/mlx-swift-lm2debb5e8(MLXLLM recompiled)2debb5e8: passed, 23 Swift Testing tests (60/60 bitwise, packed selected for all 6 instantiations) and 12 XCTest tests, 0 failuresmake docs-impact-check BASE=origin/mastercanonical documentation coverage OKfor 7 changed files: the 6 committed paths plus an uncommitted localprovider-swift/Package.resolvedresolution change, which is not part of this PR. Same result in the refactor passmake docs-check186 file(s) OK, before and after the refactor passpython3 scripts/changelog.py check;make changelog-preview27 valid fragment(s); the entry renders, before and after the refactor passmmdcon both figures, light and dark themesNot run here:
make provider-test(the full provider suite), and new full-model measurements on the rebased build. The end-to-end evidence above comes from the pre-rebase build.Limitations and landing order
master's pin since feat(provider): native Flint support and prefill projection optimization #1535; this PR changes no submodule.DARKBLOOM_GDN_PREFILL_BENCH=1 swift test --skip-build --filter GatedDeltaPrefillTests(fromlibs/mlx-swift-lm, afterswift build --build-testsand../../scripts/stage-test-metallib.sh "$(swift build --show-bin-path)").LaunchAgent.inferencePassthroughEnvKeys), with its rows indocs/provider/cli-reference.mdanddocs/reference/configuration.md. Forced A/B values (packed,rows) are forwarded too; restricting forwarding to the rollback spellings is a possible follow-up.DARKBLOOM_TTFT_*convention, and "blocked" is stale. A rename before release is a program-wide decision.docs/architecture/components/mlx-swift.mdlists pins that were already stale before this PR. It is left unchanged.mmdcin light and dark themes.Refactor pass
This section records the refactor pass on the original pin-bump version; its pin changes have since landed on
mastervia #1535.An independent refactor subagent reviewed both PRs after the preparer's self-review. Its changes are behavior-preserving. They are in commits
863a0b026and9282c7532here, and in SDK1c511d29,1ec827e0and2debb5e8.Changes:
Pin.
libs/mlx-swift-lmnow points at2debb5e8. The three refactor-pass SDK commits do four things:Qwen4ExpGDNBlocked.swift, which re-indents one string literal without changing its value;The kernel sources, the probe and every dispatch decision are unchanged.
docs/architecture/inference.md.packed, thenrows), says that every process probes each kernel instantiation once, and says which kernels the switch can force. Its links to#context,prefix-cache.md#streamed-complete-checkpointsandconfiguration.md#engine-and-schedulerresolve.docs/reference/configuration.md. TheDARKBLOOM_TTFT_GDN_BLOCKEDrow moved to afterDARKBLOOM_GEMMA4_PREFILL_CHUNK_EVAL, the other model-specific prefill control. Before, it split the MTP rows. Its text is unchanged.Changelog.
This body.
Checked in code, unchanged:
Qwen35GatedDeltaNet.cbv2Forward) passesmask: nil, so every CBv2 prompt chunk of 16 or more tokens is eligible.CBv2MTPConfig.testedMaxDraftTokens= 8 positions.testedMaxDraftTokensis 7, andCBv2MTPConfig.initclamps to it.CBv2RecurrentCheckpointGeometry.record). So T is the chunk size, not the 256-token checkpoint stride.chunkPartitionsCarryStateBitwise).qwen4_expandqwen4_exp_textbuildQwen35GatedDeltaNetwith.qwen4L2. That setsuseBlockedSeq, so their windows take the blocked-seq or the stock kernel and never reach the new path.LaunchAgent.passthroughEnvKeysandinferencePassthroughEnvKeysdo not contain the switch.buildIDinPrefixCachePolicy+CheckpointIdentity.swifthashes the binary and the loaded metallib.Package.resolved. The uncommitted change is SwiftPM re-resolving swift-syntax from 603.0.1 to 603.0.2, inside the SDK's unchanged600.0.0 ..< 604.0.0range. No pin bump since 0.9.0 has committed this file, so it stays uncommitted.Findings for reviewers, not changed here:
docs/architecture/components/mlx-swift.mdlists67153a87,a486a55dand0a725e30.masteralready pins6923a80f,14661d9bandcb77239b, so that table was stale before this PR.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.