config: a parallel leaf with no live counterpart is read bare (#36620)

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Cheng Wan
2026-08-27 12:56:11 -07:00
committed by GitHub
co-authored by Claude Opus 5
parent 7c3b5a6732
commit ca1d7ed8e6
125 changed files with 343 additions and 405 deletions
@@ -158,16 +158,8 @@ class TestCPReplicatedStateTransfer(unittest.TestCase):
manager = object.__new__(CommonKVManager)
manager.attn_cp_size = cp_size
manager.attn_cp_rank = cp_rank
# The policy reads the configured tier, so the stand-in
# carries the leaf under `config`, where the bag serves it.
parallel = SimpleNamespace(
config=SimpleNamespace(
enable_dsa_cache_layer_split=layer_split,
),
)
with patch(
"sglang.srt.disaggregation.common.conn.get_parallel",
return_value=parallel,
with get_context().override_server_args(
enable_dsa_cache_layer_split=layer_split,
):
self.assertEqual(
manager._should_skip_cp_replicated_state_transfer(),
@@ -180,11 +172,8 @@ class TestCPReplicatedStateTransfer(unittest.TestCase):
manager.attn_cp_rank = 3
manager.is_hybrid_mla_backend = False
with patch(
"sglang.srt.disaggregation.common.conn.get_parallel",
return_value=SimpleNamespace(
config=SimpleNamespace(enable_dsa_cache_layer_split=False)
),
with get_context().override_server_args(
enable_dsa_cache_layer_split=False,
):
self.assertEqual(
manager._get_dsa_cache_transfer_skip_flags(None),
@@ -15,6 +15,7 @@ from unittest import mock
import torch
from sglang.srt.model_loader.loader import PreshardedModelLoader
from sglang.srt.runtime_context import get_context, get_parallel
from sglang.test.ci.ci_register import register_cpu_ci
register_cpu_ci(est_time=10, suite="base-a-test-cpu")
@@ -803,22 +804,23 @@ class TestShardConfig(unittest.TestCase):
"init_expert_location",
"structural_signature",
}
# Both tiers on one stand-in: bare names are the live groups, `config`
# is the published parallel bag.
parallel = SimpleNamespace(
# The sizes go through both channels: some entries read the published
# leaf, others the live property. `get_moe_cp_size` is imported inside
# `_collect_shard_config`, so it is patched where it is defined.
override = get_context().override_server_args(
tp_size=8,
moe_dp_size=2,
moe_ep_size=4,
pp_size=1,
config=SimpleNamespace(
moe_dp_size=2,
moe_dense_tp_size=1,
enable_dp_lm_head=True,
),
moe_dp_size=2,
moe_dense_tp_size=1,
enable_dp_lm_head=True,
)
with mock.patch(
"sglang.srt.model_loader.loader.get_parallel",
return_value=parallel,
override.install()
self.addCleanup(override.restore)
with get_parallel().override(
tp_size=8, pp_size=1, moe_dp_size=2, moe_ep_size=4
), mock.patch(
"sglang.srt.layers.dp_attention.get_moe_cp_size",
return_value=2,
), mock.patch(
"sglang.srt.model_loader.loader.get_exec",
return_value=SimpleNamespace(
@@ -332,18 +332,9 @@ class TestBailingMoeV3Gate(_FusionGateCase):
vocab_size=32000,
hidden_size=4096,
)
parallel = SimpleNamespace(
tp_size=1,
moe_ep_size=1,
config=SimpleNamespace(enable_dp_lm_head=False),
)
self._seed(enable_dp_lm_head=False)
with (
unittest.mock.patch.object(
bailing_moe_nextn, "get_parallel", return_value=parallel
),
unittest.mock.patch.object(
bailing_moe_v3, "get_parallel", return_value=parallel
),
get_parallel().override(tp_size=1, moe_ep_size=1),
unittest.mock.patch.object(
bailing_moe_v3,
"is_shared_experts_fusion_disabled",
@@ -1,10 +1,9 @@
"""Tests for multimodal tensor transport topology detection."""
import unittest
from types import SimpleNamespace
from unittest.mock import patch
from sglang.srt.multimodal.transport import determine_tensor_transport_mode
from sglang.srt.runtime_context import get_context
from sglang.test.ci.ci_register import register_cpu_ci
from sglang.test.test_utils import CustomTestCase
@@ -22,17 +21,9 @@ class TestTensorTransportMode(CustomTestCase):
for nnodes, dist_init_addr, expected in cases:
with self.subTest(nnodes=nnodes, dist_init_addr=dist_init_addr):
# `nnodes` is a config-only leaf, so the stand-in carries it
# under `config`, where the published bag serves it.
parallel = SimpleNamespace(
config=SimpleNamespace(
nnodes=nnodes,
dist_init_addr=dist_init_addr,
),
)
with patch(
"sglang.srt.multimodal.transport.get_parallel",
return_value=parallel,
with get_context().override_server_args(
nnodes=nnodes,
dist_init_addr=dist_init_addr,
):
self.assertEqual(determine_tensor_transport_mode(), expected)
@@ -863,7 +863,7 @@ class TestACopyStaysResolved(_RestoresProcessState, CustomTestCase):
self.addCleanup(reset_context)
reset_context()
publish(copy_, role="scheduler")
self.assertEqual(get_parallel().config.dist_init_addr, "1.2.3.4:5000")
self.assertEqual(get_parallel().dist_init_addr, "1.2.3.4:5000")
self.assertEqual(
get_schedule().chunked_prefill_size,
resolution_result(parent, "chunked_prefill_size"),
@@ -304,6 +304,7 @@ class TestLaunchPathsReadConfiguredSizes(CustomTestCase):
from unittest.mock import patch
from sglang.srt.runtime_context import (
ParallelContext,
get_parallel,
publish,
reset_context,
@@ -383,15 +384,20 @@ class TestLaunchPathsReadConfiguredSizes(CustomTestCase):
f"get_parallel().config.{name} followed the live topology "
"instead of the published configuration",
)
# A bare read of a leaf with no live property is not a config read any
# more, and the error says where it went. Spelled through `getattr` so a
# mechanical `.config` sweep cannot "fix" the very read under test.
with self.assertRaisesRegex(
AttributeError, r"read it as get_parallel\(\)\.config\.nccl_port"
):
getattr(get_parallel(), "nccl_port")
from sglang.srt.arg_groups.overrides import resolution_result
self.assertEqual(
resolution_result(server_args, "nccl_port"),
getattr(get_parallel(), "nccl_port"),
"a config-only leaf read bare disagreed with what resolution decided",
)
reset_context()
with self.assertRaisesRegex(ValueError, r"'parallel' not published"):
getattr(ParallelContext(), "nccl_port")
with self.assertRaisesRegex(AttributeError, r"has no 'not_a_leaf'"):
getattr(ParallelContext(), "not_a_leaf")
def test_no_live_topology_read_before_distributed_init(self):
offenders = []
for rel, tree in _launch_paths():
+3 -3
View File
@@ -911,11 +911,11 @@ class TestForwardFlags(_IsolatedServerArgs):
@torch.compile(fullgraph=True, backend="eager", dynamic=False)
def probe(x):
par = get_parallel()
if par.config.enable_prefill_context_parallel:
if par.enable_prefill_context_parallel:
x = x + 1
if par.config.moe_dense_tp_size == 1:
if par.moe_dense_tp_size == 1:
x = x + 2
if par.config.dwdp_size > 1:
if par.dwdp_size > 1:
x = x + 4
return x