[2/N] Quantization Refactor: Compressed tensors MoE schemes#17503
[2/N] Quantization Refactor: Compressed tensors MoE schemes#17503sglang-npu-bot merged 72 commits into
Conversation
Summary of ChangesHello @TamirBaydasov, 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 refactors the Mixture-of-Experts (MoE) quantization implementation within the compressed-tensors library. The primary goal is to transition from a monolithic class structure to a more flexible scheme-based design. This change not only simplifies the integration of future quantization functionalities but also explicitly highlights and enhances support for NPU hardware, ensuring better compatibility and performance across different platforms. 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 refactors the Mixture of Experts (MoE) schemes for compressed tensors by moving them into a new schemes directory. This is a positive structural change that should improve modularity and extensibility. However, the review has identified several critical issues that appear to be oversights from the refactoring process. These include typos that will lead to runtime errors, incorrect method signatures and implementations in the new CompressedTensorsFusedMoEMethod class, and missing methods in one of the new scheme files. Addressing these issues is crucial for the correctness of the implementation.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/rerun-failed-ci |
2 similar comments
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
1 similar comment
|
/rerun-failed-ci |
|
i merge it since both HandH1998 and |
| ): | ||
| self.moe_runner_config = moe_runner_config | ||
|
|
||
| def apply( |
There was a problem hiding this comment.
This should be apply_weights @ping1jing2 @TamirBaydasov , causing this error:
File "/root/xinyuan/sglang/python/sglang/srt/models/deepseek_v2.py", line 1778, in <lambda>
lambda idx, prefix: DeepseekV2DecoderLayer(
^^^^^^^^^^^^^^^^^^^^^^^
File "/root/xinyuan/sglang/python/sglang/srt/models/deepseek_v2.py", line 1522, in __init__
self.mlp = DeepseekV2MoE(
^^^^^^^^^^^^^^
File "/root/xinyuan/sglang/python/sglang/srt/models/deepseek_v2.py", line 386, in __init__
self.experts = get_moe_impl_class(quant_config)(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/xinyuan/sglang/python/sglang/srt/layers/moe/fused_moe_triton/layer.py", line 277, in __init__
self.quant_method = quant_config.get_quant_method(self, prefix)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/xinyuan/sglang/python/sglang/srt/layers/quantization/compressed_tensors/compressed_tensors.py", line 179, in get_quant_method
layer.scheme = self.get_moe_scheme(layer=layer, layer_name=prefix)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/xinyuan/sglang/python/sglang/srt/layers/quantization/compressed_tensors/compressed_tensors.py", line 680, in get_moe_scheme
return CompressedTensorsMxInt4MoE(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Can't instantiate abstract class CompressedTensorsMxInt4MoE without an implementation for abstract method 'apply_weights'
There was a problem hiding this comment.
got it, we will hotfix it tomorrow
…ect#17503) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: ronnie_zheng <zl19940307@163.com> Co-authored-by: Peng Zhang <aniz1905@gmail.com>
…ect#17503) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: ronnie_zheng <zl19940307@163.com> Co-authored-by: Peng Zhang <aniz1905@gmail.com>
…oEMethod The quantization refactor in #17503 introduced CompressedTensorsFusedMoEMethod as a unified quant_method for all compressed-tensors MoE schemes, delegating to layer.scheme. However, restore_weights_before_loading was not forwarded. This causes INT4 weight update to fail in RL training: post_process_weights with restore_weights_before_load=True skips FusedMoE modules because hasattr(quant_method, "restore_weights_before_loading") returns False. The INT4 packed weights (768) are never restored to full size, so load_weights tries to narrow full-size HF weights (1536) into packed parameters and crashes with: RuntimeError: start (0) + length (1536) exceeds dimension size (768) Add the missing delegation with a hasattr guard since only CompressedTensorsWNA16MoE implements restore_weights_before_loading.
…oEMethod The quantization refactor in #17503 introduced CompressedTensorsFusedMoEMethod as a unified quant_method for all compressed-tensors MoE schemes, delegating to layer.scheme. However, restore_weights_before_loading was not forwarded. This causes INT4 weight update to fail in RL training: post_process_weights with restore_weights_before_load=True skips FusedMoE modules because hasattr(quant_method, "restore_weights_before_loading") returns False. The INT4 packed weights (768) are never restored to full size, so load_weights tries to narrow full-size HF weights (1536) into packed parameters and crashes with: RuntimeError: start (0) + length (1536) exceeds dimension size (768) Add the missing delegation with a hasattr guard since only CompressedTensorsWNA16MoE implements restore_weights_before_loading.
Motivation
Add MoE schemes to compressed-tensors instead of storing all classes in a single file. This should make it easier to implement additional functionality as well as clearly show that compressed-tensors also supports NPU hardware in some cases.
Images and motivation for this PR can be viewed in our roadmap: #15194
Modifications
Moved all classes from
compressed_tensors_moe.pyto new schemes in quantization/compressed_tensors/schemes/Removed
compressed_tensors_moe.pyfileAdded
get_moe_schemefunction tocompressed_tensors.pyfileFixed quant method check in
FusedMoEclass to reflect new changesAccuracy Tests
GPU tests:
Qwen3-30B-A3B-Instruct-2507-AWQ
Qwen3-30B-A3B-Instruct-2507-FP8
NPU tests:
Qwen3-30B-A3B-Instruct-2507-W8A8

Benchmarking and Profiling
Not affected
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci