Skip to content

Provider: serve Qwen4-35B-A3B on the native Qwen4 stack - #2911

Draft
jonathan308 wants to merge 6 commits into
devfrom
feat/qwen4-35b-a3b
Draft

jonathan308 wants to merge 6 commits into
devfrom
feat/qwen4-35b-a3b

Conversation

@jonathan308

@jonathan308 jonathan308 commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Depends on

  • SDK: the libs/mlx-swift-lm gitlink pins Layr-Labs/mlx-swift-lm qwen4-a3b/support (1fbe8a49). That commit adds the qwen4_moe / qwen4_moe_text types to the native Qwen4 factories and the per-type n-gram residency default. It isn't on main yet, so CI can't check out the submodule until the SDK change lands. The gitlink then moves to the SDK merge commit, together with the SDK's A3B fast paths, the resident n-gram GPU gather and the native chat encoder, which go up as separate SDK PRs.
  • Artifact: EigenLabs/Qwen4-35B-A3B-MLX-4bit-mtp (private on Hugging Face, revision 3f7abd9fffb3676b8c5cec92d82f66a7d54fb118). Providers download it from R2 under v2/qwen4-35b-a3b--97362e7471de/2026-12-04-r2.
  • Coordinator: the matching onboarding in darkbloom-platform; its catalog floor stays unset until a provider release includes this.

Summary

Qwen4-35B-A3B (qwen4_moe) runs on the native Qwen4 stack that serves Flash-Next. This change qualifies its IDs and
gives it its own media geometry, effort levels, tokenizer and template handling, and n-gram table residency.

  • Identity. Qwen4ModelIdentity names two builds: Flash-Next (qwen4_exp) and Qwen4-35B-A3B (qwen4_moe).
    The A3B 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. They get:

    • the native Qwen4 listing;
    • automatic paged KV;
    • complete SSD prefix checkpoints;
    • embedded MTP with exact acceptance;
    • continuous batching;
    • the native 1,048,576-token context, with no cap.
  • Sampling. A request that omits sampling fields gets the checkpoint's generation_config.json: temperature 1.0,
    top-p 0.95, top-k 20. These are the card's thinking-mode values. There is no presence penalty, so MTP rows keep
    drafting.

  • Efforts. The template takes xhigh, high (its default), low and off. For qwen4_moe and
    qwen4_moe_text, every client effort renders one of them:

    • none, minimal and low render low;
    • medium and high render high;
    • xhigh and max render xhigh;
    • a thinking switch set off renders off with enable_thinking: false.

    reasoning_effort_vectors.json adds both types and their cases (516 in total). It also adds a new set,
    qwen4_moe_template_model_types.

  • Tools.

    • Calls use Qwen's XML format.
    • For a qualified ID with type qwen4_moe, required and named choices keep the trained template. The sampler
      frames the call (Qwen4NativeToolConstraint).
    • Every prompt renders tool declarations and arguments the way the trained encoder writes them: Transformers'
      tojson, members in the order the caller sent them, and arguments parsed from their JSON strings in that order.
  • Media. Images and video are served only for the qualified IDs, and only with the published geometry:

    • text: hidden size 2,048, 40 layers;
    • vision: a qwen4_moe_vision tower with 27 blocks, hidden size 1,152, 16 heads, output 2,048, 16 px patches,
      2x2 merge and temporal pairs, gelu_pytorch_tanh, no DeepStack.

    Requests take up to 16 images. Each image is sized within the checkpoint's bounds by the SDK processor.

  • Tokenizer and template. The model is served from Qwen's compat tokenizer.json and chat_template.jinja.

    • The loader reads the remote-code class name Qwen4Tokenizer as byte-level BPE. This happens in memory; the
      files are not changed.
    • A snapshot without those two files is skipped at discovery and refused at load with a clear error. It never
      reports a failing render check.
    • A pinned fixture checks the served template against Qwen's reference encoder, through the prompt pipeline.
  • N-gram residency. The 12.8 GB n-gram table stays in memory by default.

    • [backend] qwen4_ngram_residency_by_model = { "qwen4-35b-a3b" = "ssd" } reads its rows from SSD, and so does
      DARKBLOOM_QWEN4_PLE_SSD_OFFLOAD=1.
    • The LaunchAgent now forwards DARKBLOOM_QWEN4_PLE_SSD_OFFLOAD. A value that provider.toml projected is never
      written into the service plist.
    • Memory quotes follow the residency the model loads with:
      • in memory: 35,215,477,491 bytes of weights, quoted with the ordinary allowance, and no offload credit;
      • on SSD: 22,415,190,771 bytes resident plus the native loading allowance (6,207,584,304 bytes), with
        ssd_offloaded_weight_bytes 12,800,286,720.
  • Benchmarks. darkbloom benchmark drives it through the native Qwen4 path, so --scheduler-prefill, --sweep
    and --runtime-generation --runtime-mtp --kv-backend paged work on it.

  • Minimum provider version. The coordinator floor for qwen4-35b-a3b should be the first provider release that
    contains this change, after 0.10.20.

Before / After: behaviour

flowchart LR
  subgraph Before
    A1[qwen4-35b-a3b request] --> B1[qwen4_moe recognised as a type only]
    B1 --> C1[contiguous KV, no prefix cache default, text-only]
    B1 --> D1[effort passed as sent: medium/max/none raise in the template]
    B1 --> E1[tokenizer_class Qwen4Tokenizer: load fails]
    B1 --> F1[quote assumes SSD n-gram rows the SDK does not use]
  end
  subgraph After
    A2[qwen4-35b-a3b request] --> B2[qualified build qwen4MoE35BA3B]
    B2 --> C2[paged KV, SSD prefix checkpoints, MTP, media with pinned geometry]
    B2 --> D2[efforts mapped to low/high/xhigh, off with thinking off]
    B2 --> E2[compat tokenizer.json + template; missing files fail closed]
    B2 --> F2[quote follows the n-gram residency: memory default, SSD option]
  end
Loading

Before / After: code path

flowchart TB
  subgraph Before
    I1[Qwen4ModelIdentity: Flash-Next IDs] --> P1[ModelMediaPolicy: Flash-Next geometry only]
    R1[ReasoningEffortPolicy: Qwen 3.8 levels for Flash-Next] --> T1[template context]
    L1[LocalTokenizerLoader] --> X1[swift-transformers strict class check]
    S1[ModelScanner.parseModelInfo] --> Q1[Qwen4ExpMmapFootprint: useMmap ignores type]
  end
  subgraph After
    I2[Qwen4ModelIdentity.Build: flashNext / qwen4MoE35BA3B] --> P2[Qwen4NativeVisionGeometry per build]
    R2[ReasoningEffort.qwen4MoELevel + qwen4MoETemplateTypes] --> T2[template context]
    L2[LocalTokenizerLoader + Qwen4CompatTokenizer] --> X2[class resolved in memory; files required]
    H2[HFTemplateFilters + TemplateJSONOrder: qwen4_moe always caller JSON] --> T2
    C2[provider.toml qwen4_ngram_residency_by_model] --> N2[Qwen4NgramResidency.apply in loadRuntimeSnapshot]
    N2 --> S2[ModelScanner.parseModelInfo]
    S2 --> Q2[Qwen4ExpMmapFootprint / LoadFootprint: SDK per-type residency]
  end
Loading

Tests

New suites and tests:

Suite What it covers
Qwen4MoEMediaPolicyTests geometry gate
Qwen4MoESupportPolicyTests listing, paged KV, prefix cache, context, tool framing, sampling defaults
ReasoningEffortValuesTests (A3B levels) effort levels by type
CachePromptParityTests.reasoningEffortVectors 516 cases and the new set
Qwen4MoETemplateParityTests 18 request cases (5 from an encoder golden file), 2 media-placeholder cases, the scan-time render check, the pinned template hash
Qwen4CompatTokenizerTests the class resolution; the fail-closed load
Qwen4NgramResidencyTests the projection, the operator's override, LaunchAgent forwarding and non-persistence, the config key
Qwen4MoEFootprintTests both quotes on a sparse stand-in with the published shard layout; discovery skipping a snapshot without the compat files
HFTemplateFiltersTests qwen4_moe always renders Transformers' filters

Run locally: a debug swift build --build-tests on an M5 Ultra, then filtered swift test --skip-build runs.

  • Changed and neighbouring suites:

    • 311 Swift Testing tests in 35 suites passed;
    • 23 XCTest tests passed (Qwen4MoEMediaPolicyTests, Qwen4MediaPolicyTests, TemplateRenderCheckTests).

    These include Qwen4SupportPolicyTests, Qwen4ExpMmapFootprintTests, Qwen4ExpLoadFootprintTests, the Qwen4
    tool and reasoning suites, TemplateJSONOrderTests, Inkling2PromptContractTests, Flint template replay,
    MTPAcceptanceConfigTests and EngineV2SamplingDefaultsTests.

  • Prompt and tokenizer neighbours: 95 Swift Testing tests in 15 suites passed, plus 32 XCTest tests. These are
    ProductionPromptParityTests, ToolCallTemplateArgumentsTests, JinjaSanitizationTests, the SwiftJinja suites,
    PromptTokenCacheTests, the LocalTokenizer suites, Qwen35TemplateFixesTests, QwenStrayThinkClose,
    GenerationLoopGuard and ReasoningPromptProbe.

  • Config, scanner and media neighbours: 225 of 227 Swift Testing tests passed, plus 18 XCTest tests. The two failures
    are unrelated to this change:

    • scannerMiMoNativeLoadQuoteIsNotGenericDiskPadding needs MIMO_V26_SERIAL_LOAD_FIXTURES;
    • ProviderConfigParseGrowthTests measures process memory and failed only while running in parallel with other
      suites. Rerun alone, it passed.
  • scripts/generate-reasoning-effort-vectors.py is reproducible: before the change, the unmodified script still
    wrote the committed file byte for byte.

  • scripts/generate-qwen4-moe-template-vectors.py --template passed: Jinja2, configured as Transformers configures
    it, renders the served template to the reference encoder's string for every case.

  • make docs-check passed. docs-impact-check passed: 52 changed files, coverage OK.

Notes

  • Prompt strings match the encoder. Token IDs can still differ on this route, because the template renders one
    string and the tokenizer encodes it once. The encoder tokenizes each segment on its own, and message data never
    becomes control tokens there. A native segment-wise encoder is the follow-up (see open questions).
  • The 243 reserved token IDs 248077–248319 are missing from tokenizer.json and are not masked during sampling yet.
    Masking them needs an SDK change.
  • Each Qwen4 model keeps a single n-gram residency per process, because the SDK reads one switch. A
    provider.toml map that asks one build for SSD and another for memory, against their defaults, is logged and
    leaves both defaults.

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

jonathan308 and others added 6 commits December 3, 2026 19:02
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>
@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference-landing Ready Ready Preview Dec 4, 2026 4:00am UTC
darkbloom-status Ready Ready Preview Dec 4, 2026 4:00am UTC
eigen-homepages-darkbloom Ready Ready Preview Dec 4, 2026 4:00am UTC

Request Review

This branch was successfully deployed

3 active deployments
Preview – d-inference-landing — d4e25d2e Deployed Dec 4, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — d4e25d2e Deployed Dec 4, 2026 by vercel[bot]
Preview – darkbloom-status — d4e25d2e Deployed Dec 4, 2026 by vercel[bot]
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.

1 participant