Add support for FlashInfer mxfp8#18945
Conversation
Summary of ChangesHello @zianglih, 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 the MXFP8 quantization capabilities by integrating FlashInfer's highly optimized kernels. It introduces FlashInfer support for both general linear operations and Mixture of Experts (MoE) layers, aiming to improve performance and efficiency for models utilizing MXFP8 quantization, especially on Blackwell GPUs. The changes involve updating the quantization dispatch logic and server arguments to enable these new backends. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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 by creating a comment using either
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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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
|
There was a problem hiding this comment.
Code Review
This pull request adds support for FlashInfer mxfp8, including both linear layers and MoE layers. The changes are well-structured, introducing new dispatch logic and kernels for the mxfp8 backend. The code includes necessary validations and updates to server arguments to accommodate the new feature. My review includes a couple of suggestions to improve error messaging for better user experience and to enhance code clarity for future maintenance. Overall, the implementation appears solid.
| w13_scale_block = layer.w13_weight_scale_inv.contiguous().view(torch.int32) | ||
| w2_scale_block = layer.w2_weight_scale_inv.contiguous().view(torch.int32) |
There was a problem hiding this comment.
The conversion from uint8 (the dtype of weight_scale_inv for mxfp8) to int32 using .view() is implicit and relies on the memory layout. For better code clarity and maintainability, it would be beneficial to add a comment explaining this conversion, especially since it's part of a low-level kernel integration.
# The flashinfer kernel expects scales to be packed as int32, where each int32 contains four uint8 scales.
# The shape check `shape[-1] % 4 == 0` above ensures this view is safe.
w13_scale_block = layer.w13_weight_scale_inv.contiguous().view(torch.int32)
w2_scale_block = layer.w2_weight_scale_inv.contiguous().view(torch.int32)| if not (is_blackwell_supported() and is_flashinfer_available()): | ||
| raise RuntimeError( | ||
| "MXFP8 FlashInfer GEMM requested via --fp8-gemm-backend=flashinfer_trtllm, " | ||
| "but FlashInfer is unavailable or unsupported on this hardware." | ||
| ) |
There was a problem hiding this comment.
The error message is a bit generic. It could be more specific about the requirements to help users debug, similar to other error messages in this file. For example, it could mention that Blackwell GPUs and FlashInfer installation are required.
| if not (is_blackwell_supported() and is_flashinfer_available()): | |
| raise RuntimeError( | |
| "MXFP8 FlashInfer GEMM requested via --fp8-gemm-backend=flashinfer_trtllm, " | |
| "but FlashInfer is unavailable or unsupported on this hardware." | |
| ) | |
| if not (is_blackwell_supported() and is_flashinfer_available()): | |
| raise RuntimeError( | |
| "MXFP8 FlashInfer GEMM requested via --fp8-gemm-backend=flashinfer_trtllm, " | |
| "but it is not available or supported on this hardware. " | |
| "This backend requires Blackwell (SM100+) GPUs and FlashInfer to be installed." | |
| ) |
10f0386 to
36bd1f7
Compare
Motivation
@HumansAnd
WIP.
FlashInfer has very good mxfp8 kernels.
Modifications
Dependency
Dense linear requires #19005
MoE requires flashinfer-ai/flashinfer#2581
Accuracy Tests
Benchmarking and Profiling
On B200 TP1 Qwen3-30B-A3B-Instruct-2507-MXFP8,
python3 benchmark/gsm8k/bench_sglang.py --num-shots 8 --num-questions 1209 --parallel 1209 --platinumthroughput is 1.7xChecklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci