Conversation
Summary of ChangesHello @wenscarl, 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 enhances the SGLang runtime by adding support for skip-softmax attention, a technique aimed at optimizing attention computation in large language models. It provides configurable control over this feature for both prefill and decode operations through new environment variables, allowing for potential performance improvements in TRT-LLM attention backends. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for skip-softmax attention by adding two new environment variables for prefill and decode thresholds, and passing them to the respective attention kernels. The changes are generally correct in distinguishing between prefill and decode contexts. However, I've identified one potential issue in nsa_backend.py where a decode-specific configuration might be incorrectly used during a prefill operation. Please see the specific comment for details.
| sparse_mla_top_k=self.nsa_index_topk, | ||
| bmm1_scale=bmm1_scale, | ||
| backend="trtllm-gen", | ||
| skip_softmax_threshold_scale_factor=envs.SGLANG_SKIP_SOFTMAX_DECODE_THRESHOLD_SCALE_FACTOR.get(), |
There was a problem hiding this comment.
This unconditionally uses the decode-specific skip-softmax factor. However, _forward_trtllm can be called for prefill operations via forward_extend when nsa_prefill_impl is set to "trtllm". This could lead to using the wrong threshold for prefill.
You should select the appropriate factor based on the forward_mode of the forward_batch. For example:
is_decode_like = (
forward_batch.forward_mode.is_decode_or_idle()
or forward_batch.forward_mode.is_target_verify()
or forward_batch.forward_mode.is_draft_extend(include_v2=True)
)
skip_softmax_factor = (
envs.SGLANG_SKIP_SOFTMAX_DECODE_THRESHOLD_SCALE_FACTOR.get()
if is_decode_like
else envs.SGLANG_SKIP_SOFTMAX_PREFILL_THRESHOLD_SCALE_FACTOR.get()
)Then use skip_softmax_factor in the function call.
Additionally, please note that flashinfer.decode.trtllm_batch_decode_with_kv_cache_mla is a decode kernel. Using it for prefill might be a separate issue to investigate.
Motivation
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci