[Model Runner V2] Cache draft logits in model's LM head dtype (#50910)

Signed-off-by: Giancarlo Delfin <gdelfin@inferact.ai>
This commit is contained in:
Giancarlo Delfin
2026-08-05 19:12:46 -07:00
committed by GitHub
parent f85c1d2f84
commit 81bc196913
6 changed files with 170 additions and 76 deletions
@@ -127,8 +127,8 @@ class DSparkSpeculator(DFlashSpeculator):
self.seeds,
sample_pos - 1,
apply_temperature=True,
output_processed_logits=self.draft_logits,
output_processed_logits_col=self._step_cols[step],
logits_cache=self.draft_logits,
logits_cache_col=self._step_cols[step],
use_fp64=self.use_fp64_gumbel,
)
@@ -123,6 +123,7 @@ def _compute_global_logprobs_and_logsumexp(
logit_idx,
req_state_idx,
draft_step,
temp,
# [num_logits, V]
target_logits_ptr,
target_logits_stride,
@@ -160,14 +161,18 @@ def _compute_global_logprobs_and_logsumexp(
)
target_log_prob = target_logit - target_lse
if HAS_DRAFT_LOGITS:
draft_logit = tl.load(
draft_logits_ptr
+ req_state_idx * draft_logits_stride_0
+ draft_step * draft_logits_stride_1
+ token,
mask=mask,
other=float("-inf"),
).to(tl.float32)
# draft_logits is stored pre-temperature, so apply scale first.
draft_logit = (
tl.load(
draft_logits_ptr
+ req_state_idx * draft_logits_stride_0
+ draft_step * draft_logits_stride_1
+ token,
mask=mask,
other=float("-inf"),
).to(tl.float32)
/ temp
)
draft_lse = _compute_global_logsumexp(
draft_local_max_ptr,
draft_local_max_stride,
@@ -272,15 +277,19 @@ def _compute_local_logits_stats_kernel(
target_sumexp,
)
if HAS_DRAFT_LOGITS:
# Get local draft max and summed exponentials.
draft_logits = tl.load(
draft_logits_ptr
+ req_state_idx * draft_logits_stride_0
+ draft_step_idx * draft_logits_stride_1
+ block_offsets,
mask=mask,
other=float("-inf"),
).to(tl.float32)
# Get local draft max and summed exponentials. draft_logits is
# stored pre-temperature, so apply scale first.
draft_logits = (
tl.load(
draft_logits_ptr
+ req_state_idx * draft_logits_stride_0
+ draft_step_idx * draft_logits_stride_1
+ block_offsets,
mask=mask,
other=float("-inf"),
).to(tl.float32)
/ temp
)
draft_max, draft_sumexp = _compute_max_and_sumexp(draft_logits)
tl.store(
draft_local_max_ptr + logit_idx * draft_local_max_stride + block_idx,
@@ -348,6 +357,7 @@ def _compute_cumulative_log_p_kernel(
logit_idx,
req_state_idx,
step,
temp,
target_logits_ptr,
target_logits_stride,
target_local_max_ptr,
@@ -429,6 +439,7 @@ def _compute_local_residual_mass_kernel(
logit_idx,
req_state_idx,
draft_step_idx,
temp,
target_logits_ptr,
target_logits_stride,
target_local_max_ptr,
@@ -599,6 +610,7 @@ def _rejection_kernel(
logit_idx,
req_state_idx,
i,
temp,
target_logits_ptr,
target_logits_stride,
target_local_max_ptr,
@@ -724,14 +736,18 @@ def _resample_kernel(
# Bonus token (no rejections). Directly use the target logits.
residual_logits = target_logits
elif HAS_DRAFT_LOGITS:
draft_logits = tl.load(
draft_logits_ptr
+ req_state_idx * draft_logits_stride_0
+ resample_idx * draft_logits_stride_1
+ block,
mask=mask,
other=float("-inf"),
).to(tl.float32)
# draft_logits is stored pre-temperature, so apply scale first.
draft_logits = (
tl.load(
draft_logits_ptr
+ req_state_idx * draft_logits_stride_0
+ resample_idx * draft_logits_stride_1
+ block,
mask=mask,
other=float("-inf"),
).to(tl.float32)
/ temp
)
target_lse = tl.load(target_rejected_logsumexp_ptr + req_idx)
draft_lse = tl.load(draft_rejected_logsumexp_ptr + req_idx)
target_log_probs = target_logits - target_lse
@@ -784,9 +800,9 @@ def _resample_kernel(
temp_ptr,
seed_ptr,
pos_ptr,
None, # processed_logits_ptr
0, # processed_logits_stride
None, # processed_logits_col_ptr
None, # logits_cache_ptr
0, # logits_cache_stride
None, # logits_cache_col_ptr
vocab_size,
APPLY_TEMPERATURE=False,
USE_FP64=USE_FP64,
+4 -3
View File
@@ -131,11 +131,12 @@ class DraftModelSpeculator(BaseSpeculator):
self.draft_logits: torch.Tensor | None = None
if self.speculative_config.draft_sample_method == "probabilistic":
# Pre-temperature logits, cached from the previous decode step.
self.draft_logits = torch.zeros(
self.max_num_reqs,
self.num_speculative_steps,
self.vocab_size,
dtype=torch.float32,
dtype=vllm_config.model_config.head_dtype,
device=device,
)
@@ -332,8 +333,8 @@ class DraftModelSpeculator(BaseSpeculator):
seeds,
positions + 1,
apply_temperature=True,
output_processed_logits=draft_logits,
output_processed_logits_col=draft_step,
logits_cache=draft_logits,
logits_cache_col=draft_step,
use_fp64=self.use_fp64_gumbel,
)
return self._greedy_sample_draft(hidden_states)