Repository navigation
Provider: serve Qwen4-35B-A3B on the native Qwen4 stack - #2911
Draft
jonathan308 wants to merge 6 commits into
Draft
jonathan308 wants to merge 6 commits into
jonathan308 wants to merge 6 commits into
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on
libs/mlx-swift-lmgitlink pins Layr-Labs/mlx-swift-lmqwen4-a3b/support(1fbe8a49). That commit adds theqwen4_moe/qwen4_moe_texttypes to the native Qwen4 factories and the per-type n-gram residency default. It isn't onmainyet, 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.EigenLabs/Qwen4-35B-A3B-MLX-4bit-mtp(private on Hugging Face, revision3f7abd9fffb3676b8c5cec92d82f66a7d54fb118). Providers download it from R2 underv2/qwen4-35b-a3b--97362e7471de/2026-12-04-r2.Summary
Qwen4-35B-A3B (
qwen4_moe) runs on the native Qwen4 stack that serves Flash-Next. This change qualifies its IDs andgives it its own media geometry, effort levels, tokenizer and template handling, and n-gram table residency.
Identity.
Qwen4ModelIdentitynames two builds: Flash-Next (qwen4_exp) and Qwen4-35B-A3B (qwen4_moe).The A3B IDs are
qwen4-35b-a3b, the served artifactEigenLabs/Qwen4-35B-A3B-MLX-4bit-mtp, and the upstreamalias
mlx-community/Qwen4-35B-A3B-oQ4e-mtp. They get: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),lowandoff. Forqwen4_moeandqwen4_moe_text, every client effort renders one of them:none,minimalandlowrenderlow;mediumandhighrenderhigh;xhighandmaxrenderxhigh;offwithenable_thinking: false.reasoning_effort_vectors.jsonadds both types and their cases (516 in total). It also adds a new set,qwen4_moe_template_model_types.Tools.
qwen4_moe, required and named choices keep the trained template. The samplerframes the call (
Qwen4NativeToolConstraint).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:
qwen4_moe_visiontower 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.jsonandchat_template.jinja.Qwen4Tokenizeras byte-level BPE. This happens in memory; thefiles are not changed.
reports a failing render check.
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 doesDARKBLOOM_QWEN4_PLE_SSD_OFFLOAD=1.DARKBLOOM_QWEN4_PLE_SSD_OFFLOAD. A value thatprovider.tomlprojected is neverwritten into the service plist.
ssd_offloaded_weight_bytes12,800,286,720.Benchmarks.
darkbloom benchmarkdrives it through the native Qwen4 path, so--scheduler-prefill,--sweepand
--runtime-generation --runtime-mtp --kv-backend pagedwork on it.Minimum provider version. The coordinator floor for
qwen4-35b-a3bshould be the first provider release thatcontains 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] endBefore / 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] endTests
New suites and tests:
Qwen4MoEMediaPolicyTestsQwen4MoESupportPolicyTestsReasoningEffortValuesTests(A3B levels)CachePromptParityTests.reasoningEffortVectorsQwen4MoETemplateParityTestsQwen4CompatTokenizerTestsQwen4NgramResidencyTestsQwen4MoEFootprintTestsHFTemplateFiltersTestsqwen4_moealways renders Transformers' filtersRun locally: a debug
swift build --build-testson an M5 Ultra, then filteredswift test --skip-buildruns.Changed and neighbouring suites:
Qwen4MoEMediaPolicyTests,Qwen4MediaPolicyTests,TemplateRenderCheckTests).These include
Qwen4SupportPolicyTests,Qwen4ExpMmapFootprintTests,Qwen4ExpLoadFootprintTests, the Qwen4tool and reasoning suites,
TemplateJSONOrderTests,Inkling2PromptContractTests, Flint template replay,MTPAcceptanceConfigTestsandEngineV2SamplingDefaultsTests.Prompt and tokenizer neighbours: 95 Swift Testing tests in 15 suites passed, plus 32 XCTest tests. These are
ProductionPromptParityTests,ToolCallTemplateArgumentsTests,JinjaSanitizationTests, theSwiftJinjasuites,PromptTokenCacheTests, theLocalTokenizersuites,Qwen35TemplateFixesTests,QwenStrayThinkClose,GenerationLoopGuardandReasoningPromptProbe.Config, scanner and media neighbours: 225 of 227 Swift Testing tests passed, plus 18 XCTest tests. The two failures
are unrelated to this change:
scannerMiMoNativeLoadQuoteIsNotGenericDiskPaddingneedsMIMO_V26_SERIAL_LOAD_FIXTURES;ProviderConfigParseGrowthTestsmeasures process memory and failed only while running in parallel with othersuites. Rerun alone, it passed.
scripts/generate-reasoning-effort-vectors.pyis reproducible: before the change, the unmodified script stillwrote the committed file byte for byte.
scripts/generate-qwen4-moe-template-vectors.py --templatepassed: Jinja2, configured as Transformers configuresit, renders the served template to the reference encoder's string for every case.
make docs-checkpassed.docs-impact-checkpassed: 52 changed files, coverage OK.Notes
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).
tokenizer.jsonand are not masked during sampling yet.Masking them needs an SDK change.
provider.tomlmap that asks one build for SSD and another for memory, against their defaults, is logged andleaves both defaults.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.