Skip to content

Support fa4 decoding#16034

Merged
Fridge003 merged 7 commits intosgl-project:mainfrom
Qiaolin-Yu:fa4
Jan 21, 2026
Merged

Support fa4 decoding#16034
Fridge003 merged 7 commits intosgl-project:mainfrom
Qiaolin-Yu:fa4

Conversation

@Qiaolin-Yu
Copy link
Copy Markdown
Collaborator

Motivation

Wait for #15182

Modifications

Accuracy Tests

python3 -m sglang.launch_server --model-path Qwen/Qwen3-235B-A22B-Instruct-2507-FP8  --trust-remote-code --attention-backend fa4 --tp 4
python3 benchmark/gsm8k/bench_sglang.py --num-shots 8 --num-questions 131
9 --parallel 1319 
100%|█████████████████████████████████████████████████████████████████████████████████████████| 1319/1319 [04:21<00:00,  5.05it/s]
Accuracy: 0.960
Invalid: 0.000
Latency: 261.286 s
Output throughput: 723.881 token/s

Benchmarking and Profiling

Checklist

@github-actions github-actions Bot added the dependencies Pull requests that update a dependency file label Dec 29, 2025
@gemini-code-assist
Copy link
Copy Markdown
Contributor

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 FlashAttention v4 (FA4) in decoding operations, enhancing the system's ability to leverage advanced attention mechanisms for improved performance during the decoding phase. This was previously restricted to prefill operations. The changes involve updating a core dependency and removing explicit code limitations that prevented FA4 from being used for decoding.

Highlights

  • FlashAttention v4 Decoding Support: Removed previous restrictions that limited FlashAttention v4 (FA4) to prefill operations, enabling its use for decoding.
  • Dependency Update: Updated the nvidia-cutlass-dsl dependency from version 4.2.1 to 4.3.0, which is likely a prerequisite for the new FA4 decoding capabilities.
  • Server Argument Validation: Modified server argument validation to no longer prevent the use of FA4 as a decode attention backend, allowing the --attention-backend fa4 flag to be used for decoding.

🧠 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.

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
Copy Markdown
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 enables FA4 decoding by updating the nvidia-cutlass-dsl dependency and removing checks that previously restricted FA4 to prefill only. The changes look good, but I've identified a couple of potential issues in flashattention_backend.py related to FP8 and MLA compatibility with FA4 that should be addressed for robustness. Please see my detailed comment.

k_rope: Optional[torch.Tensor] = None,
sinks: Optional[torch.Tensor] = None,
) -> torch.Tensor:
assert self.fa_impl_ver in [3], "Only FA3 support decoding"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

While removing this assertion enables FA4 for decoding, there are a couple of related inconsistencies that should be addressed to ensure correctness and prevent unexpected behavior:

  1. FP8 Incompatibility with FA4: The forward_extend method correctly checks for and prevents the use of FA4 with FP8 KV cache (line 747), as it's unsupported. This check is missing in forward_decode at line 1096. This could lead to errors. It's recommended to add and self.fa_impl_ver != 4 to the condition at line 1096.

  2. MLA Path Inconsistency: The forward_extend method asserts that only FA3 is supported for the MLA path (line 949). This check is missing in forward_decode. If FA4 is not supported for MLA, this could lead to silent fallbacks or errors. An assertion should be added around line 1228 for consistency.

@Qiaolin-Yu
Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

Comment thread python/pyproject.toml Outdated
Comment thread python/pyproject.toml Outdated
@Fridge003 Fridge003 merged commit 4f6f5d2 into sgl-project:main Jan 21, 2026
95 of 102 checks passed
@Zhaojp-Frank
Copy link
Copy Markdown

@Qiaolin-Yu great feature! May I ask any performance report avaiable in typical workflows? and does it also boost Hopper?

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

Labels

dependencies Pull requests that update a dependency file high priority run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants