Skip to content

Provider: serve Qwen4-35B-A3B on native Qwen4 stack (replay provider-integ + SDK main 64a6f34f) - #2949

Draft
GumbiiDigital wants to merge 29 commits into
Layr-Labs:devfrom
GumbiiDigital:feat/qwen4-35b-a3b-provider
Draft

GumbiiDigital wants to merge 29 commits into
Layr-Labs:devfrom
GumbiiDigital:feat/qwen4-35b-a3b-provider

Conversation

@GumbiiDigital

@GumbiiDigital GumbiiDigital commented Dec 6, 2026 •

Copy link
Copy Markdown

Provenance: Branch GumbiiDigital:feat/qwen4-35b-a3b-provider (head e83c8735567f0c0de90eb7c3a2e037161b06baa5, 29 SSH-signed commits) rebased cleanly onto Layr-Labs/d-inference dev (08ef86a5cb0e2c13ca19992cd5b0872436b5751a, post-v0.10.22 sync and #2929 contribution-rules checks). Replays Jonathan Spengler's (jonathan308) full 33-commit origin/qwen4-a3b/provider-integ (e9493a61d2) stack and pins libs/mlx-swift-lm to landed Layr-Labs/mlx-swift-lm main 64a6f34feffd1137f33eaaf56e6040bf296e8883 (#584 + #586). Supersedes the earlier 6-commit baseline in Layr-Labs/d-inference#2911 (cited for provenance only — #2911 and Jonathan's qwen4-a3b/* / feat/qwen4-35b-a3b branches remain untouched; branch pushed to GumbiiDigital/d-inference due to repo ruleset 21006856).

Summary

Adds full provider-side serving support for Qwen4-35B-A3B (qwen4_moe / qwen4_moe_text) on the native Qwen4 stack (alongside Flash-Next qwen4_exp), pinned to landed SDK main 64a6f34feffd1137f33eaaf56e6040bf296e8883:

  • SDK pin (libs/mlx-swift-lm → 64a6f34feffd1137f33eaaf56e6040bf296e8883): Advances libs/mlx-swift-lm from dev's 70183a70 onto Layr-Labs/mlx-swift-lm main covering Muse Glimmer #579, Qwen4-35B-A3B integration + mtp-mirror-fix (#584), and the 17 multi-row batching commits (#586 / #585: paged multi-row vector-SDPA, rows-adjacent MoE/QSA folds, non-concatenated FP32 GDN row states, MTP cohort acceptance break-even gating, multi-row router GEMV). provider-swift/Package.swift uses .package(path: "../libs/mlx-swift-lm", traits: []) and Package.resolved required no changes.
  • Identity, Paging, Prefix Cache & Sampling (Qwen4ModelIdentity, Qwen4SupportPolicy, EngineV2SamplingDefaults): Qualifies qwen4-35b-a3b, EigenLabs/Qwen4-35B-A3B-MLX-4bit-mtp, and alias mlx-community/Qwen4-35B-A3B-oQ4e-mtp for automatic paged KV, complete SSD prefix checkpoints, embedded 1-layer MTP with exact acceptance, continuous batching, native 1_048_576 context window, and checkpoint sampling defaults (temperature=1.0, top_p=0.95, top_k=20, no presence penalty).
  • Phase 0 Locked Defaults:
    • 64 GB RAM floor & resident PLE default: DARKBLOOM_QWEN4_PLE_RESIDENCY defaults to .memory for qwen4_moe* (35,215,477,491 B weights, 39.36 GiB scanner quote, no offload credit), coordinating with catalog min_ram_gb = 64 in darkbloom-platform. Opt-in SSD offload remains available via DARKBLOOM_QWEN4_PLE_RESIDENCY=ssd, DARKBLOOM_QWEN4_PLE_SSD_OFFLOAD=1, or [backend] qwen4_ngram_residency_by_model (22.42 GB resident + 6.21 GB transient = 26.66 GiB quote, 12.80 GB offloaded).
    • Output cap: Coordinated with max_output_length = 32768 (IntegrationModels.defaultOutputCap = 32_768 and darkbloom-platform catalog template).
    • Target provider release: 0.10.23 (ProviderCore.version stays 0.10.22 on dev per docs/operations/provider-release.md; bumped on release cut).
  • Native Chat Encoder & Segment Token Cache (Qwen4NativeChatEncoding, Qwen4SegmentTokenCache, Qwen4CompatTokenizer): Routes qwen4_moe prompts through SDK Qwen4ChatEncoder by default (DARKBLOOM_QWEN4_NATIVE_ENCODER=0 restores compat chat_template.jinja) with per-scope repeated-segment token caching (DARKBLOOM_QWEN4_ENCODER_TOKEN_CACHE=0 disables). Fails closed at discovery and load if compat tokenizer.json / chat_template.jinja are absent; maps Qwen4Tokenizer in memory.
  • Reasoning Efforts (ReasoningEffort, fixtures/prompt-contract/v1/reasoning_effort_vectors.json): Maps none/off/0/enable_thinking: false → off, minimal/low → low, medium/high → high (default), xhigh/max → xhigh; expands contract vectors to 516 reproducible cases.
  • Tools & Media (ToolChoicePromptPolicy, ModelMediaPolicy, Qwen4ImageReservation, MediaIngest+VideoBudget): Qwen XML format (ToolCallFormat.qwen35), sampler-enforced Qwen4NativeToolConstraint for required / named choices on qualified text requests, caller-order JSON tool declarations/arguments, pinned qwen4_moe_vision geometry gate, up to 16 images with per-image visual-token KV reservation (DARKBLOOM_QWEN4_IMAGE_GEOMETRY_RESERVATION=0 restores flat 1,024), and Qwen 3.5-family video caps (32 frames/clip, 4,096 visual tokens; DARKBLOOM_QWEN4_VIDEO_BUDGET=0 restores checkpoint sampling).
  • Reviewed Kill-Switch Service Passthrough (Qwen4KillSwitches, LaunchAgent, ServingPerformanceProfile): Forwards the 74 reviewed native Qwen4 SDK kill switches to launchd only at their restoring values (never diagnostics, experimental opt-ins, or inexact flags); preserves reviewed serving profiles for kernel/fusion/depth switches while dropping them for capacity-changing switches.

Omitted / Deferred Items

Item Status Reason
ProviderCore.version bump to 0.10.23 Deferred to release cut dev holds 0.10.22 until the dedicated release PR into master (docs/operations/provider-release.md).
swift-transformers 1.4.0 upgrade Deferred follow-up Qwen4ChatEncoder matches 678/678 text/segment goldens and 568/672 token IDs on swift-transformers 1.3.3 (672/672 on 1.4.0).
json_mode / structured_outputs Deferred follow-up Excluded from catalog capabilities until provider grammar path is qualified.
darkbloom-platform Activation PR & provider-contracts.py snapshot Deferred until post-merge & 0.10.23 cut Platform catalog floor stays unset ("") until 0.10.23 ships.

Placeholders / Pending Rollout Items

Item Owner / Gate
Physical Apple Silicon hardware qualification against R2 2026-12-04-r2 (M4 Max + M5 Max/Ultra, resident 64 GB+ and SSD 48 GB) Phase 4 hardware qualification
Provider release cut v0.10.23 (dev → master, signed/notarized) Phase 5 human-approved release
darkbloom-platform Activation PR (qwen4MoeRegistryMinimumProviderVersion = "0.10.23" + provider-contracts.py snapshot) Phase 6 post-release

Blast Radius / What This Could Affect

Shared Seams & Coexistence Audit (dev PRs #2925–#2933)

Every overlapping file between origin/dev (08ef86a5cb) and origin/qwen4-a3b/provider-integ (e9493a61d2) was audited for textual and semantic coexistence:

Shared File Change on This Branch Coexistence with Recent dev PRs (#2925–#2933) Isolation / Gating
provider-swift/Sources/ProviderCore/Inference/Prompting/ToolChoicePromptPolicy.swift Replaces Qwen4SupportPolicy.isOwnedModelID(...) && modelType == "qwen4_exp" with Qwen4ModelIdentity.isQualified(request.model, nativeModelType: modelType) in nativeFramingHandlesChoice. Clean disjoint hunk vs #2912 (settlesGemmaFrameAtLimit). Audited against #2926/#2928 (ToolArgumentNulls: unset default stays Qwen 3.6 + Qwen 3.5 35B only) and #2933 (TypelessNullToolSchemas: opt-in via =1, orthogonal to Qwen4 native framing). Only matches exact qualified ID + exact model_type (qwen4_exp or qwen4_moe) on text-only requests.
provider-swift/Sources/ProviderCore/Service/LaunchAgent.swift Adds passthrough for DARKBLOOM_QWEN4_PLE_SSD_OFFLOAD, DARKBLOOM_QWEN4_PLE_RESIDENCY, DARKBLOOM_QWEN4_VIDEO_BUDGET, DARKBLOOM_QWEN4_NATIVE_ENCODER, DARKBLOOM_QWEN4_ENCODER_TOKEN_CACHE, DARKBLOOM_QWEN4_IMAGE_GEOMETRY_RESERVATION, strips provider.toml-projected residency, and merges Qwen4KillSwitches.passthrough(from:). Clean disjoint hunks vs #2912 (GemmaAutoCallCheck.frameAtLimitKey), #2925 (Gemma 4 M5 Ultra defaults), #2926 (ToolArgumentNulls doc comment), and #2933 (TypelessNullToolSchemas.environmentKey). Only allowlisted Qwen4 keys; Qwen4KillSwitches.passthrough forwards strictly restoring values, never diagnostics or inexact opt-ins; never writes provider.toml-projected residency to plist.
provider-swift/Sources/ProviderCore/Inference/Engine/Scheduler/MultiModelBatchSchedulerEngine.swift Calls Qwen4ImageReservation.kvTokens(...) on non-GLM native Qwen4 media requests (Qwen4SupportPolicy.isQwen4ModelType(modelType)). Clean disjoint hunk (line 793) vs #2912 (settledGemmaCallsAtLimit at line 2615). Gated on !glmMedia && Qwen4SupportPolicy.isQwen4ModelType(modelType); DARKBLOOM_QWEN4_IMAGE_GEOMETRY_RESERVATION=0 restores flat 1,024 charge.
docs/developer/test.md Adds Qwen4-35B-A3B template/tokenizer/footprint check commands and updates reasoning_effort_vectors.json case count (446 → 516). Auto-merged cleanly alongside #2929's new ## Contribution Rules section (same 2026-12-04 freshness header, disjoint body hunks). Verified with make docs-check (0 findings). Docs only.
docs/architecture/inference.md & docs/reference/configuration.md Documents qwen4_moe / qwen4_moe_text architecture, native encoder, image reservation, video caps, n-gram residency, and 74 service-forwarded kill switches. Clean auto-merge with #2925–#2933 doc updates; updated stale newer than aa6e3672 notes for switches now landed in 64a6f34f. Docs only.
libs/mlx-swift-lm Advances gitlink 70183a70 → 64a6f34f (#579 + #584 + #586). Brings landed SDK main including Muse Glimmer #579 and Qwen4 #584/#586. Release builds refuse non-exact opt-ins (QSA_NAX, QSA_INDEXER_NAX, GDN_PIPELINED) unless compiled with -DDARKBLOOM_QWEN4_ALLOW_INEXACT.

Non-Interference Guarantees

  • Flash-Next (qwen4_exp): Keeps .ssd PLE default, 262_144 native context, its own Qwen4NativeVisionGeometry, Qwen 3.8 reasoning effort mapping, and existing kernels/outputs.
  • Qwen 3.5 / 3.6: Retains DARKBLOOM_TOOL_ARGUMENT_NULLS default behavior (#2903, #2926, #2928), independent effort tables, and GDN/MTP defaults (DARKBLOOM_QWEN_GDN_FROZEN_TREE_WALK=1 kill switch available if needed).
  • Gemma 4: Keeps M5 Ultra fused decode/layer-submit defaults (#2925) and GemmaAutoCallCheck frame-at-limit behavior (#2912) untouched.
  • Inkling 2 / Inkling 2 Mini, Nemotron 3.5 Super, GLM-5.3-Flash, Muse Glimmer, GPT-OSS, MiMo: Unaffected by Qwen4 identity, media, tokenizer, or residency policies; ModelMediaPolicy, ReasoningEffort, and EngineV2KVBackendPolicy branch on exact model ID / model_type.

Rollback / Fail-Closed Profile

  • Every new provider behavior has an explicit kill switch forwarded by LaunchAgent: DARKBLOOM_QWEN4_NATIVE_ENCODER=0, DARKBLOOM_QWEN4_ENCODER_TOKEN_CACHE=0, DARKBLOOM_QWEN4_IMAGE_GEOMETRY_RESERVATION=0, DARKBLOOM_QWEN4_VIDEO_BUDGET=0, DARKBLOOM_QWEN4_PLE_RESIDENCY=ssd (or DARKBLOOM_QWEN4_PLE_SSD_OFFLOAD=1), plus all 74 SDK kill switches in Qwen4KillSwitches.all.
  • Missing compat tokenizer.json / chat_template.jinja fails closed at discovery and load (Qwen4CompatTokenizer.Failure.missingCompatFiles).
  • Catalog activation remains gated behind darkbloom-platform's unset version floor ("") and register.template.json placeholders (prices: null, promote: false).

Before and After

Behavior

flowchart LR
  subgraph Before["Before (dev @ 08ef86a5)"]
    B1[qwen4-35b-a3b request] --> B2[Unqualified model ID / SDK @ 70183a70]
    B2 --> B3[No qwen4_moe factory, contiguous KV, text-only]
    B2 --> B4[Qwen4Tokenizer fails strict class check]
    B2 --> B5[Unsupported effort levels & flat 1,024 image KV]
  end
  subgraph After["After (feat/qwen4-35b-a3b-provider @ e83c8735)"]
    A1[qwen4-35b-a3b request] --> A2[Qualified qwen4MoE35BA3B + SDK main @ 64a6f34f]
    A2 --> A3[Paged KV, SSD prefix cache, embedded MTP, multi-row cohorts]
    A2 --> A4[Native Qwen4ChatEncoder + segment cache; compat fail-closed]
    A2 --> A5[Mapped efforts low/high/xhigh/off, per-image KV, 32f/4096t video]
    A2 --> A6[Memory-resident PLE default 39.36 GiB quote -> 64 GB floor]
  end
Loading

Code Path

flowchart TB
  subgraph Config["Config & Service"]
    TOML["provider.toml qwen4_ngram_residency_by_model"] --> NR["Qwen4NgramResidency.apply"]
    ENV["Operator env / Qwen4KillSwitches.all"] --> LA["LaunchAgent.passthroughEnvironment"]
  end
  subgraph Prompt["Prompting & Tools"]
    REQ["OpenAIChatCompletionRequest"] --> RE["ReasoningEffort.qwen4MoELevel (516 vectors)"]
    REQ --> TCP["ToolChoicePromptPolicy (nativeFramingHandlesChoice)"]
    RE --> LTL["LocalTokenizerLoader -> Qwen4NativeChatEncoding + Qwen4SegmentTokenCache"]
    LTL --> ENC["SDK Qwen4ChatEncoder (or compat Jinja fallback)"]
  end
  subgraph Runtime["Media, Memory & Engine"]
    NR --> SCAN["ModelScanner -> Qwen4ExpMmapFootprint / LoadFootprint"]
    REQ --> MEDIA["ModelMediaPolicy + Qwen4ImageReservation + MediaIngest+VideoBudget"]
    ENC --> ENG["MultiModelBatchSchedulerEngine -> SDK 64a6f34f (Qwen4Exp + CBv2 MTP)"]
    MEDIA --> ENG
  end
Loading

Before any rollout

  • Run Phase 4 Apple Silicon hardware qualification against R2 v2/qwen4-35b-a3b--97362e7471de/2026-12-04-r2 on 64 GB+ (resident PLE) and 48 GB (SSD offload) Macs across M4 and M5 (including >=1024-chunk prefill, XNU wired-limit check, MTP concurrency/long-context, XML tools, vision/video, and Flash-Next non-regression).
  • Wait for full CI (dev) green on this PR, merge into dev, and cut signed/notarized provider release v0.10.23 into master.
  • Land darkbloom-platform Activation PR setting qwen4MoeRegistryMinimumProviderVersion = "0.10.23" and running scripts/provider-contracts.py snapshot.

Validation

Verified on both Apple M4 Max and Apple M5 Max (128 GB, macOS 27.2.1, Xcode 27.2 / Swift 6.4.2) at head e83c8735567f0c0de90eb7c3a2e037161b06baa5 with libs/mlx-swift-lm at 64a6f34feffd1137f33eaaf56e6040bf296e8883:

Check / Command Environment Result
make docs-check (scripts/docs-check.sh + check-contribution-rules.py + self-test) M4 Max Pass (contribution-rules: 9 rule(s) OK, docs-check: 224 file(s) OK)
python3 scripts/test-check-contribution-rules.py M4 Max Pass (12/12 OK)
python3 scripts/docs-impact-check.py --base origin/dev M4 Max Pass (77 changed file(s), canonical documentation coverage OK)
make changelog-check M4 Max Pass (8 valid fragment(s))
python3 scripts/generate-reasoning-effort-vectors.py M4 Max Pass (516 cases, 0 diff)
python3 provider-swift/Tests/test_protocol_fixture_resources.py M4 Max Pass (3/3 OK)
python3 scripts/test-stage-test-metallib.py & test-stage-swiftpm-resource-bundles.py M4 Max Pass (12/12 + 5/5 OK)
DARKBLOOM_RELEASE_ENVIRONMENT=prod swift build --build-tests M4 Max & M5 Max (128 GB) Pass (171.02s M4 Max; 181.29s clean M5 Max)
swift test --skip-build --no-parallel --filter 'Qwen4MoE|Qwen4CompatTokenizer|Qwen4NgramResidency|Qwen4KillSwitches|Qwen4NativeChatEncoding|Qwen4SegmentTokenCache|Qwen4ImageReservation|Qwen4SupportPolicy|Qwen4ExpMmapFootprint|Qwen4ExpLoadFootprint|Qwen4ToolChoicePromptPolicy|Qwen4NativeToolConstraint|Qwen4ReasoningEffortValidation|Qwen4ReasoningControl|Qwen4MediaPolicy' M4 Max & M5 Max (128 GB) Pass (91 Swift Testing tests in 17 suites + 9 XCTest tests, 0 failures on both)
swift test --skip-build --no-parallel --filter 'LaunchAgent|ToolChoice|ToolArgumentNulls|TypelessNullToolSchemas|GemmaAutoCallCheck|ReasoningEffortValuesTests|CachePromptParityTests|HFTemplateFilters|TemplateJSONOrder|EngineV2SamplingDefaults|MTPAcceptance|ServingPerformance|SDKChipScopedDefaults|SDKOptInSpeedSwitches|StreamedToolCall|TemplateRenderCheck' M4 Max & M5 Max (128 GB) Pass (349 Swift Testing tests in 40 suites + 6 Swift Testing tests in 1 suite + 14 XCTest tests, 0 failures on both)
swift test --skip-build --filter ProviderCoreFoundationTests M4 Max & M5 Max (128 GB) Pass (63 Swift Testing tests in 8 suites + 116 XCTest tests, 0 failures on both)

Skipped / Ignored

  • Full sharded make provider-test / MiMo native weight fixture tests and landing / desktop-app JS suites (unchanged by this PR; delegated to CI).
  • Note: Running LaunchAgent*Tests without DARKBLOOM_RELEASE_ENVIRONMENT=prod defaults Package.swift on dev to io.darkbloom.provider.dev / darkbloom-dev; exporting DARKBLOOM_RELEASE_ENVIRONMENT=prod (matching .github/workflows/provider-tests.yml) passes all 14 LaunchAgent lifecycle/removal/restart tests cleanly.

Not proven

  • Physical end-to-end model load, attestation, prefill/decode throughput, MTP concurrency, XNU wired-memory behavior, and multimodal serving against the 35.24 GB R2 artifact 2026-12-04-r2 (Phase 4 hardware qualification).
  • Signed/notarized .app bundle smoke test (Qwen4ExpMetalResources.validateResources()) and release pipeline (v0.10.23).

Linked issue

Provenance: Layr-Labs/d-inference#2911 (not auto-closed; supersedes earlier 6-commit baseline).

Test plan

  • make docs-check, python3 scripts/docs-impact-check.py --base origin/dev, make changelog-check
  • DARKBLOOM_RELEASE_ENVIRONMENT=prod swift build --build-tests and unit/coexistence test suites on Apple M4 Max and Apple M5 Max (128 GB)
  • Full CI (dev) green on GitHub
  • Phase 4 hardware qualification on M4/M5 against R2 2026-12-04-r2

Components touched

  • provider-swift (Swift CLI)
  • native runtime / MLX
  • landing (Next.js)
  • enclave (Swift)
  • CI / provider release
  • docs

Protocol / interface changes

  • Yes — fixtures/prompt-contract/v1/reasoning_effort_vectors.json expanded to 516 cases (qwen4_moe / qwen4_moe_text + qwen4_moe_template_model_types); matching darkbloom-platform onboarding & post-release provider-contracts.py snapshot tracked in Phase 2 / Phase 6.

Documentation impact

  • Canonical documentation updated (docs/reference/qwen4-35b-a3b-support.md, docs/reference/configuration.md, docs/architecture/inference.md, docs/developer/test.md; docs-impact-check.py OK).

Changelog

  • Added or updated this PR's unique changelog.d/<topic>.md fragment(s) and ran make changelog-check (8 valid fragment(s)).

Refactor Pass

  • Rebased all 28 commits of origin/qwen4-a3b/provider-integ onto origin/dev (08ef86a5cb) with zero manual conflict hacks; added 1 final SSH-signed commit (e83c873556) pinning libs/mlx-swift-lm to landed main 64a6f34f and aligning changelog.d/qwen4-a3b-sdk-pin.md, docs/reference/configuration.md, and docs/reference/qwen4-35b-a3b-support.md.

Reviewer Notes

  • Start here: e83c873556 (SDK main pin 64a6f34f + docs/changelog alignment), ToolChoicePromptPolicy.swift, LaunchAgent.swift, Qwen4NgramResidency.swift, Qwen4KillSwitches.swift, and MultiModelBatchSchedulerEngine.swift (image KV reservation).
  • Zero textual conflicts on rebase: Both dev (#2929) and provider-integ bumped docs/developer/test.md freshness header to 2026-12-04 and edited disjoint sections; all 6 overlapping files merged cleanly and were verified by coexistence tests (LaunchAgent, ToolChoice, ToolArgumentNulls, TypelessNullToolSchemas, GemmaAutoCallCheck, ServingPerformance).

Prove it works
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

jonathan308 and others added 29 commits December 5, 2026 21:53
Qwen4-35B-A3B declares qwen4_moe / qwen4_moe_text. The native engine,
embedded MTP, prefix-cache load hash, reasoning, stream guards and tool
format checks now take those types as they take qwen4_exp. Identity-gated
features (media, the native tool constraint, effort templates) still key
on qualified registry IDs. Pins the SDK branch that adds the types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qwen4ModelIdentity names two builds: Flash-Next (qwen4_exp) and
Qwen4-35B-A3B (qwen4_moe), whose IDs are qwen4-35b-a3b, the served
artifact EigenLabs/Qwen4-35B-A3B-MLX-4bit-mtp and the upstream alias
mlx-community/Qwen4-35B-A3B-oQ4e-mtp. The A3B IDs take the native Qwen4
listing, automatic paged KV and SSD prefix checkpoints; their listing
quotes the native 1,048,576-token window. Media is served for each build
only with its own exact geometry (A3B: text 2,048 x 40, qwen4_moe_vision
tower 27 x 1,152, out 2,048). Native tool framing and inner-reasoning
handling require a qualified ID with its build's own type, and the media
path passes the loaded wrapper's real type. Omitted sampling knobs take
the A3B checkpoint's generation_config.json. Flash-Next's Qwen 3.8 effort
template stays with Flash-Next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qwen4-35B-A3B's template takes xhigh, high (its default), low and off,
and raises for any other effort, for off with thinking on and for any
other effort with thinking off. For qwen4_moe and qwen4_moe_text every
client effort now renders one of them: none, minimal and low render low,
medium and high render high, xhigh and max render xhigh while thinking,
and a thinking switch off (none, off, 0 or enable_thinking false) renders
off. The effort vectors add both types, a family for them and the set
qwen4_moe_template_model_types (516 cases).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qwen publishes the model's tokenizer and chat encoder as remote Python
code; the served artifact carries Qwen's tokenizer-compat tokenizer.json
and chat_template.jinja at its root. For qwen4_moe types the loader reads
the remote-code class name Qwen4Tokenizer as the byte-level BPE model
tokenizer.json holds, in memory; a snapshot without the two files is
skipped at discovery and refused at load with a clear error instead of
rendering without them.

Every prompt of the family renders tool declarations and arguments as the
trained encoder writes them: Transformers' tojson (members in the order
sent, ", " and ": " separators, no escaping) and the caller's JSON, with
tool-call arguments parsed from their JSON strings in order.

A fixture pins the served template (the upstream compat template with the
loop variable call, which swift-jinja reserves, renamed) and checks that
it renders the reference encoder's strings through the prompt pipeline:
every effort, both thinking switches, earlier reasoning, tool calls,
reordered tool results, media placeholders and five encoder golden cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK keeps Qwen4-35B-A3B's n-gram table resident by default and
Flash-Next's on SSD; DARKBLOOM_QWEN4_PLE_SSD_OFFLOAD chooses one for
every Qwen4 model. The LaunchAgent now forwards it.

[backend] qwen4_ngram_residency_by_model (model ID to memory or ssd) is
projected into that switch before models are scanned, so a model's quote
and its load agree. A map one switch value cannot honour, unknown IDs and
unknown values are logged and leave the defaults; an operator's value
wins. A projected value is marked and never written into the service
plist.

Memory quotes follow the residency the SDK loads each type with: in
memory, every weight with the ordinary allowance and no offload credit;
on SSD, the resident weights plus the native loading allowance with the
offloaded bytes reported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A support reference for Qwen4-35B-A3B (identity, efforts, compat
tokenizer and template, media gate, n-gram residency and memory quotes),
the residency controls in the configuration and CLI references, the
memory quotes in the hardware requirements, and a changelog fragment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A qwen4-35b-a3b clip was sampled with the checkpoint's own settings: 2 fps,
up to 768 frames and 25,165,824 clip pixels (12,288 visual tokens) per
clip. Its IDs now take the Qwen 3.5-family caps (32 frames a clip, 4,096
visual tokens shared by a request's clips), which the SDK's
Qwen4ExpProcessor reads from processing.video (an SDK without that keeps
ignoring them). DARKBLOOM_QWEN_VIDEO_MAX_FRAMES / _MAX_TOKENS tune them;
DARKBLOOM_QWEN4_VIDEO_BUDGET=0 keeps the checkpoint's sampling, and the
LaunchAgent forwards it. Flash-Next and other models are unchanged.

Tests: Qwen4MoEVideoBudgetTests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves libs/mlx-swift-lm from qwen4-a3b/support (1fbe8a49) to
qwen4-a3b/qual (688ec3dc): qwen4-a3b/integration (A3B kernels, decode
fusions, n-gram memory/SSD residency with the GPU gather) plus the native
Qwen4ChatEncoder, the reserved-token mask in the qwen4_moe heads and
Qwen4ExpProcessor's video caps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SDK now resolves a Qwen4 model's n-gram residency from
DARKBLOOM_QWEN4_PLE_RESIDENCY (memory or ssd) before
DARKBLOOM_QWEN4_PLE_SSD_OFFLOAD. Both footprints already quote through
that resolution (useMmap(forModelType:)), but Qwen4NgramResidency only
knew the legacy switch: an operator's named switch did not count as an
override of qwen4_ngram_residency_by_model, and the LaunchAgent did not
forward it. It is now both. A loaded native Qwen4 model logs the residency
it reports (Qwen4ExpPLEResidencyReporting) beside the one its memory was
quoted for, with a warning when they differ.

Tests: Qwen4NgramResidencyTests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qwen4-35B-A3B's own tokenizer renders a conversation as segments and
tokenizes each alone (encoding_qwen4.py): scaffolding recognises special
tokens, message data never does. The compat template rendered once and
tokenized once merges across segment boundaries (about 30% of tool
conversations get other IDs) and turns special-token text in messages
into control tokens.

With DARKBLOOM_QWEN4_NATIVE_ENCODER=1 (read once per process, off by
default) the tokenizer bridge of a qwen4_moe model renders every prompt
with the SDK's Qwen4ChatEncoder: messages, tools and earlier calls'
arguments from the same template inputs (ordered Jinja values keep the
request's member order), reasoning_effort / enable_thinking /
preserve_thinking from the template context, scaffolding tokenized by
the served tokenizer and data by a second instance of the same
tokenizer.json without added tokens. Media requests reach it through the
SDK processor, whose placeholders it renders. The prompt token cache is
off for that model while it is on. The LaunchAgent forwards the switch.

Tests: Qwen4NativeChatEncodingTests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The media gate reserved a flat 1,024 KV tokens per image
(MediaIngest.visionTokensPerImage). A native Qwen4 checkpoint resizes each
image within its own bounds: a Qwen4-35B-A3B image renders up to 16,384
visual tokens (3000x2000 rendered 5,828 on sd2), so 16 large images could
hold ~262K tokens of KV against 16K reserved.

For a qwen4_* model the gate now prices each inline image from its header
size through the loaded processor's exact resize
(Qwen4ExpProcessor.imageVisualTokens), plus its two vision delimiters, and
keeps the rest of the projection (text, videos, output, context clamp).
A request with an image whose size can't be read keeps the flat charge;
DARKBLOOM_QWEN4_IMAGE_GEOMETRY_RESERVATION=0 keeps it for every request
(forwarded by the LaunchAgent). Admission only: prompts and outputs are
unchanged.

Tests: Qwen4ImageReservationTests.

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

The Qwen4-35B-A3B reference now states the video caps it takes, the
per-image KV reservation, the opt-in native encoder, the reserved-token
mask in the SDK heads and the SDK's named n-gram residency switch;
configuration.md lists DARKBLOOM_QWEN4_PLE_RESIDENCY,
DARKBLOOM_QWEN4_VIDEO_BUDGET, DARKBLOOM_QWEN4_IMAGE_GEOMETRY_RESERVATION,
DARKBLOOM_QWEN4_NATIVE_ENCODER, DARKBLOOM_QWEN4_RESERVED_TOKEN_MASK and
DARKBLOOM_RESPONSES_TEXT_FORMAT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…reservation and encoder

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves libs/mlx-swift-lm to the qwen4-a3b/qual head: the reserved-token
mask writes the lowest finite logit (CBv2 refuses non-finite logits),
Qwen4ExpProcessor reports each image's visual tokens, and /v1/responses
reads text.format.

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

DARKBLOOM_QWEN4_BATCHED_QSA keeps its meaning when present (exactly 1
batches, anything else keeps one row). Unset, the provider installs the
target's own default (cbv2Qwen4BatchesByDefault): exact multirow targets
(35B-A3B) admit up to their installed row limit, Flash-Next stays at one
row. The concurrency limit uses the same predicate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Runtime concurrency rows carry distinct prompts ("Request N. ..."), so a
batched row can only be compared with its own prompt run alone. With
DARKBLOOM_BENCH_SOLO_REFERENCES=1 the one-row cell also measures every
wider row's prompt alone on the one-row slot (extra one-row cells; rows
match by promptTokensSHA256). Default runs are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DARKBLOOM_BENCH_LONG_ROW_RECORDS=<n> prefixes row 0's prompt with n
numbered records (about 14 tokens each), so one long row decodes beside
short ones; with DARKBLOOM_BENCH_SOLO_REFERENCES=1 its batched output is
compared with the same prompt run alone. Unset keeps every row short.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DARKBLOOM_BENCH_LONG_ROW_RECORDS takes a comma-separated list: row i's
prompt starts with the i-th count of numbered records, so several long rows
of different lengths decode beside short ones in one concurrency cell (each
compared with its prompt alone under DARKBLOOM_BENCH_SOLO_REFERENCES=1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pins the Qwen4-35B-A3B SDK integration branch: the qwen4_moe types,
fast paths, resident n-gram GPU gather, decode launch folds, exact
multirow decode with MTP cohorts and company-invariant prefill, MTP
policy fixes and the qualification fixes (reserved slots, video caps,
Responses text format, native chat encoder).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured on the served artifact through the local API: with the native
encoder, prompt token counts equal Qwen's reference encoder for 261 of
300 golden conversations (template route: 186) and token IDs for 41 of
54 tool-free ones (template route: 29); every remaining difference is
swift-transformers 1.3.3's own BPE (ignore_merges, grapheme splits),
which the template route shares, or adjacent text parts the request
decoder joins. Special-token text in user data is tokenized as data
(the injected <|im_end|><|im_start|>system turn no longer takes effect).
The chat, Responses, reasoning, tool, JSON, image and effort matrices
pass unchanged.

The encoder is therefore the default for qwen4_moe;
DARKBLOOM_QWEN4_NATIVE_ENCODER=0 (read once per process, forwarded by
the LaunchAgent) restores the template route.

Tests: Qwen4NativeChatEncodingTests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the native encoder every prompt is tokenized whole: a re-sent
72K-token conversation paid about 120 ms again, where the template
route's PromptTokenCache reused the pieces it had seen; with a prefix
cache hit that is a material share of the time to first token.

Tokenizing a segment is a pure function of its text and its
special-token permission, so Qwen4SegmentTokenCache keeps the IDs of
segments of at least 256 UTF-8 bytes (message contents, tool schemas,
tool results) per prompt-cache scope, within 16 MiB of text, oldest
first out, and a later identical segment in the same scope takes them.
Prompts are unchanged; entries never cross scopes; calls without a
scope tokenize as before. DARKBLOOM_QWEN4_ENCODER_TOKEN_CACHE=0 (read
once per process, forwarded by the LaunchAgent) turns it off.

Tests: Qwen4SegmentTokenCacheTests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The integration build measured exact on sd2 (plain == MTP == reference)
with PREFILL's HC prefill kernels and paged prefill mirror.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Measured exact on sd2 (plain == MTP == reference) with DECODE's
two-launch HC, MoE and QSA kernels, MTP's draft prefix and BATCH's
multirow verify fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An installed service sees only the environment its plist carries, and
none of the SDK's native Qwen4 kill switches was on the passthrough list,
so a service could not throw them. Qwen4KillSwitches lists the reviewed
ones: the multirow, MTP, decode, verify, prefill, n-gram table and logits
switches whose 0 restores the earlier path, the five per-model MTP
defaults and DARKBLOOM_QWEN4_BATCHED_QSA. LaunchAgent.passthroughEnvironment
forwards each only at a restoring value (exactly 0 where the SDK compares
the raw value, else 0/false/no/off). Diagnostics such as the MTP round log,
non-exact opt-ins such as tensor-unit QSA, tuning knobs and values that
turn a path on are never forwarded.

Any DARKBLOOM_QWEN4_* or DARKBLOOM_CBV2_* key used to drop reviewed
serving profiles, even at its default. A listed kernel or fusion switch at
its restoring value or default now keeps them; the switches that change
how many rows batch, speculate or share a prefill step (BATCHED_QSA,
MULTIROW, COMPANY_INVARIANT_PREFILL, MTP_COHORTS, MTP_ROW_WIDTHS) and
every other key still drop them.

Tests: Qwen4KillSwitchesTests (the reviewed list, forwarding only
restoring values, profile retention by switch kind) and
qwen4KernelKillSwitchesKeepTheReviewedProfile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The configuration reference lists the forwarded Qwen4 kill switches with
their restoring values, which change capacity and which are read only by
SDK integrations newer than the provider's pin; the qualification guide
and the inference architecture note which ones keep reviewed serving
profiles. Changelog fragment included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Carries the exact Qwen4 GDN conv (precise sigmoid), BATCH's multirow
and cohort routes, and MTP's depth policy.

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

Thirteen switches the SDK integration and its prefill lane added since the
list was written join Qwen4KillSwitches.all (74 in all):
- kernel and fusion switches, forwarded at 0 (or false/no/off) and keeping
  reviewed serving profiles: MULTIROW_GDN_STEP, MULTIROW_MOE_FOLDS,
  MULTIROW_QSA_FOLDS, MULTIROW_QMV_GROUPED, INDEX_ROW_BATCH, GDN_PACKED and
  HC_WIDE_SPLIT (exactly 0);
- capacity switches, forwarded at their restoring value but still dropping
  reviewed profiles: WIDE_PREFILL (prompt step width) and the cohort draft
  policy MTP_CHAINED_BASELINE and CBV2_MTP_CHAINED_PROBE;
- three whose new behaviour removed a rule, so 1 (or true/yes/on) restores
  it and is the only value forwarded: MTP_D3_BUMP,
  MTP_COPY_ROUNDS_AS_SAMPLES and DARKBLOOM_QWEN_GDN_FROZEN_TREE_WALK
  (Restore.onWord).

Tests: Qwen4KillSwitchesTests (the list, forwarding by restoring value for
each restore kind, profile retention by switch kind) and
qwen4KernelKillSwitchesKeepTheReviewedProfile.

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

vercel Bot commented Dec 6, 2026

Copy link
Copy Markdown

@GumbiiDigital is attempting to deploy a commit to the EigenLabs Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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