From b1f4361ffd4a770995ca690bd7d1f38623a79827 Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Wed, 21 Oct 2026 16:11:14 -0700 Subject: [PATCH 1/7] Pin mlx-swift-lm to the bit-exact Qwen GDN prompt kernels 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 --- changelog.d/qwen-gdn-prompt-kernel.md | 4 ++++ docs/architecture/inference.md | 17 ++++++++++++++++- docs/reference/configuration.md | 3 ++- libs/mlx | 2 +- libs/mlx-swift | 2 +- libs/mlx-swift-lm | 2 +- 6 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 changelog.d/qwen-gdn-prompt-kernel.md diff --git a/changelog.d/qwen-gdn-prompt-kernel.md b/changelog.d/qwen-gdn-prompt-kernel.md new file mode 100644 index 0000000000..271b90e7f2 --- /dev/null +++ b/changelog.d/qwen-gdn-prompt-kernel.md @@ -0,0 +1,4 @@ +### Faster Qwen Gated DeltaNet prompt prefill + +- Run Gated DeltaNet prompt chunks of 16 or more tokens for Qwen3.5, Qwen3.6, Qwen3.8 and Bonsai 2 models on kernels that compute four value rows per SIMD group. On M5 Ultra the per-layer recurrence is 1.45-1.70x faster (Qwen3.5-9B geometry, 4,096-token chunk: 3.160 to 1.930 ms), which saves about 3-4% of Qwen3.5-9B cold time to first token at 8K-32K prompt tokens. Decode, MTP verification, masked updates and shorter chunks keep the existing kernel. +- The new kernels reproduce the existing kernel bit for bit, so outputs and recurrent checkpoints do not change. The first prompt chunk of each model geometry checks this on the GPU and keeps the existing kernel where no candidate matches. Speed on M1-M4 GPUs is unmeasured. `DARKBLOOM_TTFT_GDN_BLOCKED=0` restores the existing kernel in a foreground process; the provider LaunchAgent does not receive it. diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 0e948822c3..8fa12e3e26 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -1,6 +1,6 @@ # Provider inference engine -> Last updated: 2026-10-20 +> Last updated: 2026-10-21 How a chat-completion request is served inside the `darkbloom` provider process: one in-process engine (`mlx-swift-lm` @@ -36,6 +36,21 @@ the 27B artifact, which has no MTP assistant tensors. The 9B candidate's separate local sidecar requires the explicit validation and opt-in described below; it does not extend the 27B qualification cohort. +Gated DeltaNet prompt windows of `qwen3_5`, `qwen3_5_moe` and +`prism_hadamard_qwen35` models with at least `minT = 16` unmasked positions run +a four-row recurrence kernel +(`libs/mlx-swift-lm/Libraries/MLXLLM/Models/GatedDelta.swift`, `GatedDeltaPrefill`). +The first such window of each kernel instantiation (input dtype and head +geometry) runs the candidates on a fixed probe window and keeps the first that +reproduces `gated_delta_step` bit for bit on the GPU, or else the stock kernel. +Decode, MTP verification, masked updates and shorter windows always run the +stock kernel; because a selected kernel matches it bit for bit, mixing kernels +across chunks cannot change the recurrent state that +[checkpoint capture](prefix-cache.md#streamed-complete-checkpoints) relies on. +`qwen4_exp` and `qwen4_exp_text` keep their blocked-seq path. `DARKBLOOM_TTFT_GDN_BLOCKED` +([configuration](../reference/configuration.md#engine-and-scheduler)) keeps the +stock kernel or forces one candidate for A/B measurement. + Native Qwen3.5 vision blocks honor explicit checkpoint activation declarations. For the three supported nested vision types, tanh and exact GELU are selected from `hidden_act`; absent or unknown declarations preserve the existing fast diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index d52db3c749..3d7e1008b8 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md @@ -1,6 +1,6 @@ # Configuration reference -> Last updated: 2026-10-20 +> Last updated: 2026-10-21 Provider CLI, native-runtime and retained-console environment variables, compiled defaults and reading symbols. Secrets are named, never valued. Unless specified otherwise, values are read at process start. @@ -317,6 +317,7 @@ and rollback are defined in the [provider configuration reference](../provider/c | `DARKBLOOM_NEMOTRON35_MTP_BATCHED_M1` | exact `0` disables | on | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/NemotronH35MTPExactRows.swift` (`NemotronMTPExecution`) | Batch-axis projection dispatch that retains matrix M=1. No change to target precision; not forwarded to LaunchAgents. | | `DARKBLOOM_NEMOTRON35_MTP_KV_ONLY_HISTORY` | exact `0` disables | on | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/NemotronH35MTP.swift` (`NemotronH35MTPAssistant`) | Trusted-history replay may compute only the embedded assistant's K/V. Prefix save/restore uses the separate typed history codec. Not forwarded to LaunchAgents. | | `DARKBLOOM_NEMOTRON35_MTP_MAX_DRAFT_TOKENS` | integer `1`…`7` | `7` | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/NemotronH35MTP.swift` (`NemotronH35MTPAssistant`) | Upper proposal limit for adaptive depth; invalid selected limits fall back to seven. This is not a fixed proposal count. Not forwarded to LaunchAgents. | +| `DARKBLOOM_TTFT_GDN_BLOCKED` | `0`, `false`, `no`, `off` keep the stock kernel; `packed` or `rows` force that kernel; unset or any other value probes. Case-insensitive; surrounding whitespace is ignored | probe | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/GatedDelta.swift` (`GatedDeltaPrefill.mode`, `GatedDeltaPrefill.kernel`) | Selects the Gated DeltaNet prompt-window kernel of `qwen3_5`, `qwen3_5_moe` and `prism_hadamard_qwen35` models ([mechanism](../architecture/inference.md#context)). The default probe keeps a four-row kernel only where it reproduces `gated_delta_step` bit for bit on the GPU. Forced kernels skip that check and are for A/B measurement only. Decode, MTP verification and masked updates always use the stock kernel. Read once per process; not forwarded to LaunchAgents. | | `DARKBLOOM_MTP_VERIFICATION_MODE` | `rectangular`, `serial`, `serial_target`, `automatic` | `automatic` | `provider-swift/Sources/ProviderBenchmark/MTPProductionSession.swift` | MTP verification strategy (benchmark session). | | `DARKBLOOM_MTP_ACCEPTANCE` | `exact`, `typical`, `typical:` (finite positive delta) | `exact` | `provider-swift/Sources/ProviderBenchmark/MTPProductionSession.swift`; `provider-swift/Sources/ProviderCore/Inference/MTP/MTPAcceptancePolicy.swift` (`benchmarkOverride`) | MTP draft acceptance rule (benchmark session only). An unrecognized value uses `exact`. Serving reads no environment variable for this rule; it reads `[backend] mtp_acceptance` and `mtp_acceptance_by_model` in [`provider.toml`](../provider/cli-reference.md#providertoml-keys-read-by-the-cli). | | `DARKBLOOM_PREFILL_DEADLINE_MODE` | `off`, `enforce` | `off` | `provider-swift/Sources/ProviderCore/Inference/Engine/PrefillDeadlineMode.swift` | Prefill-deadline admission on the provider. | diff --git a/libs/mlx b/libs/mlx index cb77239be3..71271f080e 160000 --- a/libs/mlx +++ b/libs/mlx @@ -1 +1 @@ -Subproject commit cb77239be31b1df7f5db895226af55c39fc4f093 +Subproject commit 71271f080e8ba3eb9e288b62e8d51be308e80cbe diff --git a/libs/mlx-swift b/libs/mlx-swift index 6923a80f62..81f58d7922 160000 --- a/libs/mlx-swift +++ b/libs/mlx-swift @@ -1 +1 @@ -Subproject commit 6923a80f624f5c91fbf456efe4e00e9698a72961 +Subproject commit 81f58d7922a89218e1d534b8fc986a373ea679b1 diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index 14661d9ba1..1c9c255ebb 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit 14661d9ba148eaf27dce3af4b46d626bf61abeae +Subproject commit 1c9c255ebbe1edcf9ce20c151081dff9c398ebf4 From d2324e0044c2ce3d1eafff3c27e71e5de39a24a0 Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Wed, 21 Oct 2026 16:11:14 -0700 Subject: [PATCH 2/7] Re-pin the GDN SDK head and tighten its docs 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 --- changelog.d/qwen-gdn-prompt-kernel.md | 4 ++-- docs/architecture/inference.md | 25 +++++++++++++------------ libs/mlx-swift-lm | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/changelog.d/qwen-gdn-prompt-kernel.md b/changelog.d/qwen-gdn-prompt-kernel.md index 271b90e7f2..2f97e5f05b 100644 --- a/changelog.d/qwen-gdn-prompt-kernel.md +++ b/changelog.d/qwen-gdn-prompt-kernel.md @@ -1,4 +1,4 @@ ### Faster Qwen Gated DeltaNet prompt prefill -- Run Gated DeltaNet prompt chunks of 16 or more tokens for Qwen3.5, Qwen3.6, Qwen3.8 and Bonsai 2 models on kernels that compute four value rows per SIMD group. On M5 Ultra the per-layer recurrence is 1.45-1.70x faster (Qwen3.5-9B geometry, 4,096-token chunk: 3.160 to 1.930 ms), which saves about 3-4% of Qwen3.5-9B cold time to first token at 8K-32K prompt tokens. Decode, MTP verification, masked updates and shorter chunks keep the existing kernel. -- The new kernels reproduce the existing kernel bit for bit, so outputs and recurrent checkpoints do not change. The first prompt chunk of each model geometry checks this on the GPU and keeps the existing kernel where no candidate matches. Speed on M1-M4 GPUs is unmeasured. `DARKBLOOM_TTFT_GDN_BLOCKED=0` restores the existing kernel in a foreground process; the provider LaunchAgent does not receive it. +- Run Gated DeltaNet prompt chunks of 16 or more tokens for Qwen3.5, Qwen3.6, Qwen3.8 and Bonsai 2 models on kernels that compute four value rows per SIMD group. On M5 Ultra the per-layer recurrence is 1.45-1.70x faster (Qwen3.5-9B geometry, 4,096-token chunk: 3.160 to 1.930 ms), which is estimated to save 3-4% of Qwen3.5-9B cold time to first token at 8K-32K prompt tokens. Decode, MTP verification, masked updates and shorter chunks keep the existing kernel. +- A new kernel runs only where it reproduces the existing kernel bit for bit, so outputs and recurrent checkpoints do not change: the first prompt chunk of each model geometry checks this on the GPU and keeps the existing kernel where no candidate matches. Speed on M1-M4 GPUs is unmeasured. `DARKBLOOM_TTFT_GDN_BLOCKED=0` restores the existing kernel in a foreground process; the provider LaunchAgent does not receive it. diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 8fa12e3e26..126e2d2938 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -36,13 +36,24 @@ the 27B artifact, which has no MTP assistant tensors. The 9B candidate's separate local sidecar requires the explicit validation and opt-in described below; it does not extend the 27B qualification cohort. +Native Qwen3.5 vision blocks honor explicit checkpoint activation declarations. +For the three supported nested vision types, tanh and exact GELU are selected +from `hidden_act`; absent or unknown declarations preserve the existing fast +approximation. The SDK's `Qwen3VLConfiguration.VisionConfiguration` +(`visionMLPApproximationForConstruction`) owns this choice in +`libs/mlx-swift-lm/Libraries/MLXVLM/Models/Qwen3VL.swift`. +See `libs/mlx-swift-lm/docs/bonsai2.md` for the exact activation mapping, +checkpoint contract and qualification scope. This implementation does not +activate a catalog entry. + Gated DeltaNet prompt windows of `qwen3_5`, `qwen3_5_moe` and `prism_hadamard_qwen35` models with at least `minT = 16` unmasked positions run a four-row recurrence kernel (`libs/mlx-swift-lm/Libraries/MLXLLM/Models/GatedDelta.swift`, `GatedDeltaPrefill`). The first such window of each kernel instantiation (input dtype and head -geometry) runs the candidates on a fixed probe window and keeps the first that -reproduces `gated_delta_step` bit for bit on the GPU, or else the stock kernel. +geometry) tries the candidates in order on a fixed probe window and keeps the +first that reproduces `gated_delta_step` bit for bit on the GPU, or else the +stock kernel. Decode, MTP verification, masked updates and shorter windows always run the stock kernel; because a selected kernel matches it bit for bit, mixing kernels across chunks cannot change the recurrent state that @@ -51,16 +62,6 @@ across chunks cannot change the recurrent state that ([configuration](../reference/configuration.md#engine-and-scheduler)) keeps the stock kernel or forces one candidate for A/B measurement. -Native Qwen3.5 vision blocks honor explicit checkpoint activation declarations. -For the three supported nested vision types, tanh and exact GELU are selected -from `hidden_act`; absent or unknown declarations preserve the existing fast -approximation. The SDK's `Qwen3VLConfiguration.VisionConfiguration` -(`visionMLPApproximationForConstruction`) owns this choice in -`libs/mlx-swift-lm/Libraries/MLXVLM/Models/Qwen3VL.swift`. -See `libs/mlx-swift-lm/docs/bonsai2.md` for the exact activation mapping, -checkpoint contract and qualification scope. This implementation does not -activate a catalog entry. - Every advertised model is served through CBv2; a `model_type` without a CBv2 adapter is dropped from the advertised set at scan time and never loads (`provider-swift/Sources/ProviderCore/Inference/Engine/EngineV2SupportedModels.swift`, diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index 1c9c255ebb..1ec827e04d 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit 1c9c255ebbe1edcf9ce20c151081dff9c398ebf4 +Subproject commit 1ec827e04d418d965cba6d738b706c3128a089f2 From 41af26069e5c2d38692e2a44e30dd4f9bbb7da07 Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Wed, 21 Oct 2026 16:11:14 -0700 Subject: [PATCH 3/7] Re-pin the GDN dispatch cleanup and name the probe candidates 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 --- docs/architecture/inference.md | 13 +++++++------ docs/reference/configuration.md | 2 +- libs/mlx-swift-lm | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 126e2d2938..90fa568e42 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -50,17 +50,18 @@ Gated DeltaNet prompt windows of `qwen3_5`, `qwen3_5_moe` and `prism_hadamard_qwen35` models with at least `minT = 16` unmasked positions run a four-row recurrence kernel (`libs/mlx-swift-lm/Libraries/MLXLLM/Models/GatedDelta.swift`, `GatedDeltaPrefill`). -The first such window of each kernel instantiation (input dtype and head -geometry) tries the candidates in order on a fixed probe window and keeps the -first that reproduces `gated_delta_step` bit for bit on the GPU, or else the -stock kernel. +In each process, the first such window of each kernel instantiation (input +dtype and head geometry) tries the `packed` and then the `rows` kernel on a +fixed probe window and keeps the first that reproduces `gated_delta_step` bit +for bit on the GPU, or else the stock kernel. Decode, MTP verification, masked updates and shorter windows always run the stock kernel; because a selected kernel matches it bit for bit, mixing kernels across chunks cannot change the recurrent state that [checkpoint capture](prefix-cache.md#streamed-complete-checkpoints) relies on. -`qwen4_exp` and `qwen4_exp_text` keep their blocked-seq path. `DARKBLOOM_TTFT_GDN_BLOCKED` +`qwen4_exp` and `qwen4_exp_text` keep their blocked-seq path. +`DARKBLOOM_TTFT_GDN_BLOCKED` ([configuration](../reference/configuration.md#engine-and-scheduler)) keeps the -stock kernel or forces one candidate for A/B measurement. +stock kernel or forces `packed` or `rows` for A/B measurement. Every advertised model is served through CBv2; a `model_type` without a CBv2 adapter is dropped from the advertised set at scan time and never loads diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index 3d7e1008b8..d63e84455b 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md @@ -317,11 +317,11 @@ and rollback are defined in the [provider configuration reference](../provider/c | `DARKBLOOM_NEMOTRON35_MTP_BATCHED_M1` | exact `0` disables | on | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/NemotronH35MTPExactRows.swift` (`NemotronMTPExecution`) | Batch-axis projection dispatch that retains matrix M=1. No change to target precision; not forwarded to LaunchAgents. | | `DARKBLOOM_NEMOTRON35_MTP_KV_ONLY_HISTORY` | exact `0` disables | on | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/NemotronH35MTP.swift` (`NemotronH35MTPAssistant`) | Trusted-history replay may compute only the embedded assistant's K/V. Prefix save/restore uses the separate typed history codec. Not forwarded to LaunchAgents. | | `DARKBLOOM_NEMOTRON35_MTP_MAX_DRAFT_TOKENS` | integer `1`…`7` | `7` | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/NemotronH35MTP.swift` (`NemotronH35MTPAssistant`) | Upper proposal limit for adaptive depth; invalid selected limits fall back to seven. This is not a fixed proposal count. Not forwarded to LaunchAgents. | -| `DARKBLOOM_TTFT_GDN_BLOCKED` | `0`, `false`, `no`, `off` keep the stock kernel; `packed` or `rows` force that kernel; unset or any other value probes. Case-insensitive; surrounding whitespace is ignored | probe | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/GatedDelta.swift` (`GatedDeltaPrefill.mode`, `GatedDeltaPrefill.kernel`) | Selects the Gated DeltaNet prompt-window kernel of `qwen3_5`, `qwen3_5_moe` and `prism_hadamard_qwen35` models ([mechanism](../architecture/inference.md#context)). The default probe keeps a four-row kernel only where it reproduces `gated_delta_step` bit for bit on the GPU. Forced kernels skip that check and are for A/B measurement only. Decode, MTP verification and masked updates always use the stock kernel. Read once per process; not forwarded to LaunchAgents. | | `DARKBLOOM_MTP_VERIFICATION_MODE` | `rectangular`, `serial`, `serial_target`, `automatic` | `automatic` | `provider-swift/Sources/ProviderBenchmark/MTPProductionSession.swift` | MTP verification strategy (benchmark session). | | `DARKBLOOM_MTP_ACCEPTANCE` | `exact`, `typical`, `typical:` (finite positive delta) | `exact` | `provider-swift/Sources/ProviderBenchmark/MTPProductionSession.swift`; `provider-swift/Sources/ProviderCore/Inference/MTP/MTPAcceptancePolicy.swift` (`benchmarkOverride`) | MTP draft acceptance rule (benchmark session only). An unrecognized value uses `exact`. Serving reads no environment variable for this rule; it reads `[backend] mtp_acceptance` and `mtp_acceptance_by_model` in [`provider.toml`](../provider/cli-reference.md#providertoml-keys-read-by-the-cli). | | `DARKBLOOM_PREFILL_DEADLINE_MODE` | `off`, `enforce` | `off` | `provider-swift/Sources/ProviderCore/Inference/Engine/PrefillDeadlineMode.swift` | Prefill-deadline admission on the provider. | | `DARKBLOOM_GEMMA4_PREFILL_CHUNK_EVAL` | integer layers | projected from `provider.toml` (`18`) | `provider-swift/Sources/ProviderCore/Config/GemmaOptimizationEnvironment.swift` | Gemma-4 prefill chunk-eval layers; the provider sets it for the engine, `scripts/install.sh` sets `18` for the smoke test. | +| `DARKBLOOM_TTFT_GDN_BLOCKED` | `0`, `false`, `no`, `off` keep the stock kernel; `packed` or `rows` force that kernel; unset or any other value probes. Case-insensitive; surrounding whitespace is ignored | probe | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/GatedDelta.swift` (`GatedDeltaPrefill.mode`, `GatedDeltaPrefill.kernel`) | Selects the Gated DeltaNet prompt-window kernel of `qwen3_5`, `qwen3_5_moe` and `prism_hadamard_qwen35` models ([mechanism](../architecture/inference.md#context)). The default probe keeps a four-row kernel only where it reproduces `gated_delta_step` bit for bit on the GPU. Forced kernels skip that check and are for A/B measurement only. Decode, MTP verification and masked updates always use the stock kernel. Read once per process; not forwarded to LaunchAgents. | | `DARKBLOOM_ENGINE_V2_VLM_PARITY_CHECK` | `0` skips | on | `provider-swift/Sources/ProviderCore/Inference/Vision/EngineV2VLMTextExtraction.swift` | VLM text-extraction parity check. | ### Native MiMo V2.6 candidate diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index 1ec827e04d..2debb5e846 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit 1ec827e04d418d965cba6d738b706c3128a089f2 +Subproject commit 2debb5e846b42214f936f5c31b585f7a384d4e0a From 59ee6cc5507fbf56b9987a389c1f04db2811ab64 Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Wed, 21 Oct 2026 17:30:13 -0700 Subject: [PATCH 4/7] Re-pin libs/mlx-swift-lm to the merged SDK change (#324) 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 --- libs/mlx-swift-lm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index f4be1ba1eb..921bfa697a 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit f4be1ba1ebb72c22ec7866b0be1af4cb07522594 +Subproject commit 921bfa697ab31fcd2298bf90568f66e65196530f From 9e3b3e0ab94b60289a5c560513dfe1275caa6806 Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Wed, 21 Oct 2026 18:10:38 -0700 Subject: [PATCH 5/7] fix(provider): forward the GDN prompt-kernel rollback to launchd 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 --- changelog.d/qwen-gdn-prompt-kernel.md | 2 +- docs/provider/cli-reference.md | 1 + docs/reference/configuration.md | 2 +- .../ProviderCore/Service/LaunchAgent.swift | 5 ++++ .../Service/LaunchAgentRestartTests.swift | 25 +++++++++++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/changelog.d/qwen-gdn-prompt-kernel.md b/changelog.d/qwen-gdn-prompt-kernel.md index 2f97e5f05b..2b56d8b648 100644 --- a/changelog.d/qwen-gdn-prompt-kernel.md +++ b/changelog.d/qwen-gdn-prompt-kernel.md @@ -1,4 +1,4 @@ ### Faster Qwen Gated DeltaNet prompt prefill - Run Gated DeltaNet prompt chunks of 16 or more tokens for Qwen3.5, Qwen3.6, Qwen3.8 and Bonsai 2 models on kernels that compute four value rows per SIMD group. On M5 Ultra the per-layer recurrence is 1.45-1.70x faster (Qwen3.5-9B geometry, 4,096-token chunk: 3.160 to 1.930 ms), which is estimated to save 3-4% of Qwen3.5-9B cold time to first token at 8K-32K prompt tokens. Decode, MTP verification, masked updates and shorter chunks keep the existing kernel. -- A new kernel runs only where it reproduces the existing kernel bit for bit, so outputs and recurrent checkpoints do not change: the first prompt chunk of each model geometry checks this on the GPU and keeps the existing kernel where no candidate matches. Speed on M1-M4 GPUs is unmeasured. `DARKBLOOM_TTFT_GDN_BLOCKED=0` restores the existing kernel in a foreground process; the provider LaunchAgent does not receive it. +- A new kernel runs only where it reproduces the existing kernel bit for bit, so outputs and recurrent checkpoints do not change: the first prompt chunk of each model geometry checks this on the GPU and keeps the existing kernel where no candidate matches. Speed on M1-M4 GPUs is unmeasured. `DARKBLOOM_TTFT_GDN_BLOCKED=0` restores the existing kernel. `darkbloom start` forwards it to the background provider, so the rollback also reaches launchd-managed providers. diff --git a/docs/provider/cli-reference.md b/docs/provider/cli-reference.md index 902207617b..73f7fe1a56 100644 --- a/docs/provider/cli-reference.md +++ b/docs/provider/cli-reference.md @@ -1738,6 +1738,7 @@ must support the checkpoint contract described in | `DARKBLOOM_MIMO_PERSISTENT_WIRED_RESIDENCY` | `provider-swift/Sources/ProviderCore/Inference/Engine/Factory/MiMo/MiMoV26WiredResidency.swift` (`isEnabled`) | | `DARKBLOOM_GLM_PERSISTENT_WIRED_RESIDENCY` | `provider-swift/Sources/ProviderCore/Inference/Models/GLM5Next/GLM5NextWiredResidency.swift` (`isEnabled`); on by default, `0`/`false`/`no`/`off` rolls back to per-command-buffer residency | | `DARKBLOOM_MLX_RESOURCE_DEBUG` | forwarded to `mlx-swift-lm` | +| `DARKBLOOM_TTFT_GDN_BLOCKED` | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/GatedDelta.swift` (`GatedDeltaPrefill.mode`); `0` keeps the stock Qwen GDN prompt kernel | | `DARKBLOOM_CBV2_PAGED_KV` | `provider-swift/Sources/ProviderCore/Inference/Engine/EngineV2KVBackendPolicy.swift` | | `DARKBLOOM_CBV2_KV_QUANTIZATION` | `provider-swift/Sources/ProviderCore/Inference/Engine/EngineV2KVQuantizationPolicy.swift` (`resolve`, live) | | `DARKBLOOM_CBV2_CHECKPOINT_QUANTIZATION` | `provider-swift/Sources/ProviderCore/Inference/Engine/EngineV2KVQuantizationPolicy.swift` (`resolve`, checkpoint) | diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index 7e951d4d74..347b586b29 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md @@ -411,7 +411,7 @@ and rollback are defined in the [provider configuration reference](../provider/c | `DARKBLOOM_MTP_ACCEPTANCE` | `exact`, `typical`, `typical:` (finite positive delta) | `exact` | `provider-swift/Sources/ProviderBenchmark/MTPProductionSession.swift`; `provider-swift/Sources/ProviderCore/Inference/MTP/MTPAcceptancePolicy.swift` (`benchmarkOverride`) | MTP draft acceptance rule (benchmark session only). An unrecognized value uses `exact`. Serving reads no environment variable for this rule; it reads `[backend] mtp_acceptance` and `mtp_acceptance_by_model` in [`provider.toml`](../provider/cli-reference.md#providertoml-keys-read-by-the-cli). | | `DARKBLOOM_PREFILL_DEADLINE_MODE` | `off`, `enforce` | `off` | `provider-swift/Sources/ProviderCore/Inference/Engine/PrefillDeadlineMode.swift` | Prefill-deadline admission on the provider. | | `DARKBLOOM_GEMMA4_PREFILL_CHUNK_EVAL` | integer layers | projected from `provider.toml` (`18`) | `provider-swift/Sources/ProviderCore/Config/GemmaOptimizationEnvironment.swift` | Gemma-4 prefill chunk-eval layers; the provider sets it for the engine, `scripts/install.sh` sets `18` for the smoke test. | -| `DARKBLOOM_TTFT_GDN_BLOCKED` | `0`, `false`, `no`, `off` keep the stock kernel; `packed` or `rows` force that kernel; unset or any other value probes. Case-insensitive; surrounding whitespace is ignored | probe | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/GatedDelta.swift` (`GatedDeltaPrefill.mode`, `GatedDeltaPrefill.kernel`) | Selects the Gated DeltaNet prompt-window kernel of `qwen3_5`, `qwen3_5_moe` and `prism_hadamard_qwen35` models ([mechanism](../architecture/inference.md#context)). The default probe keeps a four-row kernel only where it reproduces `gated_delta_step` bit for bit on the GPU. Forced kernels skip that check and are for A/B measurement only. Decode, MTP verification and masked updates always use the stock kernel. Read once per process; not forwarded to LaunchAgents. | +| `DARKBLOOM_TTFT_GDN_BLOCKED` | `0`, `false`, `no`, `off` keep the stock kernel; `packed` or `rows` force that kernel; unset or any other value probes. Case-insensitive; surrounding whitespace is ignored | probe | `libs/mlx-swift-lm/Libraries/MLXLLM/Models/GatedDelta.swift` (`GatedDeltaPrefill.mode`, `GatedDeltaPrefill.kernel`) | Selects the Gated DeltaNet prompt-window kernel of `qwen3_5`, `qwen3_5_moe` and `prism_hadamard_qwen35` models ([mechanism](../architecture/inference.md#context)). The default probe keeps a four-row kernel only where it reproduces `gated_delta_step` bit for bit on the GPU; it does not compare speed, so `0` is the rollback where a kept kernel is slower. Forced kernels skip that check and are for A/B measurement only. Decode, MTP verification and masked updates always use the stock kernel. Read once per process. Forwarded to the LaunchAgent. | | `DARKBLOOM_ENGINE_V2_VLM_PARITY_CHECK` | `0` skips | on | `provider-swift/Sources/ProviderCore/Inference/Vision/EngineV2VLMTextExtraction.swift` | VLM text-extraction parity check. | ### Managed Nemotron Super slot diff --git a/provider-swift/Sources/ProviderCore/Service/LaunchAgent.swift b/provider-swift/Sources/ProviderCore/Service/LaunchAgent.swift index 62be10b1da..e8e5a3888a 100644 --- a/provider-swift/Sources/ProviderCore/Service/LaunchAgent.swift +++ b/provider-swift/Sources/ProviderCore/Service/LaunchAgent.swift @@ -273,6 +273,10 @@ public enum LaunchAgent: Sendable { /// `DARKBLOOM_MIMO_COMPLETE_PREFIX`: model-scoped SSD prefix caching is /// on by default for the supported MiMo identities; preserve its opt-out /// in the provider job independently of the global cache kill switch. + /// `DARKBLOOM_TTFT_GDN_BLOCKED`: the SDK keeps a four-row Qwen GDN prompt + /// kernel wherever its parity probe finds it bit-exact, which says nothing + /// about speed; the stock-kernel rollback must reach the job. Spelled out + /// because its reader (`GatedDeltaPrefill.mode`) is internal to `MLXLLM`. /// `MiMoV26DecodeDefaults.environmentKeys`: the MiMo short-forward decode /// kernels (fused norms, distinct-expert MXFP4, FP32 router GEMV) are on by /// default in the SDK; their per-kernel rollbacks use the same values. @@ -288,6 +292,7 @@ public enum LaunchAgent: Sendable { MiMoV26WiredResidency.environmentFlag, GLM5NextWiredResidency.environmentFlag, PrefixCachePolicy.mimoCompletePrefixEnvironmentFlag, + "DARKBLOOM_TTFT_GDN_BLOCKED", EngineV2SlotFactory.mimoRectangularVerifyEnvironmentKey, GLM5NextProtectedModel.rectangularVerifyEnvironmentKey, ] + MiMoV26DecodeDefaults.environmentKeys + MiMoV26DecodeDefaults.verifyEnvironmentKeys diff --git a/provider-swift/Tests/ProviderCoreTests/Service/LaunchAgentRestartTests.swift b/provider-swift/Tests/ProviderCoreTests/Service/LaunchAgentRestartTests.swift index 1656cd0517..99a04b6f48 100644 --- a/provider-swift/Tests/ProviderCoreTests/Service/LaunchAgentRestartTests.swift +++ b/provider-swift/Tests/ProviderCoreTests/Service/LaunchAgentRestartTests.swift @@ -1,4 +1,5 @@ import Foundation +@testable import MLXLLM import MLXLMCommon @testable import ProviderAppAttest import Testing @@ -232,6 +233,30 @@ struct LaunchAgentEnvironmentTests { == .serialTarget) } + @Test func forwardsGDNPromptKernelRollbackToProviderJob() { + // The SDK's GDN prompt-kernel probe checks bits, not speed, so the + // stock-kernel rollback is how an operator recovers from a slower + // bit-exact kernel. launchd does not inherit the shell: the provider + // job resolves the foreground's mode only if its plist carries the key. + let key = GatedDeltaPrefill.envFlag + #expect(LaunchAgent.inferencePassthroughEnvKeys.contains(key)) + #expect(!WatchdogAgent.passthroughEnvKeys.contains(key)) + for value: String? in [nil, "", "0", " OFF ", "packed", "rows", "typo"] { + var foreground = ["UNRELATED_SECRET": "excluded"] + foreground[key] = value + let plist = LaunchAgent.makeServicePlist( + label: LaunchAgent.label, programArguments: ["/test/darkbloom", "start", "--foreground"], + logPath: "/test/provider.log", environment: foreground) + let launchd = plist["EnvironmentVariables"] as? [String: String] ?? [:] + #expect(launchd["UNRELATED_SECRET"] == nil) + #expect(GatedDeltaPrefill.Mode(environmentValue: launchd[key]) + == GatedDeltaPrefill.Mode(environmentValue: foreground[key])) + } + let rollback = LaunchAgent.passthroughEnvironment(from: [key: "0"]) + #expect(rollback == [key: "0"]) + #expect(GatedDeltaPrefill.Mode(environmentValue: rollback[key]) == .stock) + } + @Test func preservesMalformedNonEmptyControlsForRuntimeSecureDefault() { let out = LaunchAgent.passthroughEnvironment(from: [ EngineV2Factory.maxPartialPrefillsKey: "not-an-integer", From 251202f41de9401846db0672a693394ad235499b Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Wed, 21 Oct 2026 18:10:38 -0700 Subject: [PATCH 6/7] docs: qualify the GDN prompt kernels by GPU in hardware support 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 --- changelog.d/qwen-gdn-prompt-kernel.md | 2 +- docs/architecture/hardware-support.md | 29 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/changelog.d/qwen-gdn-prompt-kernel.md b/changelog.d/qwen-gdn-prompt-kernel.md index 2b56d8b648..17b9ca5e43 100644 --- a/changelog.d/qwen-gdn-prompt-kernel.md +++ b/changelog.d/qwen-gdn-prompt-kernel.md @@ -1,4 +1,4 @@ ### Faster Qwen Gated DeltaNet prompt prefill - Run Gated DeltaNet prompt chunks of 16 or more tokens for Qwen3.5, Qwen3.6, Qwen3.8 and Bonsai 2 models on kernels that compute four value rows per SIMD group. On M5 Ultra the per-layer recurrence is 1.45-1.70x faster (Qwen3.5-9B geometry, 4,096-token chunk: 3.160 to 1.930 ms), which is estimated to save 3-4% of Qwen3.5-9B cold time to first token at 8K-32K prompt tokens. Decode, MTP verification, masked updates and shorter chunks keep the existing kernel. -- A new kernel runs only where it reproduces the existing kernel bit for bit, so outputs and recurrent checkpoints do not change: the first prompt chunk of each model geometry checks this on the GPU and keeps the existing kernel where no candidate matches. Speed on M1-M4 GPUs is unmeasured. `DARKBLOOM_TTFT_GDN_BLOCKED=0` restores the existing kernel. `darkbloom start` forwards it to the background provider, so the rollback also reaches launchd-managed providers. +- A new kernel runs only where it reproduces the existing kernel bit for bit, so outputs and recurrent checkpoints do not change: the first prompt chunk of each model geometry checks this on the GPU and keeps the existing kernel where no candidate matches. On M3 Ultra, Qwen3.5-9B cold prefill takes 1.1-1.3% less time at 2K-32K prompt tokens; speed on other M1-M4 GPUs is unmeasured. `DARKBLOOM_TTFT_GDN_BLOCKED=0` restores the existing kernel. `darkbloom start` forwards it to the background provider, so the rollback also reaches launchd-managed providers. diff --git a/docs/architecture/hardware-support.md b/docs/architecture/hardware-support.md index cbe6b1b667..37a68dda4a 100644 --- a/docs/architecture/hardware-support.md +++ b/docs/architecture/hardware-support.md @@ -524,6 +524,35 @@ values, including a literal `4` from older configs, are kept. Provider full-load quotations, measured activation floors and reported capacity must remain compatible with [platform admission](https://github.com/Layr-Labs/darkbloom-platform/blob/48a198c71a2d30feec5597bacf1101120f7f955d/coordinator/internal/registry/memorypolicy/structural.go). Review both repositories when changing these contracts; do not copy the backend implementation here or replace measured floors with shape-based estimates. +### GDN prompt kernels by GPU + +Gated DeltaNet prompt windows of the Qwen model types named in +[inference](inference.md#context) take a four-row kernel only on a GPU where it +reproduces the stock `gated_delta_step` bit for bit, so on every chip outputs +and recurrent checkpoints keep the stock kernel's bits. No chip list decides +this: in each process, the first eligible window of each kernel instantiation +runs the candidates and the stock kernel on a fixed 32-position window on that +GPU and keeps the first exact candidate, or else the stock kernel +(`libs/mlx-swift-lm/Libraries/MLXLLM/Models/GatedDelta.swift`, +`GatedDeltaPrefill.probe`). The probe does not compare speed; where a kept +kernel is slower, `DARKBLOOM_TTFT_GDN_BLOCKED` +([configuration](../reference/configuration.md#engine-and-scheduler)) restores +the stock kernel. + +| GPU | Speed qualification | +|---|---| +| M5 Ultra (80-core) | Per-layer recurrence 1.45-1.70x faster (bf16 inputs, fp32 state, 512 and 4,096 positions); the probe keeps `packed` at the Qwen3.5-9B, Qwen3.8-27B and Qwen3.5-35B-A3B head geometries | +| M3 Ultra | Qwen3.5-9B cold prefill takes 1.1-1.3% less time at 2,048, 8,192 and 32,768 prompt tokens (`darkbloom benchmark --scheduler-prefill`, probe against the stock kernel, A/B/A on one binary) | +| Every other GPU | Unmeasured: bit-exact through the probe, speed unknown. `GatedDeltaPrefillTests` prints per-layer timings with `DARKBLOOM_GDN_PREFILL_BENCH=1` | + +The selected kernel has the stock kernel's inputs, outputs and fp32 state, so +steady-state memory is unchanged. The probe allocates transiently, once per +kernel instantiation and process: a 32-position window and up to four fp32 +recurrent states, at most about 16 MiB at Qwen3.8-27B's 48 value heads of 128. +Capacity compatibility: no full-load quotation, measured activation floor, KV +grant or reported capacity field changes, so +[platform admission](#cross-repository-agreement) needs no change. + ## Invariants 1. New KV charges must fit the current unified cap, OS availability and activation From e73cfaa2b8f2d8faa8c5f8c3c48e5a022f6acb3e Mon Sep 17 00:00:00 2001 From: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com> Date: Wed, 21 Oct 2026 18:54:33 -0700 Subject: [PATCH 7/7] docs(provider): restamp the docs last edited on 2026-10-22 UTC 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 --- docs/architecture/hardware-support.md | 2 +- docs/provider/cli-reference.md | 2 +- docs/reference/configuration.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/architecture/hardware-support.md b/docs/architecture/hardware-support.md index 37a68dda4a..5c27b7b04a 100644 --- a/docs/architecture/hardware-support.md +++ b/docs/architecture/hardware-support.md @@ -1,6 +1,6 @@ # Hardware support and the provider memory model -> Last updated: 2026-10-21 +> Last updated: 2026-10-22 What hardware the provider runs on and how it decides, in bytes, whether a model may load and how much KV cache each resident model may use. Read this to diff --git a/docs/provider/cli-reference.md b/docs/provider/cli-reference.md index 73f7fe1a56..69da36b601 100644 --- a/docs/provider/cli-reference.md +++ b/docs/provider/cli-reference.md @@ -1,6 +1,6 @@ # Provider CLI reference -> Last updated: 2026-10-21 +> Last updated: 2026-10-22 Reference for the `darkbloom` command-line tool: every subcommand and flag, the files and identifiers it creates, the `provider.toml` keys it reads with their diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index 347b586b29..9ab2e9171e 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md @@ -1,6 +1,6 @@ # Configuration reference -> Last updated: 2026-10-21 +> Last updated: 2026-10-22 Provider CLI, native-runtime and retained-console environment variables, compiled defaults and reading symbols. Secrets are named, never valued. Unless specified otherwise, values are read at process start.