Skip to content

vllm.model_executor.models.qwen3_dspark

Qwen3 DSpark draft model for semi-autoregressive drafting.

DSpark drafts a whole block in one parallel pass (DFlash-style: context-KV precompute + a non-causal query-block forward) and then injects intra-block dependency with a lightweight sequential Markov head.

The parallel backbone is a standard Qwen3 decoder stack reused from the DFlash Qwen3 draft (see qwen3_dflash.py). DSpark adds: * markov_head: low-rank V x r / r x V transition bias added to the base logits, sampled left-to-right by the speculator (the sequential stage). * confidence_head: per-position acceptance-probability estimate.

DSparkMarkovHead and DSparkConfidenceHead are shared with the DSV4-style DSpark model.

Classes:

DSparkConfidenceHead

Bases: Module

DSpark acceptance-confidence head.

DSparkMarkovHead

Bases: Module

Sequential transition-bias head (low-rank V x r, r x V).

markov_w1[token] embeds the previously sampled token (target vocab, vocab_size); markov_w2 projects it to a draft-vocab bias (draft_vocab_size) added to the base draft logits. The two sizes coincide for full-vocab drafts.

Both weights are replicated because the head runs sequentially for every draft position. Sharding them would add an all-reduce and a full-vocab gather to each position.

Methods:

  • apply_bias_gathered –

    Apply the Markov bias only to selected rows of logits.

  • bias –

    Vocab-size transition bias from a Markov embedding ([B, r] -> [B, V]).

  • embed –

    r-dim Markov embedding of token_ids ([B] -> [B, r]).

apply_bias_gathered(markov_embed, logits, values, index, scale=1.0)

Apply the Markov bias only to selected rows of logits.

The caller initializes logits to -inf once for all draft positions. This method scatters the corrected candidate values into that dense buffer so the normal sampler sees the truncated proposal.

bias(markov_embed, logits_processor)

Vocab-size transition bias from a Markov embedding ([B, r] -> [B, V]).

embed(token_ids)

r-dim Markov embedding of token_ids ([B] -> [B, r]).

Qwen3DSparkForCausalLM

Bases: DFlashQwen3ForCausalLM

Methods:

compute_confidence(head_hidden, markov_embed)

Per-position acceptance probability for each drafted token.

compute_draft_logits_local(hidden_states)

This TP rank's vocab shard of compute_draft_logits, not gathered.

Qwen3DSparkModel

Bases: DFlashQwen3Model

DFlash Qwen3 backbone + DSpark Markov / confidence heads.