[BugFix][v0.18.0] Gate recompute/balance/fused_mc2 by PD mode (#8374)

<!--  Thanks for sending a pull request!

BEFORE SUBMITTING, PLEASE READ
https://docs.vllm.ai/en/latest/contributing/overview.html

-->
### What this PR does / why we need it?
- Enforce recompute scheduler only in PD-disaggregated mode.
- Enforce balance scheduling only in PD-mixed mode.
- Enforce fused MC2 only on PD-disaggregated D-side (kv_consumer).
<!--
- Please clarify what changes you are proposing. The purpose of this
section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster
reviews in your PR.

- Please clarify why the changes are needed. For instance, the use case
and bug description.

- Fixes #
-->

### Does this PR introduce _any_ user-facing change?
No
<!--
Note that it means *any* user-facing change including all aspects such
as API, interface or other behavior changes.
Documentation-only updates are not considered user-facing changes.
-->

### How was this patch tested?
By ci
<!--
CI passed with new added/existing test.
If it was tested in a way different from regular unit tests, please
clarify how you tested step by step, ideally copy and paste-able, so
that other reviewers can test and check, and descendants can verify in
the future.
If tests were not added, please describe why they were not added and/or
why it was difficult to add.
-->

---------

Signed-off-by: wangxiaoteng <wangxiaoteng@huawei.com>
This commit is contained in:
wangxiaoteng888
2026-04-18 18:06:42 +08:00
committed by GitHub
parent c995a959e6
commit 363febb6cb
5 changed files with 288 additions and 3 deletions

View File

@@ -418,6 +418,257 @@ class TestNPUPlatform(TestBase):
self.assertEqual(vllm_config.cache_config.block_size, 128)
@patch("vllm_ascend.quantization.utils.maybe_auto_detect_quantization")
@patch("vllm_ascend.utils.get_ascend_device_type", return_value=AscendDeviceType.A3)
@patch("vllm_ascend.ascend_config.init_ascend_config")
@patch("vllm_ascend.core.recompute_scheduler.RecomputeSchedulerConfig.initialize_from_config")
def test_check_and_update_config_recompute_scheduler_rejects_pd_mixed_no_kv_transfer(
self, mock_init_recompute, mock_init_ascend, mock_soc_version, mock_auto_detect
):
mock_ascend_config = TestNPUPlatform.mock_vllm_ascend_config()
mock_ascend_config.recompute_scheduler_enable = True
mock_init_ascend.return_value = mock_ascend_config
vllm_config = TestNPUPlatform.mock_vllm_config()
vllm_config.kv_transfer_config = None
vllm_config.parallel_config.decode_context_parallel_size = 1
vllm_config.parallel_config.prefill_context_parallel_size = 1
vllm_config.parallel_config.tensor_parallel_size = 1
vllm_config.scheduler_config = MagicMock()
mock_init_recompute.return_value = MagicMock()
from vllm_ascend import platform
importlib.reload(platform)
self.platform = platform.NPUPlatform()
with pytest.raises(ValueError, match=r"recompute_scheduler_enable.*PD-disaggregated.*PD-mixed"):
with patch.object(platform.NPUPlatform, "_fix_incompatible_config"):
self.platform.check_and_update_config(vllm_config)
@patch("vllm_ascend.quantization.utils.maybe_auto_detect_quantization")
@patch("vllm_ascend.utils.get_ascend_device_type", return_value=AscendDeviceType.A3)
@patch("vllm_ascend.ascend_config.init_ascend_config")
@patch("vllm_ascend.core.recompute_scheduler.RecomputeSchedulerConfig.initialize_from_config")
def test_check_and_update_config_recompute_scheduler_rejects_pd_mixed_kv_both(
self, mock_init_recompute, mock_init_ascend, mock_soc_version, mock_auto_detect
):
mock_ascend_config = TestNPUPlatform.mock_vllm_ascend_config()
mock_ascend_config.recompute_scheduler_enable = True
mock_init_ascend.return_value = mock_ascend_config
vllm_config = TestNPUPlatform.mock_vllm_config()
vllm_config.kv_transfer_config = MagicMock(kv_role="kv_both", engine_id="engine0")
vllm_config.parallel_config.decode_context_parallel_size = 1
vllm_config.parallel_config.prefill_context_parallel_size = 1
vllm_config.parallel_config.tensor_parallel_size = 1
vllm_config.scheduler_config = MagicMock()
mock_init_recompute.return_value = MagicMock()
from vllm_ascend import platform
importlib.reload(platform)
self.platform = platform.NPUPlatform()
with pytest.raises(ValueError, match=r"recompute_scheduler_enable.*PD-disaggregated.*PD-mixed"):
with (
patch.object(platform.NPUPlatform, "_fix_incompatible_config"),
patch.object(platform, "check_kv_extra_config"),
):
self.platform.check_and_update_config(vllm_config)
@patch("vllm_ascend.quantization.utils.maybe_auto_detect_quantization")
@patch("vllm_ascend.utils.get_ascend_device_type", return_value=AscendDeviceType.A3)
@patch("vllm_ascend.ascend_config.init_ascend_config")
@patch("vllm_ascend.core.recompute_scheduler.RecomputeSchedulerConfig.initialize_from_config")
def test_check_and_update_config_balance_scheduler_rejects_pd_disaggregated_kv_producer(
self, mock_init_recompute, mock_init_ascend, mock_soc_version, mock_auto_detect
):
mock_ascend_config = TestNPUPlatform.mock_vllm_ascend_config()
mock_ascend_config.recompute_scheduler_enable = False
mock_init_ascend.return_value = mock_ascend_config
vllm_config = TestNPUPlatform.mock_vllm_config()
vllm_config.kv_transfer_config = MagicMock(kv_role="kv_producer", engine_id="engine0")
vllm_config.parallel_config.decode_context_parallel_size = 1
vllm_config.parallel_config.prefill_context_parallel_size = 1
vllm_config.parallel_config.tensor_parallel_size = 1
vllm_config.scheduler_config = MagicMock()
mock_init_recompute.return_value = MagicMock()
from vllm_ascend import platform
importlib.reload(platform)
self.platform = platform.NPUPlatform()
with patch("vllm_ascend.platform.envs_ascend.VLLM_ASCEND_BALANCE_SCHEDULING", True, create=True):
with pytest.raises(ValueError, match=r"VLLM_ASCEND_BALANCE_SCHEDULING.*PD-mixed.*PD-disaggregated"):
with (
patch.object(platform.NPUPlatform, "_fix_incompatible_config"),
patch.object(platform, "check_kv_extra_config"),
):
self.platform.check_and_update_config(vllm_config)
@patch("vllm_ascend.quantization.utils.maybe_auto_detect_quantization")
@patch("vllm_ascend.utils.get_ascend_device_type", return_value=AscendDeviceType.A3)
@patch("vllm_ascend.ascend_config.init_ascend_config")
@patch("vllm_ascend.core.recompute_scheduler.RecomputeSchedulerConfig.initialize_from_config")
def test_check_and_update_config_balance_scheduler_rejects_pd_disaggregated_kv_consumer(
self, mock_init_recompute, mock_init_ascend, mock_soc_version, mock_auto_detect
):
mock_ascend_config = TestNPUPlatform.mock_vllm_ascend_config()
mock_ascend_config.recompute_scheduler_enable = False
mock_init_ascend.return_value = mock_ascend_config
vllm_config = TestNPUPlatform.mock_vllm_config()
vllm_config.kv_transfer_config = MagicMock(kv_role="kv_consumer", engine_id="engine0")
vllm_config.parallel_config.decode_context_parallel_size = 1
vllm_config.parallel_config.prefill_context_parallel_size = 1
vllm_config.parallel_config.tensor_parallel_size = 1
vllm_config.scheduler_config = MagicMock()
mock_init_recompute.return_value = MagicMock()
from vllm_ascend import platform
importlib.reload(platform)
self.platform = platform.NPUPlatform()
with patch("vllm_ascend.platform.envs_ascend.VLLM_ASCEND_BALANCE_SCHEDULING", True, create=True):
with pytest.raises(ValueError, match=r"VLLM_ASCEND_BALANCE_SCHEDULING.*PD-mixed.*PD-disaggregated"):
with (
patch.object(platform.NPUPlatform, "_fix_incompatible_config"),
patch.object(platform, "check_kv_extra_config"),
):
self.platform.check_and_update_config(vllm_config)
@patch("vllm_ascend.quantization.utils.maybe_auto_detect_quantization")
@patch("vllm_ascend.utils.get_ascend_device_type", return_value=AscendDeviceType.A3)
@patch("vllm_ascend.ascend_config.init_ascend_config")
@patch("vllm_ascend.core.recompute_scheduler.RecomputeSchedulerConfig.initialize_from_config")
def test_check_and_update_config_fused_mc2_rejects_pd_mixed_no_kv_transfer(
self, mock_init_recompute, mock_init_ascend, mock_soc_version, mock_auto_detect
):
mock_ascend_config = TestNPUPlatform.mock_vllm_ascend_config()
mock_ascend_config.recompute_scheduler_enable = False
mock_ascend_config.enable_mc2_hierarchy_comm = False
mock_init_ascend.return_value = mock_ascend_config
vllm_config = TestNPUPlatform.mock_vllm_config()
vllm_config.kv_transfer_config = None
vllm_config.parallel_config.decode_context_parallel_size = 1
vllm_config.parallel_config.prefill_context_parallel_size = 1
vllm_config.parallel_config.tensor_parallel_size = 1
vllm_config.scheduler_config = MagicMock()
mock_init_recompute.return_value = MagicMock()
from vllm_ascend import platform
importlib.reload(platform)
self.platform = platform.NPUPlatform()
with patch("vllm_ascend.platform.envs_ascend.VLLM_ASCEND_ENABLE_FUSED_MC2", 1, create=True):
with pytest.raises(ValueError, match=r"VLLM_ASCEND_ENABLE_FUSED_MC2.*kv_role='kv_consumer'.*PD-mixed"):
with patch.object(platform.NPUPlatform, "_fix_incompatible_config"):
self.platform.check_and_update_config(vllm_config)
@patch("vllm_ascend.quantization.utils.maybe_auto_detect_quantization")
@patch("vllm_ascend.utils.get_ascend_device_type", return_value=AscendDeviceType.A3)
@patch("vllm_ascend.ascend_config.init_ascend_config")
@patch("vllm_ascend.core.recompute_scheduler.RecomputeSchedulerConfig.initialize_from_config")
def test_check_and_update_config_fused_mc2_rejects_pd_mixed_kv_both(
self, mock_init_recompute, mock_init_ascend, mock_soc_version, mock_auto_detect
):
mock_ascend_config = TestNPUPlatform.mock_vllm_ascend_config()
mock_ascend_config.recompute_scheduler_enable = False
mock_ascend_config.enable_mc2_hierarchy_comm = False
mock_init_ascend.return_value = mock_ascend_config
vllm_config = TestNPUPlatform.mock_vllm_config()
vllm_config.kv_transfer_config = MagicMock(kv_role="kv_both", engine_id="engine0")
vllm_config.parallel_config.decode_context_parallel_size = 1
vllm_config.parallel_config.prefill_context_parallel_size = 1
vllm_config.parallel_config.tensor_parallel_size = 1
vllm_config.scheduler_config = MagicMock()
mock_init_recompute.return_value = MagicMock()
from vllm_ascend import platform
importlib.reload(platform)
self.platform = platform.NPUPlatform()
with patch("vllm_ascend.platform.envs_ascend.VLLM_ASCEND_ENABLE_FUSED_MC2", 1, create=True):
with pytest.raises(ValueError, match=r"VLLM_ASCEND_ENABLE_FUSED_MC2.*kv_role='kv_consumer'.*kv_role='kv_both'"):
with (
patch.object(platform.NPUPlatform, "_fix_incompatible_config"),
patch.object(platform, "check_kv_extra_config"),
):
self.platform.check_and_update_config(vllm_config)
@patch("vllm_ascend.quantization.utils.maybe_auto_detect_quantization")
@patch("vllm_ascend.utils.get_ascend_device_type", return_value=AscendDeviceType.A3)
@patch("vllm_ascend.ascend_config.init_ascend_config")
@patch("vllm_ascend.core.recompute_scheduler.RecomputeSchedulerConfig.initialize_from_config")
def test_check_and_update_config_fused_mc2_rejects_pd_disaggregated_kv_producer(
self, mock_init_recompute, mock_init_ascend, mock_soc_version, mock_auto_detect
):
mock_ascend_config = TestNPUPlatform.mock_vllm_ascend_config()
mock_ascend_config.recompute_scheduler_enable = False
mock_ascend_config.enable_mc2_hierarchy_comm = False
mock_init_ascend.return_value = mock_ascend_config
vllm_config = TestNPUPlatform.mock_vllm_config()
vllm_config.kv_transfer_config = MagicMock(kv_role="kv_producer", engine_id="engine0")
vllm_config.parallel_config.decode_context_parallel_size = 1
vllm_config.parallel_config.prefill_context_parallel_size = 1
vllm_config.parallel_config.tensor_parallel_size = 1
vllm_config.scheduler_config = MagicMock()
mock_init_recompute.return_value = MagicMock()
from vllm_ascend import platform
importlib.reload(platform)
self.platform = platform.NPUPlatform()
with patch("vllm_ascend.platform.envs_ascend.VLLM_ASCEND_ENABLE_FUSED_MC2", 1, create=True):
with pytest.raises(ValueError, match=r"VLLM_ASCEND_ENABLE_FUSED_MC2.*kv_role='kv_consumer'.*kv_role='kv_producer'"):
with (
patch.object(platform.NPUPlatform, "_fix_incompatible_config"),
patch.object(platform, "check_kv_extra_config"),
):
self.platform.check_and_update_config(vllm_config)
@patch("vllm_ascend.quantization.utils.maybe_auto_detect_quantization")
@patch("vllm_ascend.utils.get_ascend_device_type", return_value=AscendDeviceType.A3)
@patch("vllm_ascend.ascend_config.init_ascend_config")
@patch("vllm_ascend.core.recompute_scheduler.RecomputeSchedulerConfig.initialize_from_config")
def test_check_and_update_config_fused_mc2_allows_pd_disaggregated_kv_consumer(
self, mock_init_recompute, mock_init_ascend, mock_soc_version, mock_auto_detect
):
mock_ascend_config = TestNPUPlatform.mock_vllm_ascend_config()
mock_ascend_config.recompute_scheduler_enable = False
mock_ascend_config.enable_mc2_hierarchy_comm = False
mock_init_ascend.return_value = mock_ascend_config
vllm_config = TestNPUPlatform.mock_vllm_config()
vllm_config.kv_transfer_config = MagicMock(kv_role="kv_consumer", engine_id="engine0")
vllm_config.parallel_config.decode_context_parallel_size = 1
vllm_config.parallel_config.prefill_context_parallel_size = 1
vllm_config.parallel_config.tensor_parallel_size = 1
vllm_config.scheduler_config = MagicMock()
mock_init_recompute.return_value = MagicMock()
from vllm_ascend import platform
importlib.reload(platform)
self.platform = platform.NPUPlatform()
with patch("vllm_ascend.platform.envs_ascend.VLLM_ASCEND_ENABLE_FUSED_MC2", 1, create=True):
with (
patch.object(platform.NPUPlatform, "_fix_incompatible_config"),
patch.object(platform, "check_kv_extra_config"),
):
self.platform.check_and_update_config(vllm_config)
def test_update_block_size_for_backend_preserves_hybrid_block_size(self):
vllm_config = TestNPUPlatform.mock_vllm_config()
vllm_config.model_config.is_hybrid = True