Skip to content

feat(speculative): load official Speculators and OpenBMB DSpark drafters for Qwen3 and Llama targets #3261

Done

Description

@inureyes

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):

Behavior (from upstream code and the two configs)

  • Speculators layout (RedHatAI/...speculator.dspark, speculators_model_type: dspark, architectures: [DSparkDraftModel]): the draft backbone lives in transformer_layer_config (model_type qwen3, 5 layers, hidden 2560, layer_types all sliding_attention, sliding_window 2048); root fields are aux_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_dict merges transformer_layer_config under the root, maps aux_hidden_state_layer_ids to target_layer_ids, sets is_causal to None, and synthesizes dflash_config = {projector_type: dspark}.
  • OpenBMB layout (openbmb/MiniCPM5-2B-DSpark, architectures: [Qwen3DSparkModel]): flat root config with target_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_size counts proposals unless the anchor is included (dspark_bonus_anchor, or a Speculators checkpoint with sample_from_anchor: false); the verify width is block_size + 1 otherwise.
  • num_target_layers is optional; when absent, each tap is validated against the bound target's depth, not derived as max(taps) + 1.
  • Reduced draft vocabulary: when draft_vocab_size < vocab_size, the drafter owns lm_head [draft_vocab, hidden], markov_w2 projects to draft_vocab, and a sampled draft id t maps to the target id t + d2t[t] (d2t int32, from the checkpoint; t2d is ignored). draft_vocab_size must satisfy 0 < draft_vocab_size <= vocab_size. A checkpoint that ships lm_head.weight keeps 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 nested dflash_config; is_dflash_drafter_config (:379-420) keys on that block or the DFlash architectures, so neither official layout is recognized. The struct has no draft_vocab_size, layer_types, sliding_window, sample_from_anchor or aux_hidden_state_layer_ids, and num_target_layers defaults (:125, :201).
  • VanillaMarkovHead (src/lib/mlxcel-core/src/drafter/dflash/markov.rs:43-145) checks both factors against one vocab, so a reduced markov_w2 is rejected.
  • DFlash-family targets are Qwen 3.5, LFM2, Muse Glimmer and Laguna (impl DFlashTargetModel in src/server/batch/dflash_target.rs:254-380). LoadedModel::Qwen3 and LoadedModel::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

  1. Config (dflash/config.rs): accept both layouts in from_json as above; add draft_vocab_size: Option<usize> (defaults to vocab_size), layer_types, sliding_window, sample_from_anchor and an optional num_target_layers; teach is_dflash_drafter_config to recognize speculators_model_type == "dspark" and Qwen3DSparkModel. Reject a draft_vocab_size outside 1..=vocab_size at load.
  2. Drafter (dflash/model.rs, dflash/drafter.rs, dflash/markov.rs): sliding-window draft attention when layer_types says so (window from sliding_window). Causality follows upstream DFlashAttention (https://github.com/Neywa-Labs/mlx-vlm/blob/main/mlx_vlm/speculative/drafters/qwen3_dflash/dflash.py): an explicit is_causal wins; when it is null, as Speculators sets it, a layer is causal exactly when it is sliding and sliding_window_non_causal is false; the reduced-vocabulary head plus d2t remap applied to every sampled draft id before it leaves the drafter; ignore t2d; keep a shipped lm_head instead of binding the target's.
  3. Targets: implement DFlashTargetModel for Qwen3Model and Llama3Model (hidden capture at target_layer_ids, multi-row verify, KV trim on finalize, the block-versus-chain exactness_allows probe), and add both to the DFlash dispatch in src/server/batch/speculative_burst.rs, src/commands/generate.rs and src/bin/speculative_bench.rs. Validate at bind time that every tap is below the target depth and that vocab_size matches; mismatches are errors naming both numbers.
  4. Family gating: rename the decline text so DSpark no longer says "LFM2" only. Qwen3 and Llama keep required_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.rs reduced_vocab_markov_and_d2t_map_to_target_ids: draft vocab 4 inside target vocab 10 with d2t = [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.rs tests: 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 0 and mlxcel generate -m models/MiniCPM5-2B --draft-model models/MiniCPM5-2B-DSpark -p "Write a Python function that adds two integers." -n 128 --temp 0 each report a non-zero acceptance rate and output byte-identical to the run without --draft-model. The same pairings work on mlxcel-server --model-draft.
  • LFM2 DSpark (LiquidAI/LFM2.5-2.6B with LiquidAI/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.py

Related

#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

  1. added
    status:ready
    type:enhancement
    priority:medium
    area:inference
    modelsize:small
    modeltype:text
    arch:dense
    on Nov 22, 2026
  2. added
    status:done
    and removed
    status:ready
    on Nov 28, 2026
  3. added 2 commits that reference this issue on Nov 28, 2026
    f8098c9
    9ffa486
  4. added this to the 0.9 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch:densearea:inferencemodelsize:smallmodeltype:textpriority:mediumstatus:donetype:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions