Support speculative decoding in hybrid attention backend#9573
Support speculative decoding in hybrid attention backend#9573zhyncs merged 5 commits intosgl-project:mainfrom
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @Qiaolin-Yu, 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 introduces support for speculative decoding within the hybrid attention backend, which was previously unsupported. This enhancement allows for more efficient inference by leveraging both prefill and decode attention mechanisms in conjunction with speculative decoding algorithms. The changes involve adapting the HybridAttnBackend to correctly manage CUDA graph states and forward metadata for speculative operations, updating the ModelRunner to permit this configuration, and adding new test cases to validate the functionality.
Highlights
- Speculative Decoding Support: Enables the use of speculative decoding algorithms with the HybridAttnBackend, allowing for potential performance improvements in inference.
- HybridAttnBackend Enhancements: The HybridAttnBackend now correctly initializes CUDA graph states for both prefill and decode backends when speculative decoding is active, and intelligently dispatches forward metadata calls based on the current forward_mode.
- Configuration Flexibility: Removes a previous restriction in the ModelRunner that prevented the combination of hybrid attention and speculative decoding, providing greater flexibility in backend configuration.
- Comprehensive Testing: Introduces a new dedicated test suite, TestHybridAttnBackendSpeculativeDecoding, to ensure the stability and correctness of speculative decoding when used with the hybrid attention backend.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request adds support for speculative decoding in the hybrid attention backend. The changes involve updating the HybridAttnBackend to correctly delegate calls to either the prefill or decode backends based on the forward mode, which is crucial for handling the verification step in speculative decoding. The ModelRunner is also updated to allow this configuration, and a new test case is added to validate the functionality. The changes are logical and well-implemented. I've suggested some refactoring to reduce code duplication in HybridAttnBackend for better maintainability.
Motivation
Close #9330
Modifications
Accuracy Tests
Launch the server
Test accuracy
Accuracy: 0.794
Benchmarking and Profiling
Checklist