Skip to content

Comments

Support w8a8_fp8_block with cutlass kernel, and use DeepEP DeepGEMM#15386

Open
Wangzheee wants to merge 3 commits intosgl-project:mainfrom
Wangzheee:support_w8a8_fp8_block
Open

Support w8a8_fp8_block with cutlass kernel, and use DeepEP DeepGEMM#15386
Wangzheee wants to merge 3 commits intosgl-project:mainfrom
Wangzheee:support_w8a8_fp8_block

Conversation

@Wangzheee
Copy link

@Wangzheee Wangzheee commented Dec 18, 2025

Motivation

support llm-compressor quant model use DeepEP DeepGEMM
support llm-compressor quant model w8a8_fp8(block-quant) use cutlass kernel

Use recipe changed 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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 w8a8_fp8_block quantization with the high-performance Cutlass kernel and enabling the use of DeepEP DeepGEMM for llm-compressor quantized models. It introduces a more robust mechanism for handling block quantization parameters and dynamically selects the optimal MoE runner backend, enhancing performance and compatibility across various quantization schemes and hardware configurations.

Highlights

  • Enhanced Block Quantization Handling: Improved logic for retrieving weight_block_size in linear.py to support llm-compressor quantized models, ensuring proper block quantization parameter retrieval.
  • DeepGEMM Integration for MoE: Enabled the use of DeepEP DeepGEMM as a MoE runner backend, with dynamic selection based on configuration and hardware capabilities.
  • Cutlass Kernel Support for W8A8-FP8 Block Quantization: Introduced support for w8a8_fp8_block quantization using the Cutlass kernel for fused MoE experts, including necessary tensor initializations and hardware capability checks (SM90/SM100).
  • Flexible MoE Runner Backend Selection: The MoE runner now dynamically chooses between DeepGEMM, Cutlass, and Triton backends based on availability and configuration for block quantization strategies.
  • Expanded Quantization Compatibility: Extended Cutlass MoE support in server_args.py to include compressed-tensors quantization, alongside existing fp8 support.

🧠 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 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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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. 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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 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.

Comment on lines 123 to 124
weight_quant = quant_config.target_scheme_map["Linear"].get("weights")
input_quant = quant_config.target_scheme_map["Linear"].get("input_activations")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Comment on lines +695 to +746
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
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Comment on lines +879 to +898
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)

Comment on lines +956 to +957
scale_block_size = 128
block_shape = [scale_block_size, scale_block_size]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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]

@Wangzheee Wangzheee mentioned this pull request Dec 18, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant