Skip to content

vllm.v1.worker.gpu.spec_decode.suffix.speculator

GPU suffix decoding speculator for the V2 model runner.

Extends the n-gram speculator with the two parts of SuffixDecoding (https://arxiv.org/abs/2411.04975) that carry most of its acceptance gain:

  • Variable-length matching: drafts continue the occurrence whose preceding tokens match the longest suffix of the request's history (up to suffix_decoding_max_tree_depth), instead of a fixed n-gram window.
  • Cross-request memory: responses of finished requests are appended to a device-resident token corpus. A hash index keyed on the last 2 and last 4 tokens gives candidate positions, and each candidate is extended to the longest suffix match, so the index is only an entry point for suffix matching.

The propose path never synchronizes with the host. Ingestion reads token history and lengths directly from RequestState and processes finished requests in sorted id order; index updates are order-independent, so every TP rank holds an identical corpus without any collective.

Classes:

SuffixSpeculator

Bases: BaseSpeculator

V2-compatible GPU suffix decoding speculator.

Methods:

  • on_requests_finished –

    Add finished responses to the corpus before their slots are freed.

  • reset_state –

    Forget everything learned so far (used after the warmup requests).

on_requests_finished(finished_req_ids)

Add finished responses to the corpus before their slots are freed.

reset_state()

Forget everything learned so far (used after the warmup requests).

_corpus_draft(row, seq_len, table_ptr, corpus_ptr, corpus_len, HASH_MUL, NUM_BUCKETS, SLOTS, MAX_DEPTH, DEPTH_PO2, K, K_PO2)

(match_len, draft, num_tokens) from the corpus for one request.

Candidates are the slots of the request's 4-token and 2-token buckets. Each is verified and extended against the corpus, so hash collisions and entries for overwritten documents only cost a slot. The draft is then chosen by frequency, as in SuffixDecoding: for each candidate match length L, the candidates matching at least L tokens vote token by token (prefix-consistent; ties go to the newest candidate), and the chain with the highest sum of per-token probabilities wins (ties: longer L).

_suffix_ingest_kernel(token_ids_ptr, token_ids_stride, docs_ptr, num_docs, total_len_ptr, corpus_ptr, corpus_len, head_ptr, doc_seq_ptr, head_out_ptr, doc_seq_out_ptr, table_ptr, HASH_MUL, NUM_BUCKETS, SLOTS, BLOCK)

Append finished responses to the corpus ring and index them, with one program per (document, block).

Documents are placed one after another. A document that does not fit before the end of the ring wraps to offset 0, so no document straddles the boundary. Older documents are overwritten in FIFO order (including earlier documents of the same batch, if the batch exceeds the ring); their index entries become stale and are rejected by verification at lookup. Each program replays the batch's placement to find its offset and skips positions a later document of the batch overwrites, so every position is written by exactly one program and the result does not depend on execution order.

_suffix_local_scan_kernel(token_ids_ptr, token_ids_stride, idx_mapping_ptr, total_len_ptr, num_sampled_ptr, scratch_ptr, scratch_stride, Lp1, MAX_DEPTH, BLOCK)

Per (request, block): best (match_len, end_pos) packed into one int64.

end_pos is the exclusive end of an earlier occurrence of the request's suffix in its own history; the draft continues from end_pos. Longer matches win, then later positions.

_suffix_observe_kernel(idx_mapping_ptr, num_sampled_ptr, num_rejected_ptr, stats_ptr, last_bucket_ptr, last_valid_ptr, K, K_PO2)

Fold the target's verdict on each request's last draft into the stats.

Integer atomics are order-independent, so every TP rank keeps identical stats (and therefore identical confidences).