Skip to content

Enable 4bit bnb prequant MOE #21548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

py-andy-c
Copy link
Contributor

@py-andy-c py-andy-c commented Jul 24, 2025

Essential Elements of an Effective PR Description Checklist

  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

Purpose

Test Plan

Test Result

(Optional) Documentation Update

Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@mergify mergify bot added the qwen Related to Qwen models label Jul 24, 2025
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 aims to enable 4bit bnb prequant MOE. The changes involve modifying the validation logic for MoE quantization and updating a model implementation to selectively quantize the MoE router gate.

My review identified a critical issue in the validation logic that could lead to a runtime crash, and a high-severity design issue in the model implementation that impacts maintainability and correctness. I've provided suggestions to fix both issues.

Comment on lines +424 to 427
if self.pre_quant and self.load_8bit:
raise ValueError(
"Prequant BitsAndBytes models with FusedMoE is not "
"supported yet.")
if self.load_8bit:
raise ValueError(
"BitsAndBytes 8bit quantization with FusedMoE is not "
"Prequant BitsAndBytes 8bit models with FusedMoE is not "
"supported yet.")
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This change incorrectly allows 8-bit MoE quantization when pre_quant is false. The BitsAndBytesMoEMethod for 8-bit weights is not implemented and raises a NotImplementedError (see vllm/model_executor/layers/quantization/bitsandbytes.py). This will lead to a runtime crash for a configuration that this check now allows.

To enable 4-bit pre-quantized MoE while correctly disallowing 8-bit MoE, you should only check for self.load_8bit. The original check for self.pre_quant was what blocked 4-bit pre-quant, and removing it is correct, but the self.load_8bit check should remain as it was to prevent using the unimplemented 8-bit MoE path.

if self.load_8bit:
    raise ValueError(
        "BitsAndBytes 8bit quantization with FusedMoE is not "
        "supported yet.")

Comment on lines 123 to +132
self.gate = ReplicatedLinear(config.hidden_size,
config.num_experts,
bias=False,
quant_config=None,
quant_config=self._maybe_ignore_quant_config(quant_config), # Some quantization methods do not quantize the gate
prefix=f"{prefix}.gate")

def _maybe_ignore_quant_config(self, quant_config: QuantizationConfig):
if not isinstance(quant_config, (BitsAndBytesConfig)):
return None
return quant_config
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This implementation for deciding whether to quantize the MoE gate has a couple of issues:

  1. Hardcoded Logic: It specifically checks for BitsAndBytesConfig, making it difficult to extend to other quantization methods that might also support gate quantization. This can lead to silent failures where a new quantization method is expected to quantize the gate but doesn't. A more extensible approach would be to have a method on the QuantizationConfig itself to indicate this capability.
  2. Incorrect Type Hint: The type hint for quant_config in _maybe_ignore_quant_config is QuantizationConfig, but it can be None at the call site.
  3. Clarity: The function name _maybe_ignore_quant_config is a bit ambiguous.
self.gate = ReplicatedLinear(config.hidden_size,
                                     config.num_experts,
                                     bias=False,
                                     quant_config=self._get_gate_quant_config(quant_config),
                                     prefix=f"{prefix}.gate")

    def _get_gate_quant_config(
        self, quant_config: Optional[QuantizationConfig]
    ) -> Optional[QuantizationConfig]:
        # The gate is only quantized for BitsAndBytes for now.
        if isinstance(quant_config, BitsAndBytesConfig):
            return quant_config
        return None

@jeejeelee jeejeelee self-assigned this Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
qwen Related to Qwen models
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants