Skip to content

Conversation

@leavelet
Copy link
Contributor

@leavelet leavelet commented Dec 6, 2025

Motivation

Try to resolve #14368

This PR fixes a data misalignment issue in EagleDraftInput.filter_batch that caused "length of new_indices != length of topk_p" warnings and potentially incorrect behavior in Speculative Decoding (EAGLE).

Modifications

Modified EagleDraftInput.filter_batch in python/sglang/srt/speculative/eagle_info.py.

  • Added a check: if len(new_indices) != len(self.topk_p), we force has_been_filtered = False.
  • This ensures that when a length mismatch occurs (indicating the presence of extra/outdated data), we perform explicit indexing using new_indices to correctly filter the data, rather than relying on unsafe slicing

Accuracy Tests

Benchmarking and Profiling

Checklist

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @leavelet, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical data misalignment bug within the EagleDraftInput.filter_batch function, which is integral to the Speculative Decoding (EAGLE) process. The fix ensures that the system correctly handles situations where internal data structures have inconsistent lengths, preventing warnings and potential errors. By adjusting the filtering logic, the change guarantees that the batch processing remains accurate and robust, thereby improving the overall stability and reliability of the speculative decoding mechanism.

Highlights

  • Bug Fix: Resolves a data misalignment issue in the EagleDraftInput.filter_batch method, specifically addressing a scenario where the lengths of new_indices and self.topk_p did not match.
  • Speculative Decoding Robustness: Enhances the robustness of Speculative Decoding (EAGLE) by preventing potential incorrect behavior and warnings related to length mismatches during the prefill/extend phase.
  • Conditional Filtering Logic: Introduces a check that explicitly sets has_been_filtered = False when a length mismatch is detected, ensuring that data is correctly filtered via explicit indexing rather than relying on potentially unsafe slicing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a fix for a data misalignment issue in the Eagle speculative decoding implementation. The change in EagleDraftInput.filter_batch correctly handles cases where spec_info lengths mismatch by forcing has_been_filtered to False. This ensures that explicit, safe indexing is used for filtering data, preventing potential incorrect behavior from unsafe slicing. The fix is well-targeted and the logic is sound, improving the robustness of the speculative decoding process.

@leavelet
Copy link
Contributor Author

leavelet commented Dec 6, 2025

Since the default value of filter_batch is has_been_filtered = True, but the caller cannot accurately determine whether any sequences have already been completed, would it be a good idea to add a check within the function, or should we add the check in all the callers?

I see that @ShangmingCai self-assigned #14368, would you like to take a look?

f"length of new_indices: {len(new_indices)} != length of topk_p: {len(self.topk_p)}, adjuesting has_been_filtered to False"
)
has_been_filtered = False

Copy link
Collaborator

@ShangmingCai ShangmingCai Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a workaround.

QQ: Is it possible that we fix it in here: https://github.com/sgl-project/sglang/blob/main/python/sglang/srt/speculative/eagle_info.py#L188? I think the comment might suggest that the bug actually occurs in the filter step of the verify process.

cc: @hnyls2002

@hnyls2002
Copy link
Collaborator

Moved to #14742

@hnyls2002 hnyls2002 closed this Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] speculative report error when pd mode = normal

3 participants