Skip to content

Conversation

weireweire
Copy link
Collaborator

@weireweire weireweire commented Aug 4, 2025

📌 Description

Unify decode and prefill attention test for trtllm-gen by extract common function. Support fp8/fp4 qkvo scale, o_sf, o_sf offset test.

🔍 Related Issues

🚀 Pull Request Checklist

Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.

✅ Pre-commit Checks

  • I have installed pre-commit by running pip install pre-commit (or used your preferred method).
  • I have installed the hooks with pre-commit install.
  • I have run the hooks manually with pre-commit run --all-files and fixed any reported issues.

If you are unsure about how to set up pre-commit, see the pre-commit documentation.

🧪 Tests

  • Tests have been added or updated as needed.
  • All tests are passing (unittest, etc.).

Reviewer Notes

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.

Summary of Changes

Hello @weireweire, 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 significantly refactors and expands the testing infrastructure for the trtllm-gen backend's attention mechanisms. It unifies the batch prefill and decode attention tests into a single, more modular file, improving maintainability and clarity. A key enhancement is the addition of robust testing for various quantization schemes, including FP8 and FP4, ensuring correct handling of associated scaling factors and offsets.

Highlights

  • Test Unification and Modularization: Consolidated trtllm-gen batch prefill and decode attention tests into a single new file (tests/test_trtllm_gen_attention.py), extracting common utility functions to improve code organization and reduce redundancy.
  • Expanded Quantization Testing: Added comprehensive test coverage for fp8 and nvfp4 (FP4) data types, specifically verifying qkvo scales, output scaling factors (o_sf), and o_sf offsets in both prefill and decode operations.
  • Test File Restructuring: Removed the tests/test_trtllm_gen_context.py file and significantly refactored tests/test_trtllm_gen_decode.py as their functionalities are now covered by the new unified test suite.
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 or fill out our survey to provide feedback.

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 unifies decode and prefill attention tests for trtllm-gen by extracting common functions and adding support for fp8/fp4 qkvo scale, o_sf, and o_sf offset tests. To improve robustness and clarity, I've suggested ensuring the q tensor is contiguous before being passed into the decode function.

Copy link
Collaborator

@yzh119 yzh119 left a comment

Choose a reason for hiding this comment

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

@weireweire
Copy link
Collaborator Author

It's better to reuse this test for recently added sink support. please consider the conflict.

Copy link
Collaborator

@yzh119 yzh119 left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @weireweire for the refactor.

It's better to reuse this test for recently added sink support. please consider the conflict.

Yes let's leave that for future work.

@weireweire
Copy link
Collaborator Author

We'd better merge this soon, more conflict will coming

@weireweire
Copy link
Collaborator Author

weireweire commented Aug 12, 2025

rebased and fixed a prefill blocker. please merge soon, @yzh119
And I didn't see sink test in old attention test. is it added?

@@ -2096,7 +2096,8 @@ def run(
lse=lse,
)
else:
assert self._plan_info is not None, "plan info is not initialized"
if self._backend == "cudnn":
Copy link
Collaborator

Choose a reason for hiding this comment

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

This check is not needed for cudnn. See Line 2073. This is already in else part. I added this since run_args has _plan_info and mypy was complaining.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, filter out trtllm-gen check then.

@yzh119
Copy link
Collaborator

yzh119 commented Aug 13, 2025

And I didn't see sink test in old attention test. is it added?

They are tested in https://github.com/flashinfer-ai/flashinfer/blob/main/tests/test_attention_sink.py and https://github.com/flashinfer-ai/flashinfer/blob/main/tests/test_attention_sink_blackwell.py, we can unify them later.

@yzh119 yzh119 merged commit 30319e7 into flashinfer-ai:main Aug 13, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants