-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Revert "[perf][spec decoding] Skip full-vocab softmax in EAGLE draft when topk == 1 (#26235)" #26358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert "[perf][spec decoding] Skip full-vocab softmax in EAGLE draft when topk == 1 (#26235)" #26358
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -483,16 +483,8 @@ def draft_forward(self, forward_batch: ForwardBatch): | |||||||||||||||||
| 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) | ||||||||||||||||||
| probs = torch.softmax(logits_output.next_token_logits, dim=-1) | ||||||||||||||||||
| topk_p, topk_index = fast_topk(probs, self.topk, dim=-1) | ||||||||||||||||||
|
Comment on lines
+486
to
+487
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can optimize the top-1 probability computation here as well when if self.topk == 1:
max_logits, topk_index = torch.max(logits_output.next_token_logits, dim=-1, keepdim=True)
topk_p = 1.0 / torch.exp(logits_output.next_token_logits - max_logits).sum(dim=-1, keepdim=True)
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( | ||||||||||||||||||
| topk_index, | ||||||||||||||||||
| 0, | ||||||||||||||||||
|
|
@@ -659,14 +651,8 @@ def _draft_extend_for_decode( | |||||||||||||||||
| 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) | ||||||||||||||||||
| probs = torch.softmax(draft_logits_output.next_token_logits, dim=-1) | ||||||||||||||||||
| ret_topk_p, ret_topk_index = fast_topk(probs, self.topk, dim=-1) | ||||||||||||||||||
|
Comment on lines
+654
to
+655
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apply the same top-1 softmax optimization here to avoid full-vocab softmax and
Suggested change
|
||||||||||||||||||
| ret_hidden_states = draft_logits_output.hidden_states | ||||||||||||||||||
|
|
||||||||||||||||||
| # Construct the return values | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of reverting completely to the full-vocab softmax when$\text{softmax}(x)_{\text{argmax}} = 1 / \sum e^{x_i - \max(x)}$ , we can compute
self.topk == 1, we can mathematically optimize the top-1 probability computation. By using the identitytopk_pandtopk_indexwithout materializing the full softmax tensor in HBM. This avoids the accuracy collapse caused by hardcodingtopk_p = 1.0while retaining the performance benefits of skipping the full-vocab softmax.