Support w8a8_fp8_block with cutlass kernel, and use DeepEP DeepGEMM#15386
Support w8a8_fp8_block with cutlass kernel, and use DeepEP DeepGEMM#15386Wangzheee wants to merge 3 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello @Wangzheee, 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 advances the quantization capabilities by integrating 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. 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 w8a8_fp8 block quantization with cutlass kernels and integrates DeepEP DeepGEMM for llm-compressor models. The changes are primarily within python/sglang/srt/layers/quantization/compressed_tensors/compressed_tensors_moe.py and introduce significant new logic for handling different quantization backends.
My review has identified a critical issue where new logic for quantization scheme detection is being incorrectly overwritten, rendering it ineffective. Additionally, there are several medium-severity concerns regarding code duplication, the use of magic numbers, and large blocks of boilerplate code that would benefit from refactoring to improve maintainability and readability. Addressing these points will enhance the quality and robustness of the new features.
| weight_quant = quant_config.target_scheme_map["Linear"].get("weights") | ||
| input_quant = quant_config.target_scheme_map["Linear"].get("input_activations") |
There was a problem hiding this comment.
The logic added in lines 107-121 to determine weight_quant and input_quant from a matched target is immediately overwritten by these two lines. This appears to be a copy-paste error from the original code and renders the new matching logic ineffective. Please remove these lines to ensure the correct quantization schemes are used.
| if self.use_cutlass_fused_experts_fp8: | ||
| self.ab_strides1 = torch.full( | ||
| (num_experts,), | ||
| hidden_size, | ||
| device=w13_weight.device, | ||
| dtype=torch.int64, | ||
| ) | ||
| self.c_strides1 = torch.full( | ||
| (num_experts,), | ||
| 2 * intermediate_size_per_partition, | ||
| device=w13_weight.device, | ||
| dtype=torch.int64, | ||
| ) | ||
| self.ab_strides2 = torch.full( | ||
| (num_experts,), | ||
| intermediate_size_per_partition, | ||
| device=w2_weight.device, | ||
| dtype=torch.int64, | ||
| ) | ||
| self.c_strides2 = torch.full( | ||
| (num_experts,), | ||
| hidden_size, | ||
| device=w2_weight.device, | ||
| dtype=torch.int64, | ||
| ) | ||
| self.workspace = torch.empty( | ||
| 90000, device=w13_weight.device, dtype=torch.uint8 | ||
| ) | ||
| self.a_ptr = torch.empty( | ||
| num_experts, device=w13_weight.device, dtype=torch.int64 | ||
| ) | ||
| self.b_ptr = torch.empty( | ||
| num_experts, device=w13_weight.device, dtype=torch.int64 | ||
| ) | ||
| self.out_ptr = torch.empty( | ||
| num_experts, device=w13_weight.device, dtype=torch.int64 | ||
| ) | ||
| self.a_scales_ptr = torch.empty( | ||
| num_experts, device=w13_weight.device, dtype=torch.int64 | ||
| ) | ||
| self.b_scales_ptr = torch.empty( | ||
| num_experts, device=w13_weight.device, dtype=torch.int64 | ||
| ) | ||
| self.expert_offsets = torch.empty( | ||
| num_experts + 1, device=w13_weight.device, dtype=torch.int32 | ||
| ) | ||
| self.problem_sizes1 = torch.empty( | ||
| num_experts, 3, device=w13_weight.device, dtype=torch.int32 | ||
| ) | ||
| self.problem_sizes2 = torch.empty( | ||
| num_experts, 3, device=w13_weight.device, dtype=torch.int32 | ||
| ) |
There was a problem hiding this comment.
This large block of code initializes numerous tensors required for the cutlass kernel. This boilerplate could be encapsulated into a helper function or a dedicated data class to improve readability and maintainability. For example, a method _initialize_cutlass_buffers(...) could handle this setup.
Additionally, the workspace size is hardcoded to 90000 on line 721. This magic number should be replaced with a named constant and a comment explaining how this value was determined or if it should be calculated dynamically.
| moe_runner_backend = get_moe_runner_backend() | ||
| if moe_runner_backend.is_auto(): | ||
| if ( | ||
| deep_gemm_wrapper.ENABLE_JIT_DEEPGEMM | ||
| and get_moe_a2a_backend().is_deepep() | ||
| ): | ||
| moe_runner_backend = MoeRunnerBackend.DEEP_GEMM | ||
| else: | ||
| moe_runner_backend = MoeRunnerBackend.TRITON | ||
| elif moe_runner_backend.is_deep_gemm() or moe_runner_backend.is_triton(): | ||
| pass # moe_runner_backend is already set | ||
| else: | ||
| if ( | ||
| deep_gemm_wrapper.ENABLE_JIT_DEEPGEMM | ||
| and get_moe_a2a_backend().is_deepep() | ||
| ): | ||
| moe_runner_backend = MoeRunnerBackend.DEEP_GEMM | ||
| else: | ||
| moe_runner_backend = MoeRunnerBackend.TRITON | ||
| self.runner = MoeRunner(moe_runner_backend, moe_runner_config) |
There was a problem hiding this comment.
The logic to determine the moe_runner_backend is duplicated. The code block inside if moe_runner_backend.is_auto(): is identical to the one in the final else: block. This can be simplified to avoid redundancy and improve maintainability.
moe_runner_backend = get_moe_runner_backend()
if not (moe_runner_backend.is_deep_gemm() or moe_runner_backend.is_triton()):
if (
deep_gemm_wrapper.ENABLE_JIT_DEEPGEMM
and get_moe_a2a_backend().is_deepep()
):
moe_runner_backend = MoeRunnerBackend.DEEP_GEMM
else:
moe_runner_backend = MoeRunnerBackend.TRITON
self.runner = MoeRunner(moe_runner_backend, moe_runner_config)| scale_block_size = 128 | ||
| block_shape = [scale_block_size, scale_block_size] |
There was a problem hiding this comment.
The scale_block_size is hardcoded to 128. This magic number should be defined as a named constant (e.g., SCALE_BLOCK_SIZE) to improve readability and maintainability. A comment explaining the choice of 128 would also be beneficial.
# A block size of 128 is a common and often optimal choice for performance.
SCALE_BLOCK_SIZE = 128
block_shape = [SCALE_BLOCK_SIZE, SCALE_BLOCK_SIZE]
Motivation
support llm-compressor quant model use DeepEP DeepGEMM
support llm-compressor quant model w8a8_fp8(block-quant) use cutlass kernel
Use
recipechanged to target different quantization algorithms or formats.recipe = QuantizationModifier(
targets="Linear",
scheme="FP8_BLOCK",
ignore=["lm_head", "re:.*mlp.gate$"],
)
support w8a8_fp8(block-quant) with cutlass kernel
support use DeepEP DeepGEMM
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist