Repository navigation
[Spec Decode] EAGLE 3: Micro-optimization of Draft to Target logit conversion #25917
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
Changes from 2 commits
abaf62a
65abf20
4adfe09
e827152
e45518b
7d9dc18
b60c9d4
58a84e4
a916afb
85449d3
efbbb86
ac87436
0091604
888d041
ad8586f
aa2aaf3
369b9ed
6f92f4d
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||
| import torch | ||||||
| from typing import Optional | ||||||
|
|
||||||
| class EagleMixin: | ||||||
| def propose_chain(self, hidden_states: torch.Tensor) -> torch.Tensor: | ||||||
|
Member
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.
Member
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. Or "greedy_sample_draft_tokens" might be more appropriate since I now see that this is a shortcut for compute_logits + greedy sampling
Contributor
Author
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. There is a method called propose_tree so propose_chain is analogious to it. The
Member
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. In what way is
Contributor
Author
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.
The functionality/role of For E1, its compute logits and argmax whereas in E3 it has an extra step of offset computation. This different behavior of E1 and E3 is abstracted away from
Member
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. I see what you mean. I think I would still prefer something like
Contributor
Author
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. Alright, I have renamed it to |
||||||
| logits = self.compute_logits(hidden_states) | ||||||
| draft_token_ids = logits.argmax(dim=-1) | ||||||
| return draft_token_ids | ||||||
|
|
||||||
| class Eagle3Mixin: | ||||||
| def compute_draft_logits( | ||||||
| self, | ||||||
| hidden_states: torch.Tensor, | ||||||
| ) -> Optional[torch.Tensor]: | ||||||
| # Computes draft logits from hidden states. | ||||||
| logits = self.logits_processor(self.lm_head, hidden_states) | ||||||
| return logits | ||||||
|
|
||||||
| def compute_logits( | ||||||
| self, | ||||||
| hidden_states: torch.Tensor, | ||||||
| ) -> Optional[torch.Tensor]: | ||||||
| # Maps draft logits to target logits. | ||||||
| logits = self.compute_draft_logits(hidden_states) | ||||||
| if self.draft_id_to_target_id is None: | ||||||
| assert logits.shape[1] == self.config.vocab_size, \ | ||||||
| "Expected logits to have shape " \ | ||||||
| f"(*, {self.config.vocab_size}), but got {logits.shape}" | ||||||
| return logits | ||||||
|
|
||||||
| base = torch.arange(self.config.draft_vocab_size, device=logits.device) | ||||||
| targets = base + self.draft_id_to_target_id | ||||||
| logits_new = logits.new_full(( | ||||||
| logits.shape[0], | ||||||
| self.config.vocab_size, | ||||||
| ), float('-inf')) | ||||||
| logits_new[:, targets] = logits | ||||||
| return logits_new | ||||||
|
|
||||||
| def propose_chain(self, hidden_states: torch.Tensor) -> torch.Tensor: | ||||||
| logits = self.compute_draft_logits(hidden_states) | ||||||
|
Member
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. I think this is supposed to call
Suggested change
Contributor
Author
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.
|
||||||
| draft_token_ids = logits.argmax(dim=-1) | ||||||
| offset = self.draft_id_to_target_id[draft_token_ids] | ||||||
|
ekagra-ranjan marked this conversation as resolved.
Resolved
|
||||||
| draft_token_ids += offset | ||||||
| return draft_token_ids | ||||||
|
ekagra-ranjan marked this conversation as resolved.
Resolved
|
||||||
Uh oh!
There was an error while loading. Please reload this page.