-
Notifications
You must be signed in to change notification settings - Fork 470
feature: add fp4 mm using trtllm backend #1355
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # 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 @ttyio, 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 enhances FlashInfer's capabilities for efficient quantized matrix multiplication by integrating the TensorRT-LLM backend for FP4 operations. It introduces support for flexible 128x4 and 8x4 block quantization layouts and incorporates an autotuning framework to dynamically select optimal GEMM kernels, leading to improved performance and broader applicability for various model architectures.
Highlights
- New FP4 GEMM Backend: I've added support for FP4 matrix multiplication using the TensorRT-LLM (TRTLLM) backend, providing an alternative to the existing cuDNN backend for quantized GEMM operations.
- Flexible Scale Factor Layouts: The implementation now supports both 128x4 and 8x4 block quantization layouts for scale factors. This allows for more granular control and potential optimization based on the specific matrix dimensions and hardware characteristics.
- Autotuning for TRTLLM GEMM: A new autotuning mechanism has been integrated for the TRTLLM FP4 GEMM. This enables dynamic selection of the most performant kernel tactic at runtime, adapting to different input shapes and maximizing efficiency.
- Unified FP4 Quantization API: I've introduced a new
nvfp4_quantize
API that streamlines the quantization process. This function handles both the core quantization logic and the necessary data shuffling required for the TRTLLM backend, simplifying its usage. - Code Refactoring and Centralization: Matrix shuffling utilities have been refactored and centralized into
flashinfer/utils.py
andflashinfer/fp4_quantization.py
. This improves code organization and maintainability by consolidating related functionalities.
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
-
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 introduces support for FP4 matrix multiplication using the TensorRT-LLM backend, which is a significant feature addition. The changes include support for both 128x4 and 8x4 block quantization layouts and autotuning capabilities. The code is well-structured, with a major refactoring of the GEMM runner into a dedicated class and clear separation of concerns.
I've identified a critical bug in csrc/trtllm_gemm_runner.cu
where an incorrect type is passed for the device index, which will likely lead to a compilation failure. Additionally, there's a documentation error in flashinfer/gemm.py
regarding the scale factor layout requirements for the new backend, which could mislead users. Once these issues are addressed, the PR should be in good shape.
dc75fd3
to
961e759
Compare
1. support both 128x4 and 8x4 block quant layout 2. support autotuning Signed-off-by: Vincent Huang <vincenth@nvidia.com>
961e759
to
08bb8f8
Compare
@yzh119 can I get this reviewed/merged when you have time? thank you! |
include/flashinfer/trtllm/gemm/trtllmGen_gemm_export/KernelMetaInfo.h
Outdated
Show resolved
Hide resolved
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.
Overall LGTM, left some suggestions on coding style.
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.
LGTM, thanks @ttyio !
…ZZLED (#1371) <!-- .github/pull_request_template.md --> ## 📌 Description cutlass fused moe modules are broken after #1355 because the structure of `FP4QuantizationSFLayout` has changed. This PR fixes the issue. ## 🔍 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 cc @wenscarl @ttyio
feature: add fp4 mm using trtllm backend
📌 Description
🔍 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
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