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
Merged
ShangmingCai
merged 3 commits into
sgl-project:main
from
nvpohanh:codex/mooncake-efa-allocator-validation
Sep 22, 2026
Merged
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
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
103 changes: 103 additions & 0 deletions
103
test/registered/unit/disaggregation/test_mooncake_efa_allocator.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,103 @@ | ||
| import unittest | ||
| from types import SimpleNamespace | ||
| from unittest.mock import patch | ||
|
|
||
| from sglang.srt.arg_groups.overrides import post_capture_kv_sizing_planned | ||
| from sglang.srt.disaggregation.mooncake.utils import ( | ||
| _validate_efa_allocator_compatibility, | ||
| 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), | ||
| ), | ||
| ): | ||
| result = check_mooncake_custom_mem_pool_enabled() | ||
| _validate_efa_allocator_compatibility(*result) | ||
| return result | ||
|
|
||
| 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"): | ||
| 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_allows_intra_node_nvlink(self): | ||
| self.assertEqual( | ||
| self._check("efa", custom_mem_pool="INTRA_NODE_NVLINK"), | ||
| (True, "INTRA_NODE_NVLINK"), | ||
| ) | ||
|
|
||
| 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")) | ||
|
|
||
| def test_efa_disables_post_capture_kv_sizing(self): | ||
| cfg = SimpleNamespace( | ||
| enable_unified_memory=False, | ||
| device="cuda", | ||
| dcp_size=1, | ||
| kv_cache_dtype="auto", | ||
| prefill_only_disable_kv_cache=False, | ||
| enable_memory_saver=False, | ||
| disaggregation_transfer_backend="mooncake", | ||
| ) | ||
| with ( | ||
| patch("sglang.srt.arg_groups.overrides.resolving_view", return_value=cfg), | ||
| patch( | ||
| "sglang.srt.arg_groups.overrides.use_mla_backend", return_value=False | ||
| ), | ||
| patch.object( | ||
| envs.SGLANG_ENABLE_POST_CAPTURE_KV_SIZING, "get", return_value=True | ||
| ), | ||
| patch.object( | ||
| envs.SGLANG_MOONCAKE_CUSTOM_MEM_POOL, "get", return_value=None | ||
| ), | ||
| patch.object(envs.MOONCAKE_PROTOCOL, "get", return_value="efa"), | ||
| ): | ||
| self.assertFalse(post_capture_kv_sizing_planned(object())) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.
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.