vllm.v1.worker.gpu.spec_decode.adaptive_verification
¶
Adaptive verification for DSpark speculative decoding.
Classes:
-
AdaptiveVerificationManager– -
AdmittedDraftCounts–Per-request admitted draft counts, in flight to the host.
Functions:
-
assign_draft_token_budget–Admit the globally best
draft_budgetdraft slots, in place. -
build_cost_tables_from_curves–Build cost tables: graph-padded below the capture limit, smooth above.
-
resolve_adaptive_cudagraph_mode–Select a separate decode route for variable-length verification.
AdaptiveVerificationManager
¶
Methods:
-
batches_to_profile–Dummy-run kwargs whose step timings seed the cost tables.
-
compact_batch–Compact the CPU batch to the chosen draft budget.
-
get_num_tokens–Token count once the draft budget is trimmed to fit.
-
reallocate_drafts–The admitted draft counts are None unless copy_admitted_drafts_to_host
-
record_confidences–Publish this step's raw confidences for the ranking kernel and start
-
warmup_budget_kernel–JIT the draft-budget kernel so the first binding step doesn't compile.
batches_to_profile(capture_sizes)
¶
Dummy-run kwargs whose step timings seed the cost tables.
Run these inside StepTimingCollector.collect(), then hand the block's timings to set_initial_cost_curves.
compact_batch(num_draft_tokens_per_req, num_scheduled_tokens, cu_num_logits_np)
¶
Compact the CPU batch to the chosen draft budget.
Returns the compacted per-request token counts and the CPU cu_num_logits_np. If the draft budget is 0, we can know cu_num_logits_np exactly, otherwise its unchanged/an-upper-bound.
get_num_tokens(num_tokens_per_req, draft_tokens)
¶
Token count once the draft budget is trimmed to fit.
Stashes the chosen budget in _batch_budget for the compaction and
reallocation that follow in the same step.
reallocate_drafts(req_ids, idx_mapping)
¶
The admitted draft counts are None unless copy_admitted_drafts_to_host is set and the budget binds; otherwise the host counts are already exact.
record_confidences(confidence_probs, input_batch)
¶
Publish this step's raw confidences for the ranking kernel and start copying them to the CPU, where a later step's budget reads them.
warmup_budget_kernel()
¶
JIT the draft-budget kernel so the first binding step doesn't compile.
AdmittedDraftCounts
¶
Per-request admitted draft counts, in flight to the host.
assign_draft_token_budget(confidence_probs, idx_mapping, capacities, draft_budget, survival)
¶
Admit the globally best draft_budget draft slots, in place.
Every (request, step) slot is scored by its survival probability, the running product of that request's per-position confidences, and the highest scores win. Survival only decreases along a request, so the winners are always a prefix of each request's steps and only per-request counts are needed.
capacities enters holding each request's scheduled draft count (which bounds its
eligible slots) and leaves holding the admitted count. The caller only calls this
when draft_budget < capacities.sum(), so every winner is a real draft slot.
survival is int32 scratch with room for num_reqs * num_steps slots.
build_cost_tables_from_curves(draft_curve, verify_curve, max_num_reqs, max_batch_tokens, cudagraph_limit=0)
¶
Build cost tables: graph-padded below the capture limit, smooth above.
Parameters:
-
(draft_curve¶list[tuple[int, float]]) –(size, cost) samples for the draft model.
-
(verify_curve¶list[tuple[int, float]]) –(size, cost) samples for the verify model.
-
(max_num_reqs¶int) –Largest request count to build a table for.
-
(max_batch_tokens¶int) –Largest token count to build a table for.
-
(cudagraph_limit¶int, default:0) –Largest cudagraph-captured size. At or below it, execution pads up to the next captured size, so cost is a step function. Above it there is no padding, so cost is continuous.
resolve_adaptive_cudagraph_mode(mode, *, piecewise_capture_available)
¶
Select a separate decode route for variable-length verification.