Repository navigation
[ROCm] Enable MXFP4 LoRA support on MI355X and add CDNA4 device IDs #37268
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
ChuanLi1101
wants to merge
1
commit into
vllm-project:main
Choose a base branch
from
ChuanLi1101:feat/rocm-mxfp4-lora-mi355x
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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,132 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| """Tests for MXFP4 backend selection on ROCm platforms.""" | ||
|
|
||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from vllm.model_executor.layers.fused_moe.oracle.mxfp4 import ( | ||
| Mxfp4MoeBackend, | ||
| select_mxfp4_moe_backend, | ||
| ) | ||
|
|
||
|
|
||
| def _make_lora_config(): | ||
| """Create a mock FusedMoEConfig with LoRA enabled.""" | ||
| config = MagicMock() | ||
| config.is_lora_enabled = True | ||
| config.moe_backend = "auto" | ||
| config.moe_parallel_config.use_batched_activation_format = False | ||
| return config | ||
|
|
||
|
|
||
| def _make_non_lora_config(): | ||
| """Create a mock FusedMoEConfig with LoRA disabled.""" | ||
| config = MagicMock() | ||
| config.is_lora_enabled = False | ||
| config.moe_backend = "auto" | ||
| config.moe_parallel_config.use_batched_activation_format = False | ||
| return config | ||
|
|
||
|
|
||
| class TestMxfp4LoraBackendROCm: | ||
| """Test MXFP4 backend selection for LoRA on ROCm platforms.""" | ||
|
|
||
| @patch( | ||
| "vllm.model_executor.layers.fused_moe.oracle.mxfp4.current_platform" | ||
| ) | ||
| @patch( | ||
| "vllm.model_executor.layers.fused_moe.oracle.mxfp4.has_triton_kernels" | ||
| ) | ||
| def test_rocm_lora_with_triton_kernels( | ||
| self, mock_has_triton, mock_platform | ||
| ): | ||
| mock_platform.is_rocm.return_value = True | ||
| mock_platform.is_cuda.return_value = False | ||
| mock_platform.get_device_capability.return_value = (9, 5) | ||
| mock_has_triton.return_value = True | ||
|
|
||
| config = _make_lora_config() | ||
| backend, experts_cls = select_mxfp4_moe_backend(config) | ||
| assert backend == Mxfp4MoeBackend.TRITON_UNFUSED | ||
|
|
||
| @patch( | ||
| "vllm.model_executor.layers.fused_moe.oracle.mxfp4.current_platform" | ||
| ) | ||
| @patch( | ||
| "vllm.model_executor.layers.fused_moe.oracle.mxfp4.has_triton_kernels" | ||
| ) | ||
| def test_rocm_lora_without_triton_raises( | ||
| self, mock_has_triton, mock_platform | ||
| ): | ||
| mock_platform.is_rocm.return_value = True | ||
| mock_platform.is_cuda.return_value = False | ||
| mock_platform.get_device_capability.return_value = (9, 5) | ||
| mock_has_triton.return_value = False | ||
|
|
||
| config = _make_lora_config() | ||
| with pytest.raises(NotImplementedError, match="triton_kernels"): | ||
| select_mxfp4_moe_backend(config) | ||
|
|
||
| @patch( | ||
| "vllm.model_executor.layers.fused_moe.oracle.mxfp4.current_platform" | ||
| ) | ||
| @patch( | ||
| "vllm.model_executor.layers.fused_moe.oracle.mxfp4.has_triton_kernels" | ||
| ) | ||
| def test_non_cuda_non_rocm_lora_raises( | ||
| self, mock_has_triton, mock_platform | ||
| ): | ||
| mock_platform.is_rocm.return_value = False | ||
| mock_platform.is_cuda.return_value = False | ||
| mock_platform.get_device_capability.return_value = (0, 0) | ||
| mock_has_triton.return_value = False | ||
|
|
||
| config = _make_lora_config() | ||
| with pytest.raises( | ||
| NotImplementedError, match="only supported on CUDA and ROCm" | ||
| ): | ||
| select_mxfp4_moe_backend(config) | ||
|
|
||
|
|
||
| class TestROCmDeviceIdNameMap: | ||
| """Test that MI350X/MI355X device IDs are properly mapped.""" | ||
|
|
||
| def test_mi350x_device_id(self): | ||
| from vllm.platforms.rocm import _ROCM_DEVICE_ID_NAME_MAP | ||
|
|
||
| assert "0x75a0" in _ROCM_DEVICE_ID_NAME_MAP | ||
| assert _ROCM_DEVICE_ID_NAME_MAP["0x75a0"] == "AMD_Instinct_MI350X" | ||
|
|
||
| def test_mi355x_device_id(self): | ||
| from vllm.platforms.rocm import _ROCM_DEVICE_ID_NAME_MAP | ||
|
|
||
| assert "0x75a3" in _ROCM_DEVICE_ID_NAME_MAP | ||
| assert _ROCM_DEVICE_ID_NAME_MAP["0x75a3"] == "AMD_Instinct_MI355X" | ||
|
|
||
| def test_existing_mi300x_unchanged(self): | ||
| from vllm.platforms.rocm import _ROCM_DEVICE_ID_NAME_MAP | ||
|
|
||
| assert _ROCM_DEVICE_ID_NAME_MAP["0x74a1"] == "AMD_Instinct_MI300X" | ||
|
|
||
| def test_existing_mi325x_unchanged(self): | ||
| from vllm.platforms.rocm import _ROCM_DEVICE_ID_NAME_MAP | ||
|
|
||
| assert _ROCM_DEVICE_ID_NAME_MAP["0x74a5"] == "AMD_Instinct_MI325X" | ||
|
|
||
|
|
||
| class TestGfx950CapabilityParsing: | ||
| """Test that gfx950 arch string is correctly parsed.""" | ||
|
|
||
| def test_gfx950_capability(self): | ||
| from vllm.platforms.rocm import _capability_from_gcn_arch | ||
|
|
||
| result = _capability_from_gcn_arch("gfx950") | ||
| assert result == (9, 5) | ||
|
|
||
| def test_gfx942_capability(self): | ||
| from vllm.platforms.rocm import _capability_from_gcn_arch | ||
|
|
||
| result = _capability_from_gcn_arch("gfx942") | ||
| assert result == (9, 4) | ||
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.
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.
What is the purpose of this test? I don't see any mxfp4 testing here with lora. There should be accuracy tests here. But also mxfp4 test for ROCm should include a much broader set of tests, which I think is out of the scope of this PR. So probably best if you find the lora or quantization test file that fits best this new feature and add an accuracy test there instead of this new file.