Repository navigation
[PD] Validate Mooncake EFA allocator compatibility #39973
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |||||
| """Mooncake-specific utilities for custom memory pool management.""" | ||||||
|
|
||||||
| import logging | ||||||
| import os | ||||||
| from typing import Any, Optional, Tuple | ||||||
|
|
||||||
| import torch | ||||||
|
|
@@ -26,6 +27,41 @@ | |||||
| SUPPORTED_MOONCAKE_CUSTOM_MEM_POOL_TYPES = ["NVLINK", "BAREX", "INTRA_NODE_NVLINK"] | ||||||
|
|
||||||
|
|
||||||
| def _cuda_expandable_segments_enabled() -> Optional[str]: | ||||||
| """Return the allocator env var that enables CUDA expandable segments.""" | ||||||
| for var in ("PYTORCH_CUDA_ALLOC_CONF", "PYTORCH_ALLOC_CONF"): | ||||||
| for field in os.environ.get(var, "").split(","): | ||||||
| key, _, value = field.partition(":") | ||||||
| if key.strip() == "expandable_segments" and value.strip().lower() == "true": | ||||||
| return var | ||||||
| return None | ||||||
|
|
||||||
|
|
||||||
| def _validate_efa_allocator_compatibility( | ||||||
| enable_custom_mem_pool: bool, custom_mem_pool_type: Optional[str] | ||||||
| ) -> None: | ||||||
| """Reject CUDA VMM allocators unsupported by the current libfabric EFA path.""" | ||||||
| if envs.MOONCAKE_PROTOCOL.get().lower() != "efa": | ||||||
| return | ||||||
|
|
||||||
| if enable_custom_mem_pool: | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We recommend that mode for A100/H20/H100 in Gate on the type instead:
Suggested change
and drop
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [by Codex] Addressed in f9b3372: EFA validation now rejects only NVLINK and BAREX, while INTRA_NODE_NVLINK remains allowed. The unit test and EFA documentation were updated accordingly. |
||||||
| raise ValueError( | ||||||
| f"SGLANG_MOONCAKE_CUSTOM_MEM_POOL={custom_mem_pool_type} is " | ||||||
| "incompatible with MOONCAKE_PROTOCOL=efa. Mooncake custom memory " | ||||||
| "pools use CUDA VMM allocations, which the current libfabric EFA " | ||||||
| "provider cannot transfer. Unset SGLANG_MOONCAKE_CUSTOM_MEM_POOL." | ||||||
| ) | ||||||
|
|
||||||
| expandable_segments_var = _cuda_expandable_segments_enabled() | ||||||
| if expandable_segments_var is not None: | ||||||
| raise ValueError( | ||||||
| f"{expandable_segments_var} enables expandable_segments, which is " | ||||||
| "incompatible with MOONCAKE_PROTOCOL=efa because the current " | ||||||
| "libfabric EFA provider cannot transfer CUDA VMM allocations. " | ||||||
| "Disable expandable_segments." | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def init_mooncake_custom_mem_pool( | ||||||
| device: str, | ||||||
| ) -> Tuple[bool, Optional[Any], Optional[str]]: | ||||||
|
|
@@ -109,4 +145,6 @@ def check_mooncake_custom_mem_pool_enabled() -> Tuple[bool, Optional[str]]: | |||||
| enable_custom_mem_pool = False | ||||||
| custom_mem_pool_type = None | ||||||
|
|
||||||
| _validate_efa_allocator_compatibility(enable_custom_mem_pool, custom_mem_pool_type) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only reaches the decode side when staging is on. So a default decode worker with Call it from somewhere both roles hit (
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [by Codex] Addressed in f9b3372: allocator compatibility validation now runs at the start of MooncakeKVManager.init, which is shared by both prefill and decode roles, before engine initialization and buffer registration. |
||||||
|
|
||||||
| return enable_custom_mem_pool, custom_mem_pool_type | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import unittest | ||
| from unittest.mock import patch | ||
|
|
||
| from sglang.srt.disaggregation.mooncake.utils import ( | ||
| check_mooncake_custom_mem_pool_enabled, | ||
| ) | ||
| from sglang.srt.environ import envs | ||
| from sglang.test.ci.ci_register import register_cpu_ci | ||
|
|
||
| register_cpu_ci(est_time=1, suite="base-a-test-cpu") | ||
|
|
||
|
|
||
| class TestMooncakeEfaAllocator(unittest.TestCase): | ||
| def _check(self, protocol, custom_mem_pool=None, allocator_env=None): | ||
| allocator_env = allocator_env or {} | ||
| with ( | ||
| patch.object(envs.MOONCAKE_PROTOCOL, "get", return_value=protocol), | ||
| patch.object( | ||
| envs.SGLANG_MOONCAKE_CUSTOM_MEM_POOL, | ||
| "get", | ||
| return_value=custom_mem_pool, | ||
| ), | ||
| patch( | ||
| "sglang.srt.disaggregation.mooncake.utils.os.environ.get", | ||
| side_effect=lambda key, default="": allocator_env.get(key, default), | ||
| ), | ||
| ): | ||
| return check_mooncake_custom_mem_pool_enabled() | ||
|
|
||
| def test_efa_uses_default_allocator(self): | ||
| self.assertEqual(self._check("efa"), (False, None)) | ||
|
|
||
| def test_efa_rejects_custom_memory_pools(self): | ||
| for pool_type in ("true", "NVLINK", "BAREX", "INTRA_NODE_NVLINK"): | ||
| with self.subTest(pool_type=pool_type): | ||
| with self.assertRaisesRegex( | ||
| ValueError, "incompatible with MOONCAKE_PROTOCOL=efa" | ||
| ): | ||
| self._check("efa", custom_mem_pool=pool_type) | ||
|
|
||
| def test_efa_rejects_expandable_segments(self): | ||
| for var in ("PYTORCH_CUDA_ALLOC_CONF", "PYTORCH_ALLOC_CONF"): | ||
| with self.subTest(var=var): | ||
| with self.assertRaisesRegex(ValueError, var): | ||
| self._check( | ||
| "efa", | ||
| allocator_env={ | ||
| var: "garbage_collection_threshold:0.8," | ||
| "expandable_segments:True" | ||
| }, | ||
| ) | ||
|
|
||
| def test_efa_allows_disabled_expandable_segments(self): | ||
| self.assertEqual( | ||
| self._check( | ||
| "EFA", | ||
| allocator_env={"PYTORCH_CUDA_ALLOC_CONF": "expandable_segments:False"}, | ||
| ), | ||
| (False, None), | ||
| ) | ||
|
|
||
| def test_non_efa_keeps_custom_memory_pool_behavior(self): | ||
| self.assertEqual(self._check("rdma", custom_mem_pool="true"), (True, "NVLINK")) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.
Third VMM source that slips through:
SGLANG_ENABLE_POST_CAPTURE_KV_SIZING=1backs the KV cache withKvVmmBufferOwner(memory_pool.py:2364, cuMemCreate/cuMemMap).post_capture_kv_sizing_plannedalready opts out whenSGLANG_MOONCAKE_CUSTOM_MEM_POOLis set (arg_groups/overrides.py:1822) but knows nothing aboutMOONCAKE_PROTOCOL, so EFA + post-capture sizing with neither flagged var set still registers VMM buffers and fails the same way.Either add a bullet here, or add the protocol check to
post_capture_kv_sizing_planned.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.
[by Codex] Addressed in f9b3372: post_capture_kv_sizing_planned now returns false for the Mooncake EFA backend, with unit-test coverage and documentation noting the automatic fallback.