[Spec Decode] DSpark confidence-scheduled verification (#47808)

Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>
Signed-off-by: Lucas Wilkinson <LucasWilkinson@users.noreply.github.com>
Signed-off-by: Benjamin Chislett <chislett.ben@gmail.com>
Signed-off-by: Lucas Wilkinson <wilkinson.lucas@gmail.com>
Signed-off-by: Nick Hill <nickhill123@gmail.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Benjamin Chislett <chislett.ben@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Nick Hill <nickhill123@gmail.com>
Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
Lucas Wilkinson
2026-08-12 12:27:48 -07:00
committed by GitHub
co-authored by OpenAI Codex Claude Opus 5 Benjamin Chislett mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Nick Hill OpenAI Codex
parent fe889ac925
commit 7f7a32cfec
40 changed files with 1643 additions and 111 deletions
+27 -4
View File
@@ -10,7 +10,13 @@ from vllm.v1.worker.gpu.input_batch import InputBatch
class StructuredOutputsWorker:
def __init__(self, max_num_logits: int, vocab_size: int, device: torch.device):
def __init__(
self,
max_num_logits: int,
vocab_size: int,
device: torch.device,
mask_stride: int,
):
self.logits_indices = torch.zeros(
max_num_logits, dtype=torch.int32, device=device
)
@@ -19,6 +25,7 @@ class StructuredOutputsWorker:
)
self.device = device
self.copy_stream = torch.cuda.Stream()
self.mask_stride = mask_stride
def apply_grammar_bitmask(
self,
@@ -45,7 +52,13 @@ class StructuredOutputsWorker:
req_idx = req_id_to_idx[grammar_req_id]
logits_start_idx = cu_num_logits[req_idx]
logits_end_idx = cu_num_logits[req_idx + 1]
mapping.extend(range(logits_start_idx, logits_end_idx))
# Key by (request, position) rather than absolute logit index:
# adaptive verification finalizes per-request logit offsets on
# device, so the kernel resolves them from the GPU cu_num_logits.
mapping.extend(
req_idx * self.mask_stride + position
for position in range(logits_end_idx - logits_start_idx)
)
# Asynchronously copy the mapping to GPU.
with torch.cuda.stream(self.copy_stream):
@@ -69,9 +82,11 @@ class StructuredOutputsWorker:
logits,
logits.stride(0),
logits_indices,
input_batch.cu_num_logits,
bitmask,
bitmask.stride(0),
vocab_size,
MASK_STRIDE=self.mask_stride,
BLOCK_SIZE=BLOCK_SIZE,
)
@@ -87,13 +102,21 @@ def _apply_grammar_bitmask_kernel(
logits_ptr,
logits_stride,
logits_indices_ptr,
cu_num_logits_ptr,
bitmask_ptr,
bitmask_stride,
vocab_size,
MASK_STRIDE: tl.constexpr,
BLOCK_SIZE: tl.constexpr,
):
bitmask_idx = tl.program_id(0)
logits_idx = tl.load(logits_indices_ptr + bitmask_idx)
mapping_idx = tl.load(logits_indices_ptr + bitmask_idx)
req_idx = mapping_idx // MASK_STRIDE
position_idx = mapping_idx % MASK_STRIDE
logits_idx = tl.load(cu_num_logits_ptr + req_idx)
num_req_logits = tl.load(cu_num_logits_ptr + req_idx + 1) - logits_idx
logits_idx += position_idx
position_is_active = position_idx < num_req_logits
# Load the bitmask.
block_id = tl.program_id(1)
@@ -111,5 +134,5 @@ def _apply_grammar_bitmask_kernel(
tl.store(
logits_ptr + logits_idx * logits_stride + block_offset,
-float("inf"),
mask=bitmask & (block_offset < vocab_size),
mask=position_is_active & bitmask & (block_offset < vocab_size),
)