From c1d754d681108096d8a125054f01a51afd60c618 Mon Sep 17 00:00:00 2001 From: Dao007forever Date: Tue, 9 Jun 2026 11:05:36 -0700 Subject: [PATCH] [Mooncake] Use all HCAs on multi-NIC hosts instead of GPU-indexed RNIC selection (#43799) Signed-off-by: Dao Le Co-authored-by: Claude Opus 4.7 (1M context) --- .../unit/test_mooncake_store_worker.py | 88 ------------------- .../kv_connector/v1/mooncake/rdma_utils.py | 69 --------------- .../kv_connector/v1/mooncake/store/worker.py | 8 +- 3 files changed, 2 insertions(+), 163 deletions(-) diff --git a/tests/v1/kv_connector/unit/test_mooncake_store_worker.py b/tests/v1/kv_connector/unit/test_mooncake_store_worker.py index d709d1f597..8cd5e6e535 100644 --- a/tests/v1/kv_connector/unit/test_mooncake_store_worker.py +++ b/tests/v1/kv_connector/unit/test_mooncake_store_worker.py @@ -283,94 +283,6 @@ def test_get_configured_preferred_segment_rejects_empty_override(): rdma_utils.get_configured_preferred_segment({"preferred_segment": " "}) -def test_get_configured_worker_rnic_prefers_explicit_device_name(monkeypatch): - store_config = worker.MooncakeStoreConfig( - metadata_server="", - local_buffer_size=1, - protocol="rdma", - device_name="rocep139s0", - master_server_address="", - ) - - assert ( - rdma_utils.get_configured_worker_rnic( - protocol=store_config.protocol, - configured_device=store_config.device_name, - ) - == "rocep139s0" - ) - - -def test_get_configured_worker_rnic_selects_device_from_explicit_csv(monkeypatch): - monkeypatch.setattr( - rdma_utils, - "get_current_physical_gpu_index", - lambda: 1, - ) - store_config = worker.MooncakeStoreConfig( - metadata_server="", - local_buffer_size=1, - protocol="rdma", - device_name="rocep139s0,rocep140s0", - master_server_address="", - ) - - assert ( - rdma_utils.get_configured_worker_rnic( - protocol=store_config.protocol, - configured_device=store_config.device_name, - ) - == "rocep140s0" - ) - - -def test_get_configured_worker_rnic_warns_and_returns_empty_for_rdma_with_no_device( - caplog, monkeypatch -): - """No device configured + protocol=rdma → emit a clear warning and return "" - so the C++ side handles auto-selection. There is no Python-side fallback.""" - monkeypatch.setattr(logging.getLogger("vllm"), "propagate", True) - with caplog.at_level(logging.WARNING): - result = rdma_utils.get_configured_worker_rnic( - protocol="rdma", - configured_device="", - ) - assert result == "" - warnings = [r for r in caplog.records if r.levelno == logging.WARNING] - assert any("No RDMA devices specified" in r.message for r in warnings), ( - f"expected fallback warning, got {[r.message for r in warnings]}" - ) - - -def test_get_configured_worker_rnic_silent_for_tcp_with_no_device(caplog, monkeypatch): - """protocol=tcp + no device → return "" silently (no RDMA, no warning).""" - monkeypatch.setattr(logging.getLogger("vllm"), "propagate", True) - with caplog.at_level(logging.WARNING): - result = rdma_utils.get_configured_worker_rnic( - protocol="tcp", - configured_device="", - ) - assert result == "" - warnings = [r for r in caplog.records if r.levelno == logging.WARNING] - assert not any("RDMA" in r.message for r in warnings), ( - "did not expect RDMA warning for tcp protocol, got " - f"{[r.message for r in warnings]}" - ) - - -def test_get_configured_worker_rnic_rejects_short_explicit_csv(monkeypatch): - monkeypatch.setattr( - rdma_utils, - "get_current_physical_gpu_index", - lambda: 2, - ) - with pytest.raises(ValueError, match="does not cover local GPU 2"): - rdma_utils.get_configured_worker_rnic( - protocol="rdma", - configured_device="rocep139s0,rocep140s0", - ) - - class _ReplicaDesc: def __init__(self, tier: str): self.tier = tier diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/rdma_utils.py b/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/rdma_utils.py index 9ee0d2cc54..34e62ef536 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/rdma_utils.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/rdma_utils.py @@ -5,8 +5,6 @@ from collections.abc import Mapping from typing import Any -import torch - import vllm.envs as envs from vllm.logger import init_logger @@ -20,22 +18,6 @@ def normalize_string_override(value: Any) -> str | None: return normalized or None -def get_current_physical_gpu_index() -> int | None: - try: - from vllm.platforms import current_platform - except ImportError: - return None - - try: - device_index = torch.accelerator.current_device_index() - physical_device_id = current_platform.device_id_to_physical_device_id( - device_index - ) - return int(physical_device_id) - except Exception: - return None - - def get_requester_local_hostname(local_ip: str) -> str: override = normalize_string_override(envs.MOONCAKE_REQUESTER_LOCAL_HOSTNAME) if override is not None: @@ -62,54 +44,3 @@ def get_configured_preferred_segment( ) return env_value return None - - -def _get_explicit_worker_rnic(device_list: str) -> str: - entries = [entry.strip() for entry in device_list.split(",")] - if any(not entry for entry in entries): - raise ValueError( - "Mooncake worker device_name contains an empty RDMA device entry" - ) - if len(entries) == 1: - return entries[0] - - gpu_index = get_current_physical_gpu_index() - if gpu_index is None: - raise RuntimeError( - "Mooncake RDMA requester could not determine the local physical GPU index" - ) - if gpu_index >= len(entries): - raise ValueError( - "Mooncake worker device list does not cover local GPU " - f"{gpu_index}: {device_list}" - ) - device_name = entries[gpu_index] - logger.info( - "Mooncake selected worker RNIC %s from explicit device list for local GPU %s", - device_name, - gpu_index, - ) - return device_name - - -def get_configured_worker_rnic( - *, - protocol: str, - configured_device: str, -) -> str: - normalized_device = normalize_string_override(configured_device) - if normalized_device is not None: - return _get_explicit_worker_rnic(normalized_device) - - if protocol not in {"rdma", "efa"}: - return "" - - logger.warning( - "No RDMA devices specified for Mooncake backend (protocol=%s). " - "Set 'device_name' in mooncake_config.json to a single RNIC name " - "or a comma-separated CSV indexed by physical GPU; falling back to " - "Mooncake's built-in auto-selection, which may converge on the same " - "NIC across all DP ranks and saturate bandwidth.", - protocol, - ) - return "" diff --git a/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/worker.py b/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/worker.py index b3a40d8b45..18cae18ee9 100644 --- a/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/worker.py +++ b/vllm/distributed/kv_transfer/kv_connector/v1/mooncake/store/worker.py @@ -141,7 +141,7 @@ class MooncakeStoreConfig: ) @staticmethod - def load_from_env() -> "MooncakeStoreConfig": + def load_from_config() -> "MooncakeStoreConfig": config_path = os.getenv("MOONCAKE_CONFIG_PATH") if not config_path: raise ValueError( @@ -983,16 +983,12 @@ class MooncakeStoreWorker: ) # Initialize MooncakeDistributedStore with its own TransferEngine - store_config = MooncakeStoreConfig.load_from_env() + store_config = MooncakeStoreConfig.load_from_config() extra_config = ( vllm_config.kv_transfer_config.kv_connector_extra_config if vllm_config.kv_transfer_config else {} ) - store_config.device_name = rdma_utils.get_configured_worker_rnic( - protocol=store_config.protocol, - configured_device=store_config.device_name, - ) self.store = MooncakeDistributedStore() local_ip = get_ip() local_hostname = rdma_utils.get_requester_local_hostname(local_ip)