-
Notifications
You must be signed in to change notification settings - Fork 424
feat: Add weight layout option for trtllm-gen fused moe #1297
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 @aleozlx, 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 enhances the flashinfer
library by adding explicit support for different weight layouts, particularly BlockMajorK
, within its TensorRT-LLM (TRT-LLM) fused Mixture-of-Experts (MoE) kernels. This change allows for more flexible and potentially optimized weight storage and access patterns, which can be beneficial for performance. The modifications span both the Python API and the underlying C++ implementation, ensuring end-to-end support for the new layout.
Highlights
- New Weight Layout Support: Introduced a new
WeightLayout
enum in Python and C++ to support different matrix layouts for GEMM operations, specificallyBlockMajorK
for optimized performance in certain scenarios. - API Extension: Extended the
trtllm_fp8_block_scale_moe
function in the Python API to accept aweight_layout
parameter, allowing users to specify the desired weight organization. - C++ Backend Integration: Propagated the
weight_layout
parameter through the C++TrtllmGenBatchedGemmRunnerOptions
and variousRunner
constructors within thetrtllm_fused_moe
components, ensuring the chosen layout is respected during kernel execution. - Weight Conversion Utility: Added a
convert_to_block_layout
utility function in Python to facilitate the transformation of weight tensors into theBlockMajorK
format, which is crucial for leveraging the new layout. - Test Coverage Expansion: Updated the
test_moe_fp8
suite to include test cases for theBlockMajorK
weight layout, ensuring the new functionality behaves as expected.
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
The pull request introduces weight layout functionality for BlockMajorK usage, including modifications to C++ and Python code to support different weight layouts in the fused MoE kernels. The changes involve adding a new WeightLayout
enum in Python, modifying the kernel launcher and runner in C++, and updating the test suite to include different weight layouts. The code includes checks for valid weight layout values and incorporates the new layout parameter into the kernel execution.
local testing results
|
after slight refactor, double checked fp8
|
ready to merge! pytest -x -v tests/test_trtllm_gen_fused_moe.py 60 passed, 210 skipped in 239.06s (0:03:59) |
after update branch 60 passed, 210 skipped in 250.24s (0:04:10) |
the latest cubin refresh addresses another integration request tested: 60 passed, 210 skipped in 271.29s (0:04:31) as discussed we won't wait for the cubin refactor. pls merge soon when you get a chance @yzh119 thx! |
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 for the great work!
…i#1297) <!-- .github/pull_request_template.md --> ## 📌 Description Expose weight layout for BlockMajorK usage ## 🔍 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. -->
📌 Description
Expose weight layout for BlockMajorK usage
🔍 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