[Model Runner V2] Add probabilistic rejection sampling for spec decoding (#35461)

Signed-off-by: Giancarlo Delfin <gdelfin@inferact.ai>
This commit is contained in:
Giancarlo Delfin
2026-03-11 14:04:32 -07:00
committed by GitHub
parent 12001f2ebc
commit c77181e534
9 changed files with 494 additions and 112 deletions
+15
View File
@@ -15,6 +15,8 @@ class RequestState:
num_speculative_steps: int,
vocab_size: int,
device: torch.device,
model_dtype: torch.dtype,
cache_draft_logits: bool,
):
self.max_num_reqs = max_num_reqs
self.max_model_len = max_model_len
@@ -70,6 +72,19 @@ class RequestState:
dtype=torch.int64,
device=device,
)
# Draft token logits.
# NOTE: This tensor maintains the "processed" logits after applying temperature,
# top-p, etc.
self.draft_logits: torch.Tensor | None = None
if cache_draft_logits:
self.draft_logits = torch.zeros(
self.max_num_reqs,
self.num_speculative_steps,
self.vocab_size,
dtype=model_dtype,
device=device,
)
self.next_prefill_tokens = torch.zeros(
self.max_num_reqs, dtype=torch.int32, device=device
)