Faster weight processing (moe nvfp4)#1412
Conversation
There was a problem hiding this comment.
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 PR aims to improve the performance of weight processing for Mixture-of-Experts (MoE) models, specifically for NVFP4 quantized weights. It achieves this by introducing a caching mechanism for permutation indices, which are costly to recompute. This optimization will speed up the preparation of static weights for kernel operations.
Highlights
- Optimized Weight Permutation: Introduced new utility functions (_maybe_get_cached_w3_w1_permute_indices, _maybe_get_cached_w2_permute_indices) in flashinfer/fused_moe/core.py to cache and reuse permutation indices for MoE weights (W3/W1 and W2). This avoids redundant and expensive recomputations.
- Integration into Weight Preparation: The prepare_static_weights_for_kernel function in the test suite (tests/test_trtllm_gen_fused_moe.py) has been updated to leverage these new caching functions, demonstrating their intended use and benefit in speeding up weight preparation.
- Enhanced Test Coverage: A new pytest fixture cache_permute_indices and modifications to test_moe_quantization_classes were added to properly test the new caching mechanism for weight permutation.
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. ↩
|
pytest -x tests/test_trtllm_gen_fused_moe.py -k FP4 18 passed, 72 skipped, 180 deselected in 132.28s (0:02:12) |
There was a problem hiding this comment.
Code Review
This pull request introduces a caching mechanism for permutation indices to speed up weight processing in the MoE implementation, which is a great performance enhancement. My review focuses on a bug in the caching logic that could lead to incorrect cache hits, and some opportunities for code refactoring to improve maintainability in both the core logic and the tests.
|
@aleozlx awesome work! |
|
@azhurkevich i'll check sgl, got cluster access recently |
|
testing results as of lastest change pytest -x tests/test_trtllm_gen_fused_moe.py 60 passed, 210 skipped in 243.93s (0:04:03) ready to merge from my perspective! |
|
pytest -x tests/test_trtllm_gen_fused_moe.py -k FP4 18 passed, 72 skipped, 180 deselected in 129.88s (0:02:09) |
|
after some discussion on if we want to only test cached code path and remove older version. we are aligned on only testing cached path ready to merge! |
📌 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-commitby runningpip install pre-commit(or used your preferred method).pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
unittest, etc.).Reviewer Notes