Repository navigation
Description
Summary
Load the official Red Hat Speculators and OpenBMB DSpark drafters (for example RedHatAI/Qwen3-4B-speculator.dspark for Qwen/Qwen3-4B, and openbmb/MiniCPM5-2B-DSpark for openbmb/MiniCPM5-2B, a llama target) and drive them against dense Qwen3 and Llama targets. mlxcel's DSpark support is LFM2-only today (#1339): the config parser does not read either checkpoint layout, the drafter assumes the draft and target vocabularies are the same, and neither Qwen3 nor Llama is a DFlash-family target.
Upstream reference
Neywa-Labs/mlx-vlm#2676 (merge 6291b6ca, commit 9891c730):
- https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/speculative/drafters/dspark/config.py (
DSparkConfig.from_dict,validate) - https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/speculative/drafters/dspark/dspark.py (
VanillaMarkovwithdraft_vocab_size,d2t, ownlm_head,sanitize) - https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/speculative/drafters/compatibility.py (
validate_dflash_target) - Target capture and verify on https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/models/qwen3/language.py and
models/llama/language.py(capture_layer_ids,speculative_verify,rollback_speculative_cache); the same commit touchesmistral3,mistral4andkimi_k3, out of scope here.
Behavior (from upstream code and the two configs)
- Speculators layout (
RedHatAI/...speculator.dspark,speculators_model_type: dspark,architectures: [DSparkDraftModel]): the draft backbone lives intransformer_layer_config(model_type qwen3, 5 layers, hidden 2560,layer_typesallsliding_attention,sliding_window 2048); root fields areaux_hidden_state_layer_ids [1, 9, 17, 25, 33](the target taps),block_size 7,mask_token_id 151669,markov_rank 256,draft_vocab_size 151936,sample_from_anchor true,sliding_window_non_causal false,enable_confidence_head true.from_dictmergestransformer_layer_configunder the root, mapsaux_hidden_state_layer_idstotarget_layer_ids, setsis_causalto None, and synthesizesdflash_config = {projector_type: dspark}. - OpenBMB layout (
openbmb/MiniCPM5-2B-DSpark,architectures: [Qwen3DSparkModel]): flat root config withtarget_layer_ids [1, 10, 20, 30, 39],num_target_layers 42,block_size 7,mask_token_id 75982,draft_vocab_size 130560,projector_type dspark, full attention. - Block size: the checkpoint
block_sizecounts proposals unless the anchor is included (dspark_bonus_anchor, or a Speculators checkpoint withsample_from_anchor: false); the verify width isblock_size + 1otherwise. num_target_layersis optional; when absent, each tap is validated against the bound target's depth, not derived asmax(taps) + 1.- Reduced draft vocabulary: when
draft_vocab_size < vocab_size, the drafter ownslm_head [draft_vocab, hidden],markov_w2projects todraft_vocab, and a sampled draft idtmaps to the target idt + d2t[t](d2tint32, from the checkpoint;t2dis ignored).draft_vocab_sizemust satisfy0 < draft_vocab_size <= vocab_size. A checkpoint that shipslm_head.weightkeeps its own head even at full vocabulary. - Targets: Qwen3 and Llama return the hidden state after each tapped layer, and their verify forward is followed by a KV trim to the accepted length (attention-only, no recurrent state).
Current mlxcel behavior
DFlashConfig::from_json(src/lib/mlxcel-core/src/drafter/dflash/config.rs:278-315) flattens only a nesteddflash_config;is_dflash_drafter_config(:379-420) keys on that block or the DFlash architectures, so neither official layout is recognized. The struct has nodraft_vocab_size,layer_types,sliding_window,sample_from_anchororaux_hidden_state_layer_ids, andnum_target_layersdefaults (:125,:201).VanillaMarkovHead(src/lib/mlxcel-core/src/drafter/dflash/markov.rs:43-145) checks both factors against onevocab, so a reducedmarkov_w2is rejected.- DFlash-family targets are Qwen 3.5, LFM2, Muse Glimmer and Laguna (
impl DFlashTargetModelinsrc/server/batch/dflash_target.rs:254-380).LoadedModel::Qwen3andLoadedModel::Llama(src/loaded_model.rs:44,:55) have no capture or verify hooks.DFlashDrafterFamily::DSpark(dflash_target.rs:145) and its decline message (:454) describe it as the LFM2 drafter.
Required changes
- Config (
dflash/config.rs): accept both layouts infrom_jsonas above; adddraft_vocab_size: Option<usize>(defaults tovocab_size),layer_types,sliding_window,sample_from_anchorand an optionalnum_target_layers; teachis_dflash_drafter_configto recognizespeculators_model_type == "dspark"andQwen3DSparkModel. Reject adraft_vocab_sizeoutside1..=vocab_sizeat load. - Drafter (
dflash/model.rs,dflash/drafter.rs,dflash/markov.rs): sliding-window draft attention whenlayer_typessays so (window fromsliding_window). Causality follows upstreamDFlashAttention(https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/speculative/drafters/qwen3_dflash/dflash.py): an explicitis_causalwins; when it is null, as Speculators sets it, a layer is causal exactly when it is sliding andsliding_window_non_causalis false; the reduced-vocabulary head plusd2tremap applied to every sampled draft id before it leaves the drafter; ignoret2d; keep a shippedlm_headinstead of binding the target's. - Targets: implement
DFlashTargetModelforQwen3ModelandLlama3Model(hidden capture attarget_layer_ids, multi-row verify, KV trim on finalize, the block-versus-chainexactness_allowsprobe), and add both to the DFlash dispatch insrc/server/batch/speculative_burst.rs,src/commands/generate.rsandsrc/bin/speculative_bench.rs. Validate at bind time that every tap is below the target depth and thatvocab_sizematches; mismatches are errors naming both numbers. - Family gating: rename the decline text so
DSparkno longer says "LFM2" only. Qwen3 and Llama keeprequired_drafter_family() = None, as Qwen 3.5 does.
Scope
In scope: the two layouts, reduced draft vocabulary, Qwen3 and Llama targets, B = 1, greedy (upstream DSpark also requires temperature=0).
Out of scope: Mistral 3/4 and Kimi K3 targets from the same upstream commit (separate issues per family), batched DSpark, the confidence head beyond loading-and-ignoring as #1339 does.
Acceptance criteria
-
src/lib/mlxcel-core/src/drafter/dflash/config_tests.rs:speculators_layout_parses(the RedHat config gives taps[1, 9, 17, 25, 33], verify width 8, mask 151669, sliding window 2048),openbmb_layout_parses(taps[1, 10, 20, 30, 39],num_target_layers 42),draft_vocab_out_of_range_is_rejected,missing_num_target_layers_is_not_derived_from_taps. -
src/lib/mlxcel-core/src/drafter/dflash/markov_tests.rsreduced_vocab_markov_and_d2t_map_to_target_ids: draft vocab 4 inside target vocab 10 withd2t = [0, 2, 4, 6]maps sampled draft id 3 to target id 9, and the head accepts a[4, rank]markov_w2. -
src/server/batch/dflash_target.rstests: Qwen3 and Llama targets admit a DSpark drafter and refuse a tap index at or above their depth with an error naming the index. - Real checkpoints, integrated:
mlxcel generate -m models/Qwen3-4B --draft-model models/Qwen3-4B-speculator.dspark -p "Explain speculative decoding." -n 128 --temp 0andmlxcel generate -m models/MiniCPM5-2B --draft-model models/MiniCPM5-2B-DSpark -p "Write a Python function that adds two integers." -n 128 --temp 0each report a non-zero acceptance rate and output byte-identical to the run without--draft-model. The same pairings work onmlxcel-server --model-draft. - LFM2 DSpark (
LiquidAI/LFM2.5-2.6BwithLiquidAI/LFM2.5-2.6B-DSpark) still passes its existing tests and real-checkpoint pairing.
Validation
Checkpoints (Hub API, 2026-11-23): Qwen/Qwen3-4B (8.1 GB), RedHatAI/Qwen3-4B-speculator.dspark (3.4 GB), openbmb/MiniCPM5-2B (5.0 GB), openbmb/MiniCPM5-2B-DSpark (0.65 GB). All fit a 128 GB machine.
make verify-test
cargo test --profile test-fast -p mlxcel-core drafter::dflash
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --check
python3 scripts/ci/check_cross_repo_refs.pyRelated
#1339 (LFM2 DSpark drafter), #2386 and the V4.1 DSpark issue (Neywa-Labs/mlx-vlm#2678, a separate drafter that needs the V4.1 port; this issue does not depend on it).
Activity
feat(speculative): load DSpark drafters for Qwen3 and Llama targets (l…
test(speculative): run the DSpark exactness gates under deterministic…