Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.d/qwen-gdn-prompt-kernel.md
Original file line number Diff line number Diff line change
@@ -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 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. 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.
31 changes: 30 additions & 1 deletion docs/architecture/hardware-support.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Comment thread
Gajesh2007 marked this conversation as resolved.
Resolved

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
Expand Down
17 changes: 17 additions & 0 deletions docs/architecture/inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,23 @@ 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`).
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`
([configuration](../reference/configuration.md#engine-and-scheduler)) keeps the
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
(`provider-swift/Sources/ProviderCore/Inference/Engine/EngineV2SupportedModels.swift`,
Expand Down
3 changes: 2 additions & 1 deletion docs/provider/cli-reference.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) |
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/configuration.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -411,6 +411,7 @@ and rollback are defined in the [provider configuration reference](../provider/c
| `DARKBLOOM_MTP_ACCEPTANCE` | `exact`, `typical`, `typical:<delta>` (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; 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
Expand Down
5 changes: 5 additions & 0 deletions provider-swift/Sources/ProviderCore/Service/LaunchAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
@testable import MLXLLM
import MLXLMCommon
@testable import ProviderAppAttest
import Testing
Expand Down Expand Up @@ -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",
Expand Down
Loading