Add DCP to runtime parallel context (#30478)

This commit is contained in:
Baizhou Zhang
2026-07-10 21:23:41 -07:00
committed by GitHub
parent bbcfcaeefe
commit 07165d5daa
16 changed files with 167 additions and 105 deletions
@@ -7,10 +7,10 @@ which gives one import, one naming scheme, and the scoped ``override()``
test primitive. Direct calls to the ``parallel_state`` size/rank getters in
these directories are regressions against that sweep.
Exemptions, pinned by path: ``layers/dp_attention.py`` is delegation
substrate (the wrapper's attn-DP dims delegate TO it), and ``layers/dcp/``
is the DCP subsystem's own plumbing, booked for a follow-up sweep. Sweeping
an exempt path must remove it from the pin.
Exemptions, pinned by path: ``runtime_context.py`` and
``layers/dp_attention.py`` are delegation substrate, while
``layers/dcp/comm.py`` retains deprecated DCP compatibility shims for
out-of-tree callers. Sweeping an exempt path must remove it from the pin.
"""
from sglang.test.ci.ci_register import register_cpu_ci
@@ -27,7 +27,7 @@ from sglang.test.test_utils import CustomTestCase
_SRT_ROOT = Path(next(iter(sglang.srt.__path__)))
_BANNED_CALLS = re.compile(
r"\bget_(?:"
r"\b(?:dcp_enabled|get_(?:"
r"tensor_model_parallel_(?:world_size|rank)"
r"|pipeline_model_parallel_(?:world_size|rank)"
r"|moe_expert_parallel_(?:world_size|rank)"
@@ -36,8 +36,10 @@ _BANNED_CALLS = re.compile(
r"|attn_tensor_model_parallel_(?:world_size|rank)"
r"|attn_context_model_parallel_(?:world_size|rank)"
r"|dcp_(?:world_size|rank)"
r"|dcp_group(?:_no_assert)?"
r"|attention_dcp_(?:world_size|rank)"
r"|attention_(?:tp|cp)_(?:group|rank|size)"
r")\(\)"
r"))\(\)"
)
# The whole package is swept; the exemptions are the substrate itself.
@@ -45,7 +47,9 @@ _SWEPT_DIRS = ("",)
_EXEMPT = (
"distributed/", # parallel_state: defines the canonical getters
"runtime_context.py", # delegates DCP reads to canonical getters
"layers/dp_attention.py", # delegation substrate for the attn-DP dims
"layers/dcp/comm.py", # deprecated out-of-tree DCP compatibility shims
# The dumper's megatron plugin calls third-party getters that share the
# parallel_state names (self._mpu.get_tensor_model_parallel_rank()).
"debug_utils/dumper.py",
@@ -32,6 +32,8 @@ SIZE_RANK_DELEGATIONS = [
("world_rank", f"{_PS}.get_world_rank"),
("tp_size", f"{_PS}.get_tensor_model_parallel_world_size"),
("tp_rank", f"{_PS}.get_tensor_model_parallel_rank"),
("dcp_size", f"{_PS}.get_dcp_world_size"),
("dcp_rank", f"{_PS}.get_dcp_rank"),
("pp_size", f"{_PS}.get_pipeline_model_parallel_world_size"),
("pp_rank", f"{_PS}.get_pipeline_model_parallel_rank"),
("moe_ep_size", f"{_PS}.get_moe_expert_parallel_world_size"),
@@ -51,6 +53,7 @@ SIZE_RANK_DELEGATIONS = [
GROUP_DELEGATIONS = [
("world_group", f"{_PS}.get_world_group"),
("tp_group", f"{_PS}.get_tp_group"),
("dcp_group", f"{_PS}.get_dcp_group"),
("pp_group", f"{_PS}.get_pp_group"),
("moe_ep_group", f"{_PS}.get_moe_ep_group"),
("moe_dp_group", f"{_PS}.get_moe_dp_group"),
@@ -151,6 +154,40 @@ class TestParallelOverride(_IsolatedOverrides):
self.assertEqual(p._overrides, {})
class TestParallelDCP(_IsolatedOverrides):
def test_attn_dcp_defaults_when_group_is_uninitialized(self):
with (
patch(f"{_PS}.get_dcp_group_no_assert", return_value=None),
patch(f"{_PS}.get_dcp_world_size", side_effect=AssertionError),
patch(f"{_PS}.get_dcp_rank", side_effect=AssertionError),
):
self.assertFalse(get_parallel().dcp_enabled)
self.assertEqual(get_parallel().attn_dcp_size, 1)
self.assertEqual(get_parallel().attn_dcp_rank, 0)
def test_attn_dcp_delegates_when_enabled(self):
with (
patch(f"{_PS}.get_dcp_group_no_assert", return_value=object()),
patch(f"{_PS}.get_dcp_world_size", return_value=8),
patch(f"{_PS}.get_dcp_rank", return_value=3),
):
self.assertTrue(get_parallel().dcp_enabled)
self.assertEqual(get_parallel().attn_dcp_size, 8)
self.assertEqual(get_parallel().attn_dcp_rank, 3)
def test_dcp_enablement_is_platform_agnostic(self):
with (
patch(f"{_PS}.get_dcp_group_no_assert", return_value=object()),
patch("sglang.srt.utils.is_cuda", return_value=False) as is_cuda,
patch(f"{_PS}.get_dcp_world_size", return_value=8),
patch(f"{_PS}.get_dcp_rank", return_value=3),
):
self.assertTrue(get_parallel().dcp_enabled)
self.assertEqual(get_parallel().attn_dcp_size, 8)
self.assertEqual(get_parallel().attn_dcp_rank, 3)
is_cuda.assert_not_called()
class _IsolatedServerArgs(CustomTestCase):
"""Save/restore the published ServerArgs around each test (the slot is
process-global; another test file sharing the process may have published)."""