[perf][spec decoding] Skip full-vocab softmax in EAGLE draft when topk == 1 (#26235)

This commit is contained in:
Qiaolin Yu
2026-05-25 02:06:48 -07:00
committed by GitHub
parent 7c04b9e942
commit a77449f86d
2 changed files with 26 additions and 6 deletions
@@ -401,6 +401,12 @@ class EAGLEDraftExtendCudaGraphRunner:
forward_batch.positions,
forward_batch,
)
if self.topk == 1:
ret.topk_index = torch.argmax(
ret.next_token_logits, dim=-1, keepdim=True
)
ret.topk_p = torch.ones_like(ret.topk_index, dtype=torch.float32)
else:
probs = torch.softmax(ret.next_token_logits, dim=-1)
ret.topk_p, ret.topk_index = fast_topk(probs, self.topk, dim=-1)
@@ -483,6 +483,14 @@ class EagleDraftWorker(BaseDraftWorker):
forward_batch, skip_attn_backend_init=True
).logits_output
maybe_detect_nan(logits_output.next_token_logits, f"draft_forward step {i}")
if self.topk == 1:
# topk=1 → degenerate single-path tree; `topk_p` is unused
# downstream, so skip softmax and just argmax over logits.
topk_index = torch.argmax(
logits_output.next_token_logits, dim=-1, keepdim=True
)
topk_p = torch.ones_like(topk_index, dtype=torch.float32)
else:
probs = torch.softmax(logits_output.next_token_logits, dim=-1)
topk_p, topk_index = fast_topk(probs, self.topk, dim=-1)
maybe_detect_oob(
@@ -651,6 +659,12 @@ class EagleDraftWorker(BaseDraftWorker):
draft_logits_output.hidden_states = draft_logits_output.hidden_states[
select_index
]
if self.topk == 1:
ret_topk_index = torch.argmax(
draft_logits_output.next_token_logits, dim=-1, keepdim=True
)
ret_topk_p = torch.ones_like(ret_topk_index, dtype=torch.float32)
else:
probs = torch.softmax(draft_logits_output.next_token_logits, dim=-1)
ret_topk_p, ret_topk_index = fast_topk(probs, self.topk, dim=-1)
ret_hidden_states = draft_logits_output.hidden_states