Skip to content

Re-enable Flashinfer TRTLLM GEN MHA and Add Unit Test#12885

Merged
Fridge003 merged 8 commits intosgl-project:mainfrom
samuellees:trtllm-gen-renable
Nov 11, 2025
Merged

Re-enable Flashinfer TRTLLM GEN MHA and Add Unit Test#12885
Fridge003 merged 8 commits intosgl-project:mainfrom
samuellees:trtllm-gen-renable

Conversation

@samuellees
Copy link
Copy Markdown
Contributor

@samuellees samuellees commented Nov 8, 2025

Motivation

Re-enable Flashinfer TRTLLM GEN MHA BF16. And add unit test for it. It was disabled non-intentionally.
Related PR cc @DomBrown
Related PR cc @netanel-haber

cc @yizhang2077

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @samuellees, 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 focuses on enhancing the attention backend capabilities for Blackwell GPUs by re-enabling and thoroughly testing the Flashinfer TRTLLM GEN MHA with BF16 precision. The changes ensure that this high-performance attention mechanism is properly supported and validated, contributing to improved model efficiency and reliability on the latest NVIDIA hardware.

Highlights

  • Re-enable Flashinfer TRTLLM GEN MHA: The Flashinfer TRTLLM GEN MHA (Multi-Head Attention) with BF16 precision has been re-enabled, specifically for use on Blackwell GPUs.
  • Blackwell GPU Backend Support: The assertion logic for Blackwell GPUs has been updated to explicitly allow the trtllm_mha attention backend, alongside the existing triton backend, for hybrid GDN models.
  • New Unit Test for TRTLLM MHA: A new unit test has been added to validate the functionality and accuracy of the trtllm_mha attention backend using the GSM8K benchmark, ensuring its correct operation.
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 re-enables the Flashinfer TRTLLM GEN MHA backend and adds a corresponding unit test. The changes look good overall. I've made a few suggestions to improve code readability and maintainability in both the main logic and the new test file. These include simplifying a condition check, using constants for hardcoded values, deriving the test host from the base URL for consistency, and removing a debug print statement from the test.

Comment on lines 201 to +203
runner.server_args.attention_backend == "triton"
), "triton backend is the only supported backend on Blackwell GPUs for hybrid GDN models, use --attention-backend triton to specify the backend."
or runner.server_args.attention_backend == "trtllm_mha"
), "triton or trtllm_mha backend are the only supported backends on Blackwell GPUs for hybrid GDN models, use --attention-backend triton or --attention-backend trtllm_mha to specify the backend."
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.

medium

For better readability and maintainability, you can use the in operator to check if the attention backend is one of the supported values. This makes the code more concise and easier to extend. Additionally, the assertion message can be simplified.

                    runner.server_args.attention_backend in ("triton", "trtllm_mha")
                ), "Only 'triton' or 'trtllm_mha' backends are supported on Blackwell GPUs for hybrid GDN models. Use --attention-backend to specify one."

class TestFlashinferTrtllmGenAttnBackend(CustomTestCase):
@classmethod
def setUpClass(cls):
cls.model = "Qwen/Qwen3-Next-80B-A3B-Instruct"
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.

medium

To improve maintainability, it's a good practice to define hardcoded strings like model names as constants. This makes it easier to manage and update the model name if needed.

Suggested change
cls.model = "Qwen/Qwen3-Next-80B-A3B-Instruct"
cls.model = "Qwen/Qwen3-Next-80B-A3B-Instruct" # Consider defining as a module-level constant

num_questions=200,
max_new_tokens=512,
parallel=128,
host="http://127.0.0.1",
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.

medium

The host is hardcoded to http://127.0.0.1. For consistency and to avoid potential issues if DEFAULT_URL_FOR_TEST changes, it's better to derive the host from self.base_url, similar to how the port is derived.

Suggested change
host="http://127.0.0.1",
host=self.base_url.rsplit(":", 1)[0],

port=int(self.base_url.split(":")[-1]),
)
metrics = run_eval(args)
print(f"{metrics=}")
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.

medium

This print statement appears to be for debugging purposes. It should be removed to keep the test output clean.

@samuellees samuellees changed the title Renable Flashinfer TRTLLM GEN MHA and Add Unit Test Re-enable Flashinfer TRTLLM GEN MHA and Add Unit Test Nov 8, 2025
@Fridge003
Copy link
Copy Markdown
Collaborator

Fridge003 commented Nov 8, 2025

@samuellees Please add this test to b200 nightly test suite
https://github.com/sgl-project/sglang/blob/main/test/srt/run_suite.py#L220

@samuellees
Copy link
Copy Markdown
Contributor Author

@samuellees Please add this test to b200 nightly test suite https://github.com/sgl-project/sglang/blob/main/test/srt/run_suite.py#L220

Done

Comment thread test/srt/run_suite.py Outdated
@Fridge003 Fridge003 merged commit 3594815 into sgl-project:main Nov 11, 2025
28 of 45 checks passed
@samuellees samuellees deleted the trtllm-gen-renable branch November 11, 2025 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants