Repository navigation
[Bugfix][Quantization] Fix MXFP8 startup crash on layers below mm_mxfp8 shape limits #54223
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
mgoin
merged 7 commits into
vllm-project:main
from
samuelkim7:mxfp8-can-implement-shape
Sep 25, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
137a0f8
[Bugfix][Quantization] Fix MXFP8 startup crash on layers below mm_mxf…
samuelkim7 620fae7
Check SM12x N alignment and Marlin MXFP8 shapes in can_implement
samuelkim7 82af45b
Simplify MXFP8 kernel shape validation and selection tests
mgoin 0311805
Merge branch 'main' into mxfp8-can-implement-shape
mgoin 2994911
Fix remaining MXFP8 test configs missing weight shapes
mgoin 7a5e4bb
Merge branch 'main' into mxfp8-can-implement-shape
mgoin 23d5174
Merge branch 'main' into mxfp8-can-implement-shape
mgoin 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
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
135 changes: 135 additions & 0 deletions
135
tests/kernels/quantization/test_mxfp8_kernel_selection.py
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,135 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| """Tests for MXFP8 linear kernel selection logic (CPU-only) | ||
|
|
||
| Run `pytest tests/kernels/quantization/test_mxfp8_kernel_selection.py`. | ||
| """ | ||
|
|
||
| from contextlib import contextmanager | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
| from vllm.model_executor.kernels.linear import ( | ||
| FlashInferCutedslMxfp8LinearKernel, | ||
| FlashInferCutlassMxfp8LinearKernel, | ||
| MarlinMxfp8LinearKernel, | ||
| Mxfp8LinearLayerConfig, | ||
| init_mxfp8_linear_kernel, | ||
| ) | ||
| from vllm.platforms import PlatformEnum | ||
|
|
||
| pytestmark = pytest.mark.cpu_test | ||
|
|
||
| # Kernels backed by FlashInfer mm_mxfp8, which requires N, K >= 128 and | ||
| # K % 32 == 0. | ||
| _MM_MXFP8_KERNELS = [ | ||
| FlashInferCutedslMxfp8LinearKernel, | ||
| FlashInferCutlassMxfp8LinearKernel, | ||
| ] | ||
|
|
||
| _SUPPORTED_SHAPE = (4096, 4096) | ||
| # (N, K): N < 128, K < 128, K % 32 != 0. | ||
| _UNSUPPORTED_SHAPES = [(64, 4096), (4096, 64), (4096, 4112)] | ||
|
|
||
| # (N, K) with N < 128 or K < 128, which only Marlin runs. | ||
| _MARLIN_ONLY_SHAPES = [(32, 256), (64, 256), (96, 256), (256, 64)] | ||
| # (N, K): N <= 0, K <= 0, K % 32 != 0. | ||
| _MARLIN_UNSUPPORTED_SHAPES = [(0, 256), (256, 0), (256, 100)] | ||
|
|
||
| _SELECTION_CASES = [ | ||
| (100, (128, 128), FlashInferCutedslMxfp8LinearKernel), | ||
| (100, (130, 256), FlashInferCutedslMxfp8LinearKernel), | ||
| (103, (128, 128), FlashInferCutedslMxfp8LinearKernel), | ||
| (103, (130, 256), FlashInferCutedslMxfp8LinearKernel), | ||
| (120, (128, 128), FlashInferCutlassMxfp8LinearKernel), | ||
| (120, (130, 256), MarlinMxfp8LinearKernel), | ||
| (121, (128, 128), FlashInferCutlassMxfp8LinearKernel), | ||
| (121, (130, 256), MarlinMxfp8LinearKernel), | ||
| *[ | ||
| (capability, shape, MarlinMxfp8LinearKernel) | ||
| for capability in (100, 103, 120, 121) | ||
| for shape in _MARLIN_ONLY_SHAPES | ||
| ], | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("kernel_cls", _MM_MXFP8_KERNELS) | ||
| def test_mm_mxfp8_kernels_accept_supported_shape(kernel_cls): | ||
| config = Mxfp8LinearLayerConfig(weight_shape=_SUPPORTED_SHAPE) | ||
| can_implement, reason = kernel_cls.can_implement(config) | ||
| assert can_implement, reason | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("kernel_cls", _MM_MXFP8_KERNELS) | ||
| @pytest.mark.parametrize("weight_shape", _UNSUPPORTED_SHAPES) | ||
| def test_mm_mxfp8_kernels_reject_unsupported_shape(kernel_cls, weight_shape): | ||
| config = Mxfp8LinearLayerConfig(weight_shape=weight_shape) | ||
| can_implement, reason = kernel_cls.can_implement(config) | ||
| assert not can_implement | ||
| assert reason | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("weight_shape", _MARLIN_UNSUPPORTED_SHAPES) | ||
| def test_marlin_mxfp8_rejects_unsupported_shape(weight_shape): | ||
| config = Mxfp8LinearLayerConfig(weight_shape=weight_shape) | ||
| can_implement, reason = MarlinMxfp8LinearKernel.can_implement(config) | ||
| assert not can_implement | ||
| assert reason | ||
|
|
||
|
|
||
| @contextmanager | ||
| def _patch_cuda_platform(capability: int): | ||
| """Patch the platform so kernel selection runs as on a CUDA GPU with the | ||
| given compute capability. The FlashInfer and Marlin kernels report as | ||
| supported, CuTe-DSL only on SM100/103.""" | ||
| with ( | ||
| patch("vllm.model_executor.kernels.linear.current_platform") as platform, | ||
| patch( | ||
| "vllm.model_executor.kernels.linear.mxfp8.flashinfer.current_platform." | ||
| "is_device_capability_family", | ||
| side_effect=lambda cap, device_id=0: cap // 10 == capability // 10, | ||
| ), | ||
| patch.object( | ||
| FlashInferCutedslMxfp8LinearKernel, | ||
| "is_supported", | ||
| return_value=(capability in (100, 103), None), | ||
| ), | ||
| patch.object( | ||
| FlashInferCutlassMxfp8LinearKernel, | ||
| "is_supported", | ||
| return_value=(True, None), | ||
| ), | ||
| patch.object( | ||
| MarlinMxfp8LinearKernel, "is_supported", return_value=(True, None) | ||
| ), | ||
| ): | ||
| platform._enum = PlatformEnum.CUDA | ||
| yield | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("capability", "expected"), | ||
| [(100, True), (103, True), (120, False), (121, False)], | ||
| ) | ||
| def test_cutlass_mxfp8_requires_aligned_n_only_on_sm12x(capability, expected): | ||
| """(130, 256) passes the generic mm_mxfp8 limits. Only the SM12x CUTLASS | ||
| backend needs N % 32 == 0, so SM100/103 must keep accepting it.""" | ||
| config = Mxfp8LinearLayerConfig(weight_shape=(130, 256)) | ||
| with _patch_cuda_platform(capability): | ||
| can_implement, _ = FlashInferCutlassMxfp8LinearKernel.can_implement(config) | ||
| assert can_implement == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("capability", "weight_shape", "expected_kernel_cls"), _SELECTION_CASES | ||
| ) | ||
| def test_init_mxfp8_linear_kernel(capability, weight_shape, expected_kernel_cls): | ||
| """A layer that mm_mxfp8 cannot handle must fall through to the next | ||
| kernel in the CUDA priority list instead of being selected and failing | ||
| in apply_weights.""" | ||
| with _patch_cuda_platform(capability): | ||
| kernel = init_mxfp8_linear_kernel(weight_shape=weight_shape) | ||
|
|
||
| assert isinstance(kernel, expected_kernel_cls) | ||
| assert kernel.config == Mxfp8LinearLayerConfig(weight_shape=weight_shape) |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.