-
-
Notifications
You must be signed in to change notification settings - Fork 20.1k
[Quant][Feature] Support online MXFP8 quantization for MoE and dense models #35448
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5e1a1b2
Add online MXFP8 quantization support for MoE and dense models
EdalatiAli b4d2682
Merge branch 'main' into fi-moe-mxfp8
EdalatiAli 58f12b8
Merge branch 'main' into fi-moe-mxfp8
EdalatiAli 6b532f1
Merge branch 'main' into fi-moe-mxfp8
EdalatiAli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| """E2E tests for online MXFP8 quantization. | ||
|
|
||
| Loads a BF16 model with ``--quantization mxfp8`` (online quantization) and | ||
| compares log-probabilities against the same model served in BF16 without | ||
| quantization. This exercises the full pipeline: config parsing, | ||
| ``Mxfp8OnlineLinearMethod``, ``Mxfp8OnlineMoEMethod``, weight loading, | ||
| online quantization / shuffling, and inference through ``apply_monolithic``. | ||
|
|
||
| Layer skipping (``modules_to_not_convert``) is configured in the model's | ||
| ``config.json`` under ``quantization_config`` and is not tested here. | ||
|
|
||
| ``example_prompts`` is a pytest fixture (from conftest.py) that loads 8 | ||
| diverse prompts from ``tests/prompts/example.txt``. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.quantization.utils import is_quant_method_supported | ||
|
|
||
| from ..utils import check_logprobs_close | ||
|
|
||
| # A small MoE model that fits on a single GPU and has both linear + MoE layers. | ||
| MOE_MODEL = "Qwen/Qwen3-30B-A3B" | ||
| # A small dense model (no MoE) to validate the linear-only path. | ||
| DENSE_MODEL = "Qwen/Qwen3-0.6B" | ||
|
|
||
| MAX_MODEL_LEN = 1024 | ||
| MAX_TOKENS = 4 | ||
| NUM_LOG_PROBS = 8 | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| not is_quant_method_supported("mxfp8"), | ||
| reason="mxfp8 is not supported on this GPU type (requires sm_100+).", | ||
| ) | ||
| @pytest.mark.quant_model | ||
| @pytest.mark.parametrize("model", [DENSE_MODEL, MOE_MODEL], ids=["dense", "moe"]) | ||
| def test_mxfp8_logprobs( | ||
| vllm_runner, | ||
| example_prompts, | ||
| model: str, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ) -> None: | ||
| """Compare BF16 baseline logprobs against online MXFP8-quantized model. | ||
|
|
||
| Runs the same model twice -- once in BF16 (baseline) and once with | ||
| online MXFP8 quantization -- then checks that the top log-probabilities | ||
| are close. Only 4 tokens are generated to keep the test fast while | ||
| still catching numerical divergence. | ||
| """ | ||
| with monkeypatch.context() as m: | ||
| m.setenv("TOKENIZERS_PARALLELISM", "true") | ||
|
|
||
| with vllm_runner( | ||
| model, | ||
| max_model_len=MAX_MODEL_LEN, | ||
| enforce_eager=True, | ||
| ) as vllm_model: | ||
| baseline_outputs = vllm_model.generate_greedy_logprobs( | ||
| example_prompts, MAX_TOKENS, NUM_LOG_PROBS | ||
| ) | ||
|
|
||
| with vllm_runner( | ||
| model, | ||
| max_model_len=MAX_MODEL_LEN, | ||
| enforce_eager=True, | ||
| quantization="mxfp8", | ||
| ) as vllm_model: | ||
| test_outputs = vllm_model.generate_greedy_logprobs( | ||
| example_prompts, MAX_TOKENS, NUM_LOG_PROBS | ||
| ) | ||
|
|
||
| check_logprobs_close( | ||
| outputs_0_lst=baseline_outputs, | ||
| outputs_1_lst=test_outputs, | ||
| name_0="bf16", | ||
| name_1="mxfp8", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| not is_quant_method_supported("mxfp8"), | ||
| reason="mxfp8 is not supported on this GPU type (requires sm_100+).", | ||
| ) | ||
| @pytest.mark.quant_model | ||
| @pytest.mark.parametrize("model", [DENSE_MODEL, MOE_MODEL], ids=["dense", "moe"]) | ||
| def test_mxfp8_generation(vllm_runner, model: str) -> None: | ||
| """Smoke test: verify online MXFP8 model generates coherent text.""" | ||
| prompt = "1 2 3 4 5" | ||
| with vllm_runner( | ||
| model, | ||
| enforce_eager=True, | ||
| quantization="mxfp8", | ||
| max_model_len=MAX_MODEL_LEN, | ||
| ) as vllm_model: | ||
| output = vllm_model.generate_greedy([prompt], max_tokens=5) | ||
|
|
||
| generated = output[0][1] | ||
| assert len(generated) > len(prompt), ( | ||
| f"MXFP8 model produced no new tokens. Output: {generated!r}" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like you assert SILU but don't restrict selection in
_supports_activation, is this necessary?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's necessary — the monolithic class serves both block-scale (SILU only, hardcoded in flashinfer) and per-tensor (SILU + RELU2) paths, and _supports_activation can't distinguish them. Adding quant context to _supports_activation would require changing the abstract interface and every implementation across the codebase.