Skip to content

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

Merged
inureyes merged 7 commits into
lablup:mainfrom
Jaeyeong-CHOI:feat/3261-dspark-qwen3-llama
Nov 28, 2026
Merged

inureyes merged 7 commits into
lablup:mainfrom
Jaeyeong-CHOI:feat/3261-dspark-qwen3-llama

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

Summary

Closes #3261.

The official DSpark drafters for dense targets did not load. On unmodified main (944dbfc2d), GB10:

  • mlxcel generate -m models/Qwen3-4B --draft-model models/Qwen3-4B-speculator.dspark -p "Explain speculative decoding." -n 128 --temp 0 exits 1 with the draft model's config ... declares no vocab_size at top level or under text_config, so the pair cannot be checked. The Speculators config has no dflash_config block, so the directory is routed as an ordinary full-model drafter.
  • 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 exits 1 with Loading full-model drafter ... Weight not found: model.embed_tokens.weight, for the same reason.

This PR parses both config layouts, gives the DSpark drafter causal sliding-window attention, a draft head the checkpoint may ship itself and a reduced draft vocabulary with d2t, makes dense Qwen3 and Llama DFlash-family targets, and wires both into the server burst and the offline mlxcel generate driver.

Read this first. On GB10 the block-versus-chain exactness probe declines for both bf16 targets. With default settings the pairings therefore fall back to classic decode on the server (output identical to a server without a drafter, token for token) and are an error naming the override in mlxcel generate. That is the fail-closed result #1751 recorded for LFM2 DSpark on an M5 Max and #3384 for Inkling 2. Under MLXCEL_MTP_ALLOW_INEXACT=1 both pairings engage and decode about 1.8x faster, and in both the text leaves classic decode's within 128 tokens, at a position where the top two candidates are one bf16 step apart or tied. So the issue's acceptance line "non-zero acceptance rate and output byte-identical to the run without --draft-model" is not met on this host with the drafter engaged. The cause is measured below (a one-row and an eight-row matmul, and a one-query and an eight-query attention, take different CUDA kernels), and two real-checkpoint tests show the drafter and target logic itself emits classic decode's tokens when the verify rows are computed one at a time. Metal was not available to me.

What changed

Numbered as in the issue's "Required changes".

  1. Config (src/lib/mlxcel-core/src/drafter/dflash/config.rs). DFlashConfig::from_json reads both layouts:
    • Speculators: the backbone under transformer_layer_config is merged under the root (a root key of the same name wins, as upstream's {**transformer_layer_config, **params}), aux_hidden_state_layer_ids becomes target_layer_ids, is_causal is left unset, and sample_from_anchor: false marks the block as already counting the anchor.
    • OpenBMB: the flat root config is read as is.
    • New fields: draft_vocab_size: Option<usize> (refused outside 1..=vocab_size at load), layer_types, sliding_window, sliding_window_non_causal, is_causal: Option<bool>, sample_from_anchor, dspark_bonus_anchor. num_target_layers becomes Option<usize>; on the two new layouts an absent value stays None, on every existing layout it keeps the default of Some(32).
    • is_dflash_drafter_config recognizes speculators_model_type == "dspark" and architectures: ["Qwen3DSparkModel"].
    • verify_width() is block_size + 1 for a DSpark drafter unless the checkpoint says its block includes the anchor. Both published configs give 8.
  2. Drafter (attention.rs, layer.rs, model.rs, markov.rs, drafter.rs).
    • A sliding_attention layer keeps the newest sliding_window - 1 context rows in its cache (KVCache::trim_front after the write, so offset keeps counting absolute positions for RoPE) and, when causal, masks the block with create_causal_mask_with_window_full(L, prior, window). Causality follows upstream DFlashAttention: an explicit is_causal wins, and when it is unset a layer is causal exactly when it is sliding and sliding_window_non_causal is false.
    • VanillaMarkovHead::from_weights_with_draft_vocab: markov_w1 is [vocab, rank] (indexed by target ids), markov_w2 is [draft_vocab, rank]. DraftToTarget holds the validated d2t offsets; each chosen draft id t leaves the chain as t + d2t[t], which is also the next step's prev. t2d is never read.
    • A shipped lm_head.weight is kept, at any vocabulary, and measured against the draft vocabulary. A reduced draft vocabulary without its own head or without d2t is a load error.
    • draft_block_dspark_array handles both anchor layouts (sample_from_anchor).
    • The pairing gate (dspark_config_pairing_error, dspark_target_pairing_error) checks taps against the bound target's depth whether or not the config declares one, and names the tap index and the depth.
  3. Targets.
    • New src/models/dense_speculative.rs: forward_speculative, prefill_planned, rollback, the block-versus-chain probe, dense_target_pairing_error, and SpeculativeTarget plus a small public DenseSpeculativeTarget trait for Qwen3Model and Llama3Model.
    • Qwen3Model::forward_hidden and Llama3Model::hidden_states now delegate to a capturing variant with an empty capture list, so the generation forward and the verify forward are one body. Both models implement embed_tokens_module and lm_head_module.
    • src/server/batch/dflash_target.rs: DFlashTargetModel for both (every prompt row as the first draft context, classic prefill partition, the probe as the gate, B = 1 only), DFlashVerifyOutput for DenseVerifyOutput, and a new trait hook drafter_pairing_error with a no-objection default. src/server/batch/speculative_burst.rs: the three match arms. src/commands/generate_dflash.rs: the offline arm.
  4. Family gating. required_family_pairing_error calls the drafter "a DSpark drafter", not "an LFM2 DSpark drafter". Qwen3 and Llama keep required_drafter_family() = None.

Also: src/models/detection.rs (the "not a standalone model" refusal names the two new markers), src/lib/mlxcel-core/src/utils.rs (the Used by: line of create_causal_mask_with_window_full), docs/supported-models.md, docs/speculative-acceptance.md, README.md, CHANGELOG.md.

Where this differs from the issue text

  • Neither published checkpoint has a reduced draft vocabulary. RedHatAI/Qwen3-4B-speculator.dspark declares draft_vocab_size 151936 with vocab_size 151936, openbmb/MiniCPM5-2B-DSpark declares 130560 with 130560, and neither safetensors file holds a d2t or t2d tensor (headers read at revisions bdffaa5f and a63eb96b). The d2t path is implemented and tested, but only on synthetic tensors and tiny on-disk checkpoints.
  • Sliding and causal draft attention applies to DSpark drafters only. The issue says "sliding-window draft attention when layer_types says so". The z-lab/Qwen3.5-4B-DFlash config on the Hub today also declares sliding_attention layers (five of six, window 4096), so applying the rule to every DFlash drafter would change the existing Qwen 3.5 DFlash pairing, which this PR cannot measure (its checkpoints are not among those the issue names). A plain DFlash checkpoint therefore keeps attending its whole context, as before, and plain_dflash_configs_ignore_the_dspark_only_fields pins that.
  • src/bin/speculative_bench.rs is not changed. It has no DFlash dispatch on main: --kind dflash prints a DEFERRED row for every family, Qwen 3.5 included. There is nothing to add two targets to.
  • The offline dispatch is in src/commands/generate_dflash.rs, which generate.rs routes to; the two targets are added there.
  • The target check is a trait hook, not only the drafter's gate. The issue asks for the tap and vocabulary validation "at bind time". The drafter's validate_target_compat does it for a DSpark drafter. Because Qwen3 and Llama admit every DFlash-family drafter (required_drafter_family() = None), and that method is a no-op for a plain DFlash drafter, the same two bounds are also checked by the target through DFlashTargetModel::drafter_pairing_error, on both run arms and in the offline driver.
  • A shipped d2t is applied even when the draft vocabulary equals the target one, unless it is all zeros. Upstream builds no d2t in that case. Applying a table the checkpoint ships is the reading that cannot propose a wrong id; an all-zero table is dropped so the chain does no gather.
  • Prefill logits are computed for the last prompt row only, as classic decode's forward_last_logits does, instead of for every row. The first token is then sampled from the bytes classic decode would produce, and a long prompt is not projected through the vocabulary (a 4096-token prompt on Qwen3-4B would otherwise build a [1, 4096, 151936] tensor).
  • Fields upstream implements and this port does not are refused by name on the two new layouts: attention_sink_bias: true, a non-null final_logit_softcapping, a non-default rope_parameters scheme, a positive draft_window_size, and the three values upstream itself refuses (hidden_act, markov_head_type, projector_type). Neither published config sets any of them.
  • Upstream's adaptive block-size controller is not ported. Upstream starts a DSpark drafter at 4 rows and caps a sliding drafter at 6 (context inside the window) or 4 (past it). Here both drafters run at the configured width of 8, as the LFM2 drafters do; --draft-block-size overrides it.

Every other caller

Places that assumed draft ids are target ids, or that the changed helpers touch:

Place What it does now
sample_block_per_position, sample_block_per_position_array, sample_block_per_position_batched (plain DFlash sampling, reads the head's argmax as target ids) Unreachable with a reduced draft vocabulary: DFlashDraftModel::from_weights refuses draft_vocab_size < vocab_size on a checkpoint without a Markov head
DFlashDrafter::draft_block_batched (B > 1) Already refuses a DSpark drafter; unchanged
Rejection sampling at temperature > 0 DSpark is greedy_only: ensure_sampler_supported returns GreedyOnly, the server declines the request to classic decode, the offline driver refuses it. sampled_verify is never taken (supports_sampled_verify stays false)
Server speculative path (run_dflash_on_target, run_dflash_batched_on_target) Family gate, then the new target gate, before any forward. Proposals reach the verify input as target ids because the remap is inside the Markov chain
MTP code that shares helpers materialize_argmax_i32_vec has no vocabulary assumption. VanillaMarkovHead is used only by DFlashDraftModel; the Inkling 2 DSpark drafter has its own head (inkling2_dspark/markov.rs) and is untouched
peek_dspark_configured_block_size (resolve_draft_block_size) Goes through from_json, so both layouts resolve to their verify width of 8
is_dflash_drafter_config / is_dflash_drafter_dir callers: models::detection (standalone refusal), auto_detected_full_model_dir, the server's full-model refusal, resolve_offline_draft_route Both layouts are now DFlash-family drafters on all four
checkpoint_vocab_size (top-level vocab_size only) Its callers are the full-model drafter paths, which a DSpark directory no longer reaches
DFlashConfig::num_target_layers readers dspark_config_pairing_error, dspark_target_pairing_error updated. Muse and Laguna have their own config types
DFlashAttention::from_weights, DFlashDecoderLayer::from_weights (new layer_idx argument) Callers: layer.rs, model.rs, one test. Muse, Laguna and Raon use their own attention types
Qwen3Model::forward_hidden, Llama3Model::hidden_states Same signature and same graph; they call the capturing variant with no capture. Callers (generation, the embedding and reranker wrappers, ColQwen, the VLMs on a Llama backbone) are unchanged
LanguageModel::embed_tokens_module / lm_head_module, newly answered by Qwen3Model and Llama3Model Every caller is a drafter's bind or pairing gate, reached only with that drafter loaded for that target. The VLM wrappers around these models do not forward the two hooks and are unchanged
--spec-type draft-dspark (llama.cpp-compatible flag, cli/spec_compat_args.rs) Still rejected, as it was while only the LFM2 drafters existed. Not changed here

The four review lessons

  1. Boundaries. draft_vocab_size 0, 1, vocab_size, vocab_size + 1 and a huge value; a d2t that maps to exactly vocab_size, to a negative id, with i32::MAX and i32::MIN offsets, and with 0, too few and too many entries; block size 0 and 1 and verify width 2; a tap at the last layer, at the depth, one past it, at usize::MAX, and a target depth of 0; sliding window null, 0, 1, 2 and a huge value; a block wider than the window and a block of one row; an empty block; a prompt of one token, one shorter than the drafter's window and one longer than it (and longer than a prefill chunk). An empty prompt is refused before any forward by the existing guards in run_dflash_on_target and run_offline_dflash; nothing new reaches a forward with zero rows.
  2. Large inputs. A sliding layer's cache stays at window - 1 rows over 400 rounds and for a 200,000-row context in one chunk (a_long_run_keeps_the_sliding_cache_bounded). The d2t table is validated in one pass, 250,000 entries (a_vocabulary_sized_d2t_validates_in_one_pass). The prefill builds one row of logits whatever the prompt length (the_planned_prefill_covers_every_prompt_row). The per-request gates read lazy array shapes and evaluate nothing.
  3. Other callers. The table above.
  4. cargo fmt. cargo fmt --all -- --check on the committed tree, in the list below.

Verification

All on GB10 (NVIDIA DGX Spark, CUDA 13, MLX_ENABLE_TF32=0 MLXCEL_SDPA_DETERMINISTIC=1), --profile test-fast --features cuda, base 944dbfc2d. Every model, server and real-checkpoint test process ran under a watchdog (stop below 25 GiB available or above 40 GiB RSS); no trip.

Tested tree 3e240c6577d1b93e6da534cbee257f821a2b22bc, the tree of the commit (the same before and after the gate).

  • cargo fmt --all -- --check
  • cargo clippy --locked --workspace --all-targets --features cuda -- -D warnings
  • python3 scripts/ci/check_used_by.py, bash scripts/ci/check_used_by_test.sh and the other scripts/ci checks
  • cargo test --locked -p mlxcel --profile test-fast --features cuda --lib -- --test-threads=1 <filter>: detection 285 passed / 7 ignored, router_catalog_route_tests 6 passed, dflash_target 7 passed; --test speculative_dispatch 22 passed. The new mlxcel-core tests are listed under "Tests".
  • make verify-test-cuda with a private 0700 TMPDIR: 17,454 passed, 5 failed, 517 ignored over 199 test result lines. The five failures are the Raon tests models::raon1_mini::speculative::tests::{a_steered_verify_block_applies_the_alpha_exactly_as_decode_does, a_verify_block_equals_the_decode_chain_byte_for_byte, rollback_after_a_partial_accept_equals_a_fresh_decode_of_the_accepted_tokens, the_exactness_probe_passes_on_the_tiny_model} and models::raon_mhc::tests::compiled_site_equals_the_eager_site_bit_for_bit; the same five fail with the same messages on unmodified 944dbfc2d on this host.

The drafter's "not a standalone model" diagnostic now names the Speculators and OpenBMB layouts, so tests/fixtures/webui/examples/catalog.dflash-page.json (the WebUI catalog contract for a DFlash drafter directory) is updated to the new text at the catalog's 512-character bound. An earlier gate run on this branch failed router_catalog_route_tests::mounted_dflash_catalog_matches_bounded_whole_fixture because that fixture had not been updated; the run above is after the update. The fixture is the only file that differs from the tree the real-checkpoint runs below were built from, so those runs apply to this commit.

Tests

On unmodified main:

  • The test files as written for this change do not compile there (64 errors, all missing API: DraftToTarget, layer_is_causal, layer_sliding_window, draft_vocab, dspark_bonus_anchor, from_weights_with_draft_vocab, Option depth, ...).

  • The issue's five core acceptance tests, rewritten against main's API so they compile, all fail:

    Test Failure on main
    speculators_layout_parses not recognized as a drafter
    openbmb_layout_parses not recognized as a drafter
    draft_vocab_out_of_range_is_rejected draft_vocab_size 0 was accepted
    missing_num_target_layers_is_not_derived_from_taps a depth was invented for a config that declares none (32)
    reduced_vocab_markov_and_d2t_map_to_target_ids markov_w2.weight has 4 rows but the drafter config declares vocab_size 10
  • The dflash_target acceptance test cannot be written against main: Qwen3Model and Llama3Model do not implement DFlashTargetModel there.

On this commit:

Set Result
mlxcel-core drafter::dflash (config, Markov, attention, model, drafter) 146 passed, 0 failed
mlxcel-core drafter:: (every drafter), row_invariant 332 passed (1 ignored), 5 passed
mlxcel dense_speculative::tests (tiny Qwen3 and Llama targets, a real DFlashDrafter loaded from a tiny on-disk checkpoint in each layout) 10 passed
mlxcel dflash_target (includes the two new server-gate tests) 7 passed
mlxcel detection, lfm2, qwen3, llama3, cli::speculative_args, drafter, generate 285, 98, 308, 66, 23, 86, 60 passed
mlxcel dense_speculative::real_checkpoint_tests with the four checkpoints present 2 passed

New tests, by acceptance line of the issue:

  • config_tests.rs: speculators_layout_parses, openbmb_layout_parses, draft_vocab_out_of_range_is_rejected, missing_num_target_layers_is_not_derived_from_taps, plus dspark_block_size_counts_the_anchor_only_when_the_checkpoint_says_so, dspark_layer_causality_follows_the_layer_type_unless_set, dspark_sliding_fields_are_bounded_at_load, unsupported_dspark_fields_are_refused_by_name, plain_dflash_configs_ignore_the_dspark_only_fields, probe_accepts_the_speculators_and_openbmb_markers. The two fixtures are the published config.json files at revisions bdffaa5f and a63eb96b.
  • markov_tests.rs: reduced_vocab_markov_and_d2t_map_to_target_ids (draft vocabulary 4 in target vocabulary 10, d2t = [0, 2, 4, 6], draft id 3 becomes target id 9, a [4, rank] markov_w2 loads), plus the feedback of the target id into the next step, the out-of-range refusals, integer dtypes, and a 250,000-entry table.
  • dflash_target_dense_tests.rs: qwen3_and_llama_targets_admit_dspark_and_refuse_a_tap_at_or_above_their_depth (the error names the index and the depth), qwen3_and_llama_targets_run_the_dspark_burst_policy.
  • attention_sliding_tests.rs (8 tests, each against a reference built from the plain attention), model_dspark_tests.rs (8), dense_speculative_tests.rs (10), detection_tests.rs (two new cases).

Real checkpoints

Revisions: Qwen/Qwen3-4B 1cfa9a72, RedHatAI/Qwen3-4B-speculator.dspark bdffaa5f, openbmb/MiniCPM5-2B 42433e90, openbmb/MiniCPM5-2B-DSpark a63eb96b, LiquidAI/LFM2.5-2.6B 7141b56c, LiquidAI/LFM2.5-2.6B-DSpark 458cedab.

CLI, mlxcel generate -m <target> [--draft-model <drafter>] -p <prompt> -n 128 --temp 0 --show-reasoning, three runs each (one process per run, so each number includes that process's warm-up):

Model Arm Decode tok/s (3 runs) Acceptance Text
Qwen3-4B no drafter 27.52 / 27.53 / 27.53 - same in all 3
Qwen3-4B + speculator.dspark default - - exit 1: Qwen3 DFlash speculative decoding declined ...; probe verify block position 0 differs from the single-token chain in 140205 of 303872 logit bytes
Qwen3-4B + speculator.dspark MLXCEL_MTP_ALLOW_INEXACT=1, width 8 48.88 / 48.72 / 49.40 88 / 262 = 0.336 (40 rounds) same in all 3, differs from the no-drafter text
MiniCPM5-2B no drafter 48.39 / 47.94 / 48.42 - same in all 3
MiniCPM5-2B + DSpark default - - exit 1; probe 133206 of 261120 logit bytes
MiniCPM5-2B + DSpark MLXCEL_MTP_ALLOW_INEXACT=1, width 8 88.86 / 86.32 / 87.33 103 / 164 = 0.628 (24 rounds) same in all 3, differs from the no-drafter text

Server, mlxcel-server -m <target> [--model-draft <drafter>], one /v1/chat/completions request (temperature 0, 128 tokens, logprobs with 3 alternatives), then the same request again:

Model Arm Tokens against the no-drafter server Numbers (first / second request)
Qwen3-4B no drafter reference round trip 7.89 s / 5.28 s (a classic chat response carries no timings)
Qwen3-4B drafter, default identical, 128 of 128, every logprob equal probe declines, served by classic decode; 5.31 s / 5.25 s
Qwen3-4B drafter, MLXCEL_MTP_ALLOW_INEXACT=1 first 72 tokens equal, then differs draft_n 262, draft_n_accepted 88, draft_rounds 40; decode 44.6 / 53.0 tok/s; 3.00 s / 2.45 s
MiniCPM5-2B no drafter reference 3.32 s / 3.20 s
MiniCPM5-2B drafter, default identical, 128 of 128 3.26 s / 3.16 s
MiniCPM5-2B drafter, MLXCEL_MTP_ALLOW_INEXACT=1 first 32 tokens equal, then differs draft_n 164, draft_n_accepted 103, draft_rounds 24; decode 73.1 / 130.3 tok/s; 1.85 s / 1.02 s

Where the override arm leaves the reference, from the two responses' logprobs:

  • Qwen3-4B, token 72: the reference emits make at -1.25 with not second at -1.375, a gap of 0.125. The drafter run has both at -1.25 and emits not.
  • MiniCPM5-2B, token 32: the reference has likely and wants both at -1.5 and emits likely. The drafter run has wants at -1.375 and emits it.

Up to those positions the largest logprob difference on an emitted token is 0.25 and 0.125.

Exact arm, as a test. dense_speculative::real_checkpoint_tests wraps the target so each row of a verify block is its own single-token forward (classic decode's arithmetic by construction, on any backend) and runs the production drafter, captures, hidden slicing, rollback and round loop around it. On both pairings, three prompts of 96 tokens each (5, 9 or 10, and about 290 prompt tokens), the drafted tokens equal forward_last_logits greedy tokens. Accepted / proposed: Qwen3-4B 57/261, 57/267, 74/150; MiniCPM5-2B 66/203, 74/149, 80/105. The tests soft-skip when the checkpoints are absent, as the other real-checkpoint tests do.

Why the probe declines on GB10. A throwaway test (not in this PR) compared row r of an 8-row product with the same row computed alone, bf16, real shapes:

Op Rows that differ Bytes that differ
matmul 2560 to 9728 8 of 8 84 of 155,648
matmul 2560 to 151,936 8 of 8 1,546 of 2,430,976
KVCache::attend, block of 8 queries against one query at a time, 20 cached keys 8 of 8 14,830 of 65,536
same, 300 cached keys 8 of 8 15,258 of 65,536
compiled SwiGLU MLP 8 of 8 1,371 of 40,960
RMSNorm, RoPE, SwiGLU activation, fused add + RMSNorm 0 of 8 0

A batched verify block of a dense bf16 target therefore cannot equal single-token decode bit for bit on this backend. Computing it row by row is exact and gives up the speedup. The existing MLXCEL_MLA_ROW_INVARIANT=1 switch (Llama-class models, #3421) brings the MiniCPM5-2B probe from 133,206 differing bytes to 494, not to 0, on GB10; I did not chase the remainder.

LFM2.5 unchanged. LiquidAI/LFM2.5-2.6B with LiquidAI/LFM2.5-2.6B-DSpark on the server, main against this commit, same request: no drafter, drafter with default settings (the probe declines on GB10 here too) and drafter with the override give the same text on both builds in each arm, and the override arm reports draft_n 272, draft_n_accepted 88, draft_rounds 39 on both.

Verification limits

  • Byte-identical output with the drafter engaged was not obtained on GB10. Default settings decline; the override engages and the text departs at a near-tie. This is the main open point of the PR.
  • Metal was not run. I expect the default probe to decline there as well for these two bf16 targets (Qwen3 has no row-invariant forward, and Llama's is opt-in), but I did not measure it.
  • The reduced draft vocabulary is not exercised by any real checkpoint. Both published drafters score the full target vocabulary and ship no d2t.
  • A plain DFlash drafter on a Qwen3 or Llama target was not run. These targets name no required family (as the issue asks), so for example z-lab/Qwen3-4B-DFlash-b16 now passes the family gate on a Qwen3 target and is held to the tap and vocabulary bounds only. It would get every prompt row as its first draft context, the DSpark policy.
  • Server with a non-default KV cache mode or paged decode storage was not run. The burst runs on its own FP16 dense caches, as every DFlash burst does.
  • Server no-drafter decode tok/s is not reported: a classic chat response carries no timings, so that arm is compared by request round trip only.
  • Host with tile-padded classic prefill (M5) not run. The speculative prefill does not pad, as on the other DFlash targets.
  • src/bin/speculative_bench.rs is unchanged (no DFlash dispatch exists there).
  • The CLI numbers are single-process runs and include warm-up; I did not separate it.

…wen3 and Llama targets

The official DSpark drafters for dense targets did not load: RedHatAI/Qwen3-4B-speculator.dspark (for Qwen/Qwen3-4B) and openbmb/MiniCPM5-2B-DSpark (for openbmb/MiniCPM5-2B, a llama checkpoint) carry no dflash_config block, so both directories were routed as ordinary full-model drafters and failed on a missing vocab_size or a missing model.embed_tokens.weight. DSpark was LFM2-only, and neither Qwen3 nor Llama was a DFlash-family target.

Config (drafter/dflash/config.rs): DFlashConfig::from_json reads the Speculators layout (backbone under transformer_layer_config, taps in aux_hidden_state_layer_ids, is_causal unset) and the flat OpenBMB layout, and is_dflash_drafter_config recognizes speculators_model_type "dspark" and the Qwen3DSparkModel architecture. New fields: draft_vocab_size (refused outside 1..=vocab_size), layer_types, sliding_window, sliding_window_non_causal, is_causal, sample_from_anchor and dspark_bonus_anchor. num_target_layers is now optional: a config that declares none is not given a depth derived from its taps, and the taps are checked against the bound target instead. Fields upstream implements and this port does not (attention sinks, logit softcapping, a rope scaling scheme, a draft window) are refused by name on the two new layouts.

Drafter (attention.rs, layer.rs, model.rs, markov.rs, drafter.rs): a sliding_attention layer keeps the newest sliding_window - 1 context rows and, when causal, masks the proposal block with the windowed causal mask, following upstream DFlashAttention. A checkpoint that ships lm_head.weight keeps its own head. With a reduced draft vocabulary the head and markov_w2 score draft ids, markov_w1 stays indexed by target ids, and each chosen draft id t leaves the Markov chain as the target id t + d2t[t]; d2t is validated against both vocabularies at load (length, every mapped id inside the target vocabulary) and t2d is ignored. A plain DFlash checkpoint is left as it was: it ignores layer_types and cannot declare a reduced draft vocabulary.

Targets (models/dense_speculative.rs, qwen3.rs, llama3.rs): Qwen3Model and Llama3Model implement SpeculativeTarget. The capture lives inside their generation forward, so a verify block builds the graph a decode step builds; the prefill forwards the pieces classic decode forwards and computes logits for the last prompt row only; a partial accept is a KV trim; the block-versus-chain exactness probe gates the burst. Both hand out their embedding table and output head for a drafter that ships none.

Wiring: DFlashTargetModel for both in server/batch/dflash_target.rs with a new drafter_pairing_error hook (tap depth and vocabulary, naming both numbers), the three dispatch arms in speculative_burst.rs, and an offline arm in commands/generate_dflash.rs. Qwen3 and Llama name no required drafter family, as Qwen 3.5 does not, and the decline text no longer calls every DSpark drafter an LFM2 one.

Validated on GB10 (CUDA). The exactness probe declines for both bf16 targets there, so by default the pairings fall back to classic decode, as LFM2 DSpark does where its probe declines. Under MLXCEL_MTP_ALLOW_INEXACT=1 both engage; the text then leaves classic decode's at a near-tie. With each verify row run as its own single-token forward, drafted tokens equal classic tokens on both real pairings. Neither published checkpoint uses a reduced draft vocabulary, so that path is covered by unit tests and tiny on-disk checkpoints only.

Closes lablup#3261
@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:inference Generation, sampling, decoding (incl. speculative, DRY) modelsize:small 4-bit checkpoint <= 10GB; fast iteration, safe for smoke tests modeltype:text Text-only language model arch:dense Dense transformer decoder labels Nov 28, 2026
# Conflicts:
#	CHANGELOG.md
#	docs/supported-models.md
The two real-checkpoint gates looked only in the mlxcel store, the HuggingFace cache and models/<repo basename> (Qwen3-4B, MiniCPM5-2B, ...), which never matches the lowercase names the shared models/ link farm uses, so on the CI and dev hosts they always soft-skipped. They now also try the link-farm names (qwen3-4b-bf16, qwen3-4b-speculator-dspark, minicpm5-2b, minicpm5-2b-dspark), and MLXCEL_REQUIRE_MODELS=1 turns a missing checkpoint into a failure instead of a silent pass, as the other real-model tests do.
The branch predates the v0.9.0-beta.3 release, so after merging main its CHANGELOG entry landed inside the released section. It belongs under [Unreleased] / Added, next to the other entries that have not shipped.
@inureyes

Copy link
Copy Markdown
Member

Hardening review

Reviewed against #3261. No code defect found. Detection does not misclassify existing checkpoints: the new markers are only speculators_model_type == "dspark" and Qwen3DSparkModel, and a scan of 290 local config.json files found neither (nor transformer_layer_config / aux_hidden_state_layer_ids); the sliding and causal rules are gated on is_dspark(), so on-disk Qwen 3.5 DFlash configs parse as before. The server path is wired: speculative_burst.rs has Qwen3 and Llama arms for exactness, supports_batched and drive, and dflash_target.rs gates both the B=1 and batched arms through drafter_pairing_error.

Pushed (9a103f35)

  • LOW, test (fc8f2f7b): dense_speculative_real_checkpoint_tests looked only under models/<repo basename>, which never matches the local model names, so both gates always passed without running. They now also resolve qwen3-4b-bf16, qwen3-4b-speculator-dspark, minicpm5-2b and minicpm5-2b-dspark, and MLXCEL_REQUIRE_MODELS=1 turns a missing checkpoint into a failure.
  • LOW, docs (67dd216b): the CHANGELOG entry had landed inside the tagged v0.9.0-beta.3 section after the merge; it is now under [Unreleased] / Added.
  • Merges of main; conflicts in docs/supported-models.md (this PR's dense Qwen3/Llama DSpark row plus main's Inkling 2 row) and CHANGELOG.md keep both sides.

Validation (GB10, --profile test-fast --features cuda --test-threads=1, MLXCEL_SDPA_DETERMINISTIC=1)

  • fmt, check_used_by.py, clippy -p mlxcel -p mlxcel-core --all-targets --features cuda -D warnings: pass.
  • mlxcel-core drafter:: 332 passed; mlxcel dense_speculative 10, dflash_target 7, detection 285, qwen3:: 13, llama3 66, lfm2 99, drafter 86, generate 60, speculative_burst 73, --test speculative_dispatch 22: all pass.
  • Real checkpoints (downloaded and sha256-verified: Qwen3-4B bf16, Qwen3-4B speculator.dspark, MiniCPM5-2B, MiniCPM5-2B-DSpark): real_checkpoint_tests with MLXCEL_REQUIRE_MODELS=1 pass 2/2, drafted tokens equal classic greedy on 3 prompts per pairing with the acceptance counts in the PR body.
  • Server, default settings: the probe declines and the reply (128 tokens and every logprob) is identical to a server without a drafter. With MLXCEL_MTP_ALLOW_INEXACT=1 the drafter engages and the text leaves classic decode at a near-tie (token 72 on Qwen3, 31 on MiniCPM). The CLI exits with the named probe error by default.
  • Mismatched pairings are each refused by name (hidden size, vocab 248320 vs 151936, depth). Qwen 3.5 regression: qwen3.5-4b-4bit + qwen3.5-4b-dflash on the server engages (123 drafted / 86 accepted) and stays byte-identical to plain decode.

As the PR states, the acceptance line "output byte-identical to the run without --draft-model" with the drafter engaged is not met on GB10: the verify block and the single-token chain take different CUDA kernels, so the pairing fails closed there, as LFM2 DSpark (#1751) and Inkling 2 (#3384) do. Metal was not tested.

@inureyes
inureyes merged commit f8098c9 into lablup:main Nov 28, 2026
33 checks passed
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 28, 2026
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch:dense Dense transformer decoder area:inference Generation, sampling, decoding (incl. speculative, DRY) modelsize:small 4-bit checkpoint <= 10GB; fast iteration, safe for smoke tests modeltype:text Text-only language model priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants