[Core] Sync DP state on the first step of a wave (#52957)

Signed-off-by: aoshen02 <aoshen@inferact.ai>
This commit is contained in:
aoshen02
2026-09-06 02:16:58 +00:00
committed by GitHub
parent f4eccdadef
commit 039ea82660
4 changed files with 65 additions and 3 deletions
+54 -1
View File
@@ -16,6 +16,7 @@ from vllm.config import (
ECTransferConfig,
KVTransferConfig,
ModelConfig,
ParallelConfig,
SchedulerConfig,
VllmConfig,
)
@@ -23,7 +24,7 @@ from vllm.engine.arg_utils import EngineArgs
from vllm.platforms import current_platform
from vllm.utils.torch_utils import set_default_torch_num_threads
from vllm.v1.engine import EngineCoreRequest
from vllm.v1.engine.core import EngineCore, EngineCoreProc
from vllm.v1.engine.core import DPEngineCoreProc, EngineCore, EngineCoreProc
from vllm.v1.executor.abstract import Executor
from vllm.v1.executor.uniproc_executor import UniProcExecutor
from vllm.v1.kv_cache_interface import KVCacheConfig
@@ -610,6 +611,58 @@ def test_encoder_instance_zero_kv_cache(
)
def _cadenced_dp_engine_core(
monkeypatch, results: list[tuple[bool, bool]], dp_sync_interval: int = 32
):
"""A bare DPEngineCoreProc whose all-reduce is scripted by `results`;
returns the core and the step numbers at which the all-reduce ran."""
core = object.__new__(DPEngineCoreProc)
core.dp_group = object()
core.dp_sync_interval = dp_sync_interval
core.step_counter = 0
core.pending_pause = False
core.ignore_start_dp_wave = False
synced: list[int] = []
def scripted_sync(dp_group, has_unfinished, pending_pause):
synced.append(core.step_counter)
return results.pop(0)
monkeypatch.setattr(ParallelConfig, "sync_dp_state", staticmethod(scripted_sync))
return core, synced
def test_dp_sync_interval_default_is_16():
"""Regression pin: lowering the default narrows the mid-wave pause tail
for async RL, where the engine is rarely idle when pause lands."""
assert ParallelConfig.dp_sync_interval == 16
@pytest.mark.parametrize("dp_sync_interval", [32, 16])
def test_dp_sync_interval_normal_wave(monkeypatch, dp_sync_interval: int):
"""First all-reduce of a wave after one step, then every N."""
core, synced = _cadenced_dp_engine_core(
monkeypatch, [(True, False)] * 3, dp_sync_interval=dp_sync_interval
)
for _ in range(dp_sync_interval * 2 + 6):
assert DPEngineCoreProc._has_global_unfinished_reqs(core, True)
assert synced == [1, dp_sync_interval, dp_sync_interval * 2]
def test_dp_sync_interval_idle_pause_consensus_on_first_step(monkeypatch):
"""A pause of an idle engine arms every rank before its kick-started
first step, so the step-1 sync reaches consensus after one dummy batch
regardless of the configured cadence."""
core, synced = _cadenced_dp_engine_core(
monkeypatch, [(False, True)], dp_sync_interval=32
)
core.pending_pause = True
assert DPEngineCoreProc._has_global_unfinished_reqs(core, False) is False
assert synced == [1]
assert core.ignore_start_dp_wave
assert not core.pending_pause
def _pausable_engine_core_proc() -> EngineCoreProc:
"""A bare EngineCoreProc holding just the state pause_scheduler touches."""
core = object.__new__(EngineCoreProc)
+2
View File
@@ -142,6 +142,8 @@ class ParallelConfig:
"""IP of the data parallel master."""
data_parallel_rpc_port: int = Field(default=29550, ge=1, le=65535)
"""Fixed port for data parallel messaging, shared by all nodes."""
dp_sync_interval: int = Field(default=16, ge=1)
"""Steps between DP finish-sync all-reduces; must match across DP ranks."""
data_parallel_master_port: int = 29500
"""Port of the data parallel master."""
data_parallel_backend: DataParallelBackend = "mp"
+6
View File
@@ -508,6 +508,7 @@ class EngineArgs:
enable_dbo: bool = ParallelConfig.enable_dbo
ubatch_size: int = ParallelConfig.ubatch_size
dbo_decode_token_threshold: int = ParallelConfig.dbo_decode_token_threshold
dp_sync_interval: int = ParallelConfig.dp_sync_interval
dbo_prefill_token_threshold: int = ParallelConfig.dbo_prefill_token_threshold
disable_nccl_for_dp_synchronization: bool | None = (
ParallelConfig.disable_nccl_for_dp_synchronization
@@ -1190,6 +1191,10 @@ class EngineArgs:
"--dbo-decode-token-threshold",
**parallel_kwargs["dbo_decode_token_threshold"],
)
parallel_group.add_argument(
"--dp-sync-interval",
**parallel_kwargs["dp_sync_interval"],
)
parallel_group.add_argument(
"--dbo-prefill-token-threshold",
**parallel_kwargs["dbo_prefill_token_threshold"],
@@ -2307,6 +2312,7 @@ class EngineArgs:
enable_dbo=self.enable_dbo,
ubatch_size=self.ubatch_size,
dbo_decode_token_threshold=self.dbo_decode_token_threshold,
dp_sync_interval=self.dp_sync_interval,
dbo_prefill_token_threshold=self.dbo_prefill_token_threshold,
disable_nccl_for_dp_synchronization=self.disable_nccl_for_dp_synchronization,
enable_eplb=self.enable_eplb,
+3 -2
View File
@@ -2032,6 +2032,7 @@ class DPEngineCoreProc(EngineCoreProc):
scheduler_config = vllm_config.scheduler_config
self.prefill_schedule_interval = scheduler_config.prefill_schedule_interval
self.dp_sync_interval = vllm_config.parallel_config.dp_sync_interval
# Counts forward-passes of the model so that we can synchronize
# finished with DP peers every N steps.
@@ -2280,9 +2281,9 @@ class DPEngineCoreProc(EngineCoreProc):
raise SystemExit
def _has_global_unfinished_reqs(self, local_unfinished: bool) -> bool:
# Optimization - only perform finish-sync all-reduce every 32 steps.
# Sync step 1 too: an idle pause needs one dummy batch, not a full interval.
self.step_counter += 1
if self.step_counter % 32 != 0:
if self.step_counter != 1 and self.step_counter % self.dp_sync_interval != 0:
return True
has_unfinished, pause_consensus = ParallelConfig.sync_dp_state(