-
Notifications
You must be signed in to change notification settings - Fork 484
feat: update cubins for dynamic scale factor interface and one-copy kvcache on trtllm-gen mla #1248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 @yyihuang, 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 a more explicit and flexible interface for handling scaling factors within the trtllm-gen mla kernels
. By replacing a single scale parameter with a set of five specific scales (for query, key, value, softmax, and output), the changes enable finer-grained control over quantization, particularly in preparation for future FP8 quantization support. The modifications span both the Python API and the underlying C++ CUDA kernels, ensuring consistent behavior and improved extensibility for advanced quantization schemes.
Highlights
- API Interface Update: The
trtllm_batch_decode_with_kv_cache_mla
function inflashinfer/decode.py
and its corresponding C++ kernel launcher (trtllm_paged_attention_mla_launcher
incsrc/trtllm_mla_kernel_launcher.cu
) have been refactored to replace a single genericscale
parameter with five distinct, more granular scaling factors:q_scale
,k_scale
,v_scale
,sm_scale
, ando_scale
. - Dynamic Scale Factor Derivation: The
bmm1_scale
andbmm2_scale
values, which are consumed by the C++ kernel, are now dynamically computed within the Python wrapper (flashinfer/decode.py
) based on the newly introduced granular input scales. Specifically,bmm1_scale
is derived fromq_scale
,k_scale
, andsm_scale
(and the head dimension), whilebmm2_scale
is derived fromv_scale
ando_scale
. - Internal Kernel Logic Adjustment: In the C++ kernel (
csrc/trtllm_mla_kernel_launcher.cu
), therunner_params.mScaleQ
(previously controlled by the genericscale
parameter) is now hardcoded to1.0
. Therunner_params.scaleSoftmaxLog2
calculation has been updated tobmm1_scale * std::sqrt((float)(runner_params.mHeadDimQk))
, aligning with the new scale derivation logic from the Python frontend. - Test Suite Adaptation: The test cases in
tests/test_trtllm_gen_decode.py
have been updated to reflect the new function signature and parameter passing fortrtllm_batch_decode_with_kv_cache_mla
, ensuring the correctness and compatibility of the changes.
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 is currently in preview and 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 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
-
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. ↩
There was a problem hiding this 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 refactors the scaling factor interface for the TRT-LLM MLA kernels, moving from a single scale
parameter to a more detailed set of quantization and model scales (q_scale
, k_scale
, v_scale
, sm_scale
, o_scale
). This improves clarity and flexibility. The changes are mostly in the C++ kernel launcher and the Python interface.
I've found two high-severity issues that should be addressed:
- In
csrc/trtllm_mla_kernel_launcher.cu
, there's a bug in the calculation of the softmax scaling factor, which uses an incorrect head dimension. - In
flashinfer/decode.py
, there's an incorrect shape and dtype check for the pre-allocated output tensor, which would cause runtime errors.
…into trtllm-mla-cubin
<!-- .github/pull_request_template.md --> ## 📌 Description Enable deepseek MTP with q>1. Recommend small batch size and small MTP = 2 / 3. Update tests to reduce test time. Draft dynamic scale factor interface of mla (part1, part2 - cubin loading & fmha in #1248) --ready to merge now. ## 🔍 Related Issues <!-- Link any related issues here --> ## 🚀 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 - [x] I have installed `pre-commit` by running `pip install pre-commit` (or used your preferred method). - [x] I have installed the hooks with `pre-commit install`. - [x] 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](https://pre-commit.com/). ## 🧪 Tests - [x] Tests have been added or updated as needed. - [x] All tests are passing (`unittest`, etc.). ## Reviewer Notes <!-- Optional: anything you'd like reviewers to focus on, concerns, etc. --> --------- Co-authored-by: averyhuang <averyh@nvidia.com>
Close to skip rebasing on last refactor. Moved to #1342. |
📌 Description
Update the static scaling factor interface to take:
q_scale, k_scale, v_scale, sm_scale, o_scale.
🔍 Related Issues
TODOs in #1222, last comment.
🚀 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
pre-commit
by runningpip install pre-commit
(or used your preferred method).pre-commit install
.pre-commit run --all-files
and fixed any reported issues.🧪 Tests
unittest
, etc.).Reviewer Notes