Skip to content

vllm.v1.worker.gpu.spec_decode.dspark.speculator

DSpark speculator: semi-autoregressive parallel drafting.

DSpark drafts a block of num_speculative_tokens tokens in one parallel pass (reusing the DFlash machinery: context-KV precompute + a query-block forward), then injects intra-block dependency with a lightweight sequential Markov head.

Differences from DFlash
  • Anchor-as-first-prediction: each request emits exactly N = num_speculative_tokens query tokens (anchor + N-1 noise), NOT 1 + N. Every query position is a prediction (the anchor predicts the first draft token), so we sample at all N positions and sample_pos = query_pos + 1 (standard next-token), whereas DFlash's masks sit AT the predicted position. This is the sample_from_anchor path in the shared prepare-inputs kernel. Speculators-format checkpoints instead use the DFlash 1 + N fill-in layout (anchor is the bonus token).
  • Sequential Markov sampling: instead of DFlash's single parallel sample, we sample left-to-right, adding a prefix-dependent Markov bias derived from the previously sampled token at each step.

CUDA graphs (FULL, mirroring DFlash) cover the whole draft step: the parallel backbone forward AND the sequential Markov sampling.

Under batch-sharded sampling, draft steps also shard the sequential sampling across TP ranks: each rank runs the Markov loop only for the requests it owns (the same owners as verification), see _sample_sequential_sharded.

Classes:

DSparkSpeculator

Bases: DFlashSpeculator

_confidence(hidden, markov_embeds, shape)

Draft confidences from [num_rows, num_steps, rank] Markov embeddings, or None without a confidence head.

_markov_step(prev, draft_hidden, state)

Markov embedding of the previous token at one draft position.

Recurrent heads also read the backbone hidden state and carry a state across the positions of one proposal, starting from None (zeros).

_sample_logits(logits, idx_map, sample_pos, step, bias=None)

Sample draft ids from the logits. If bias is provided, the Gumbel kernel adds it.

_sample_markov_chain(base_logits, hidden, prev, idx_map, sample_pos, out_tokens, *, prev_indices=None)

Run the sequential Markov steps for a block of requests, writing the drafts to out_tokens.

Returns:

  • Tensor | None –

    [num_rows, num_speculative_steps] draft confidences, or None

  • Tensor | None –

    without a confidence head.

_sample_sequential_sharded(num_reqs, head_hidden)

_sample_sequential with each TP rank sampling only its own requests.

Request i is owned by rank shard_owner(i), as in DraftLogitsCache, so no rank owns more than cdiv(num_reqs, tp_size) requests. Each rank computes vocab-shard base logits for every request, in owner-sorted order. An all-to-all then gives each rank the full-vocab rows of the requests it owns, the Markov loop runs on just those rows, and an all-gather returns the drafts in batch order. All shapes depend only on num_reqs, so the step can be captured.

_sample_sequential_topk(num_reqs, head_hidden)

Apply the sequential Markov head only to top-k base-logit candidates.

Candidate selection is done once for all draft positions. At each sequential step, the selected logits are corrected in place and every other entry is set to -inf. The normal dense sampling and rejection paths then consume that truncated distribution unchanged.