Skip to content

Comments

Support skip-softmax attention#19089

Draft
wenscarl wants to merge 1 commit intosgl-project:mainfrom
wenscarl:skip_softmax
Draft

Support skip-softmax attention#19089
wenscarl wants to merge 1 commit intosgl-project:mainfrom
wenscarl:skip_softmax

Conversation

@wenscarl
Copy link
Collaborator

@wenscarl wenscarl commented Feb 20, 2026

Motivation

Modifications

Accuracy Tests

SGLANG_SKIP_SOFTMAX_PREFILL_THRESHOLD_SCALE_FACTOR=10000.0 \
SGLANG_SKIP_SOFTMAX_DECODE_THRESHOLD_SCALE_FACTOR=500.0 \
python3 -m sglang.launch_server   --model-path Qwen/Qwen3-30B-A3B-Instruct-2507   --trust-remote-code   --disable-radix-cache   --max-running-requests 256     --mem-fraction-static 0.89     --tp 4 --context-length 26214

Benchmarking and Profiling

python -m sglang.test.run_eval     --eval-name longbench_v2       --port 30000 --model Qwen/Qwen3-30B-A3B-Instruct-2507 --max-context-length 240000 --min-context-length 32000 --max-context-length 128000

Without skip-softmax attn:
Total latency: 245.506 s
Score: 0.374

With skip-softmax attn:  
Total latency: 367.109 s
Score: 0.368

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

@github-actions github-actions bot added the blackwell SM100/SM120 label Feb 20, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 Environment Variables: Introduced two new environment variables, SGLANG_SKIP_SOFTMAX_PREFILL_THRESHOLD_SCALE_FACTOR and SGLANG_SKIP_SOFTMAX_DECODE_THRESHOLD_SCALE_FACTOR, to control the skip-softmax attention mechanism for prefill and decode phases, respectively. These variables are set to None by default, indicating standard attention.
  • Attention Backend Integration: Integrated the newly added skip-softmax threshold scale factors into various attention backend implementations, including nsa_backend.py, trtllm_mha_backend.py, and trtllm_mla_backend.py. This allows the attention mechanisms to conditionally skip softmax computation based on the configured thresholds.

🧠 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
  • python/sglang/srt/environ.py
    • Added SGLANG_SKIP_SOFTMAX_PREFILL_THRESHOLD_SCALE_FACTOR and SGLANG_SKIP_SOFTMAX_DECODE_THRESHOLD_SCALE_FACTOR environment variables.
  • python/sglang/srt/layers/attention/nsa_backend.py
    • Modified _forward_standard_mha to pass skip_softmax_threshold_scale_factor.
    • Modified _forward_trtllm to pass skip_softmax_threshold_scale_factor.
  • python/sglang/srt/layers/attention/trtllm_mha_backend.py
    • Modified forward_decode to pass skip_softmax_threshold_scale_factor.
    • Modified forward_extend to pass skip_softmax_threshold_scale_factor for both decode and prefill paths.
  • python/sglang/srt/layers/attention/trtllm_mla_backend.py
    • Imported envs module.
    • Modified forward_decode to pass skip_softmax_threshold_scale_factor.
    • Modified forward_extend to pass skip_softmax_threshold_scale_factor for both decode and prefill paths.
Activity
  • No human activity (comments, reviews, etc.) has occurred on this pull request yet.
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 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(),
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant