-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[WIP] [BugFix] Forward spec_step_idx in MTP wrappers and eagle proposer/speculator #36910
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 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 |
|---|---|---|
|
|
@@ -109,6 +109,7 @@ def run_model( | |
| slot_mappings: dict[str, torch.Tensor] | None, | ||
| num_tokens_across_dp: torch.Tensor | None, | ||
| cudagraph_runtime_mode: CUDAGraphMode = CUDAGraphMode.NONE, | ||
| spec_step_idx: int = 0, | ||
| ) -> tuple[torch.Tensor, torch.Tensor]: | ||
| batch_descriptor = BatchDescriptor(num_tokens=num_tokens) | ||
| with set_forward_context( | ||
|
|
@@ -124,6 +125,7 @@ def run_model( | |
| input_ids=self.input_buffers.input_ids[:num_tokens], | ||
| positions=self.input_buffers.positions[:num_tokens], | ||
| hidden_states=self.hidden_states[:num_tokens], | ||
| spec_step_idx=spec_step_idx, | ||
| ) | ||
| if self.method == "mtp": | ||
| last_hidden_states = ret_hidden_states | ||
|
|
@@ -153,10 +155,11 @@ def generate_draft( | |
| slot_mappings, | ||
| num_tokens_across_dp, | ||
| cudagraph_runtime_mode, | ||
| spec_step_idx=step, | ||
| ) | ||
| last_hidden_states = last_hidden_states[:num_reqs] | ||
| hidden_states = hidden_states[:num_reqs] | ||
| logits = self.model.compute_logits(last_hidden_states) | ||
| logits = self.model.compute_logits(last_hidden_states, spec_step_idx=step) | ||
|
Comment on lines
155
to
+162
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. The To make this more robust, you could check if the model's methods support the |
||
|
|
||
| # NOTE(woosuk): We must add 1 to the positions to match the Gumbel noise | ||
| # used for draft and target sampling. | ||
|
|
@@ -264,7 +267,7 @@ def propose( | |
| num_tokens_across_dp=num_tokens_across_dp, | ||
| ) | ||
| sample_hidden_states = last_hidden_states[last_token_indices] | ||
| logits = self.model.compute_logits(sample_hidden_states) | ||
| logits = self.model.compute_logits(sample_hidden_states, spec_step_idx=0) | ||
|
|
||
| num_reqs = input_batch.num_reqs | ||
| num_reqs_padded = input_batch.num_reqs_after_padding | ||
|
|
||
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.
The
get_top_tokensmethod is called without thespec_step_idxargument. Whenuse_local_argmax_reductionis enabled, this will cause the wrong decoder layer to be used for speculative steps beyond the first, leading to incorrect draft tokens. This seems to defeat the purpose of this bug fix for this code path.To fix this,
spec_step_idxshould be passed toget_top_tokens. You will also need to update theget_top_tokensmethod on the MTP models to accept and use this parameter, similar to howcompute_logitsis being updated.