[Bugfix][Core] Fix stage initialization spawn-lock/device-lock inversion (#7926)
Signed-off-by: tzhouam <tzhouam@connect.ust.hk>
This commit is contained in:
1 parent
7f867fb782
commit
d38566ae80
4 files changed
+215
-72
No files matched your search
@@ -1588,6 +1588,8 @@ def launch_diffusion_stage_replica(
|
||||
replica_id: int = 0,
|
||||
omni_master_server: OmniMasterServer | None = None,
|
||||
omni_coordinator_address: str | None = None,
|
||||
stage_visible_devices: str | None = None,
|
||||
spawn_device_lock: threading.Lock | None = None,
|
||||
) -> tuple[Any, StageReplicaResources]:
|
||||
"""Launch a local diffusion stage replica.
|
||||
|
||||
@@ -1596,20 +1598,22 @@ def launch_diffusion_stage_replica(
|
||||
``StageDiffusionProc`` that heartbeats to ``OmniCoordinator``.
|
||||
"""
|
||||
if omni_master_server is None:
|
||||
client = initialize_diffusion_stage(
|
||||
metadata.stage_id,
|
||||
model,
|
||||
stage_config,
|
||||
metadata,
|
||||
stage_init_timeout=stage_init_timeout,
|
||||
use_inline=use_inline,
|
||||
)
|
||||
with scoped_spawn_device_env(stage_visible_devices, spawn_device_lock):
|
||||
client = initialize_diffusion_stage(
|
||||
metadata.stage_id,
|
||||
model,
|
||||
stage_config,
|
||||
metadata,
|
||||
stage_init_timeout=stage_init_timeout,
|
||||
use_inline=use_inline,
|
||||
)
|
||||
return client, StageReplicaResources()
|
||||
|
||||
from vllm_omni.diffusion import stage_diffusion_proc
|
||||
from vllm_omni.diffusion.stage_diffusion_client import StageDiffusionClient
|
||||
|
||||
od_config = build_diffusion_config(model, stage_config, metadata)
|
||||
with scoped_spawn_device_env(stage_visible_devices, spawn_device_lock):
|
||||
od_config = build_diffusion_config(model, stage_config, metadata)
|
||||
parallel_config = getattr(od_config, "parallel_config", None)
|
||||
world_size = getattr(parallel_config, "world_size", 1)
|
||||
try:
|
||||
@@ -1620,6 +1624,7 @@ def launch_diffusion_stage_replica(
|
||||
metadata.stage_id,
|
||||
{"tensor_parallel_size": world_size},
|
||||
stage_init_timeout,
|
||||
visible_devices=stage_visible_devices,
|
||||
)
|
||||
proc_manager = None
|
||||
try:
|
||||
@@ -1636,19 +1641,20 @@ def launch_diffusion_stage_replica(
|
||||
handshake=True,
|
||||
data=False,
|
||||
)
|
||||
proc_manager = stage_diffusion_proc.StageDiffusionProcManager(
|
||||
model=model,
|
||||
od_config=od_config,
|
||||
stage_init_timeout=stage_init_timeout,
|
||||
handshake_address=registration.handshake_address,
|
||||
addresses=EngineZmqAddresses(
|
||||
inputs=[registration.input_address],
|
||||
outputs=[registration.output_address],
|
||||
),
|
||||
omni_coordinator_address=omni_coordinator_address,
|
||||
omni_stage_id=metadata.stage_id,
|
||||
omni_replica_id=replica_id,
|
||||
)
|
||||
with scoped_spawn_device_env(stage_visible_devices, spawn_device_lock):
|
||||
proc_manager = stage_diffusion_proc.StageDiffusionProcManager(
|
||||
model=model,
|
||||
od_config=od_config,
|
||||
stage_init_timeout=stage_init_timeout,
|
||||
handshake_address=registration.handshake_address,
|
||||
addresses=EngineZmqAddresses(
|
||||
inputs=[registration.input_address],
|
||||
outputs=[registration.output_address],
|
||||
),
|
||||
omni_coordinator_address=omni_coordinator_address,
|
||||
omni_stage_id=metadata.stage_id,
|
||||
omni_replica_id=replica_id,
|
||||
)
|
||||
omni_master_server.release_route_port_reservations(
|
||||
metadata.stage_id,
|
||||
replica_id,
|
||||
|
||||
@@ -1755,9 +1755,13 @@ def acquire_device_locks(
|
||||
engine_args_dict: dict[str, Any],
|
||||
stage_init_timeout: int,
|
||||
locked_devices: set[int] | None = None,
|
||||
*,
|
||||
visible_devices: str | None = None,
|
||||
) -> list[int]:
|
||||
"""Acquire exclusive file locks on devices needed by this stage.
|
||||
|
||||
Pass resolved physical ``visible_devices`` to avoid changing the process
|
||||
environment while waiting. When omitted, use the device-control environment.
|
||||
Returns list of lock file descriptors that must be released after init.
|
||||
"""
|
||||
lock_fds: list[int] = []
|
||||
@@ -1790,7 +1794,7 @@ def acquire_device_locks(
|
||||
|
||||
# Get physical device IDs
|
||||
device_control_env = current_omni_platform.device_control_env_var
|
||||
visible_devices_str = os.environ.get(device_control_env)
|
||||
visible_devices_str = visible_devices if visible_devices is not None else os.environ.get(device_control_env)
|
||||
physical_devices: list[int] = []
|
||||
|
||||
if visible_devices_str:
|
||||
|
||||
@@ -411,15 +411,17 @@ class StageRuntime:
|
||||
replica.metadata.runtime_cfg,
|
||||
)
|
||||
if not self._parallel_stage_init:
|
||||
with self._scoped_spawn_device_env(physical_devices):
|
||||
lock_fds.extend(
|
||||
acquire_device_locks(
|
||||
replica.metadata.stage_id,
|
||||
replica.engine_args_dict,
|
||||
timeout,
|
||||
locked_devices,
|
||||
)
|
||||
# Never hold the spawn-env lock while waiting for a GPU:
|
||||
# its current holder may need that lock to spawn.
|
||||
lock_fds.extend(
|
||||
acquire_device_locks(
|
||||
replica.metadata.stage_id,
|
||||
replica.engine_args_dict,
|
||||
timeout,
|
||||
locked_devices,
|
||||
visible_devices=physical_devices,
|
||||
)
|
||||
)
|
||||
|
||||
launch_context = launch_stage_replica(
|
||||
vllm_config=replica.stage_vllm_config,
|
||||
@@ -557,17 +559,6 @@ class StageRuntime:
|
||||
"""Hook for runtimes that own extra infrastructure during init."""
|
||||
return None
|
||||
|
||||
@contextmanager
|
||||
def _scoped_spawn_device_env(self, physical_devices: str | None) -> Iterator[None]:
|
||||
"""Briefly scope device visibility for spawn-sensitive setup steps."""
|
||||
from vllm_omni.engine.stage_engine_startup import scoped_spawn_device_env
|
||||
|
||||
with scoped_spawn_device_env(
|
||||
physical_devices,
|
||||
self._spawn_device_lock,
|
||||
):
|
||||
yield
|
||||
|
||||
def _resolve_replica_physical_devices(self, stage_id: int, runtime_cfg: Any) -> str | None:
|
||||
if runtime_cfg is None:
|
||||
runtime_cfg = {}
|
||||
@@ -578,13 +569,6 @@ class StageRuntime:
|
||||
visible_baseline=self._init_visible_devices_baseline,
|
||||
)
|
||||
|
||||
@contextmanager
|
||||
def _stage_device_scope(self, stage_id: int, runtime_cfg: Any) -> Iterator[None]:
|
||||
"""Temporarily apply the stage device env while launching a replica."""
|
||||
physical_devices = self._resolve_replica_physical_devices(stage_id, runtime_cfg)
|
||||
with self._scoped_spawn_device_env(physical_devices):
|
||||
yield
|
||||
|
||||
# ---- Internal methods ----
|
||||
|
||||
def _validate_native_kv_topology(self, plans: list[LogicalStageInitPlan]) -> None:
|
||||
@@ -1182,10 +1166,8 @@ class StageRuntime:
|
||||
client = None
|
||||
resources = None
|
||||
try:
|
||||
with (
|
||||
stage_runtime_env(plan.metadata.stage_id, plan.metadata.runtime_cfg),
|
||||
self._stage_device_scope(plan.metadata.stage_id, plan.metadata.runtime_cfg),
|
||||
):
|
||||
physical_devices = self._resolve_replica_physical_devices(plan.metadata.stage_id, plan.metadata.runtime_cfg)
|
||||
with stage_runtime_env(plan.metadata.stage_id, plan.metadata.runtime_cfg):
|
||||
omni_conn_cfg, omni_from, omni_to = plan.omni_kv_connector
|
||||
if omni_conn_cfg:
|
||||
if omni_from is None or omni_to is None:
|
||||
@@ -1221,6 +1203,8 @@ class StageRuntime:
|
||||
replica_id=plan.replica_id,
|
||||
omni_master_server=self._get_omni_master_server(),
|
||||
omni_coordinator_address=self._get_coordinator_address(),
|
||||
stage_visible_devices=physical_devices,
|
||||
spawn_device_lock=self._spawn_device_lock,
|
||||
)
|
||||
|
||||
logger.info(
|
||||
|
||||
Reference in new issue
Block a user