Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/inferrsi/box/repos/vllm_omni/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Box hot-patching adapter for `vllm-omni` Diffusion serving (`vllm serve --omni`)
on Ascend NPU, built on the shared Box transaction kernel (`SCHEMA_VERSION = 1`)
with AST first-line witness counting and on-demand dynamic module registration.

## Scope (Pilot — Single-Stage Eager T2VA)
## Scope (Single-Stage Eager T2VA, Single- and Multi-Rank)

This initial slice covers:
This adapter covers:

- Single diffusion stage (`stage_id = 0`), single Ascend NPU (`num_gpus = 1`,
`TP = PP = DP = SP = CFG = 1`), explicit `distributed_executor_backend = "mp"`,
and pure eager execution (`enforce_eager = True`, `diffusion_use_graph = False`).
- Single diffusion stage (`stage_id = 0`), single-replica Ascend NPU topologies
with `num_gpus = PP x TP x SP x CFG` (`data_parallel_size = 1`, HSDP refused),
explicit `distributed_executor_backend = "mp"`, and pure eager execution
(`enforce_eager = True`, `diffusion_use_graph = False`).
- Native `vllm serve --omni` HTTP serving via `NativeOmniServeLab`, gating
public traffic through `OmniBoxAdmissionMiddleware` while exposing a private
owner-only Unix domain socket inside `StageDiffusionProc` / `DiffusionEngine`.
Expand All @@ -21,15 +22,16 @@ This initial slice covers:
digest, saved artifact path (when requested), and per-target AST witnesses.
- `GET /v1/models` provides a zero-hit control workload.

Multi-stage / multi-rank switching, DiT ACLGraph recapture, and NPU kernel /
controlled-config hot-swaps are tracked in follow-up slices under #937 / #863.
Multi-stage switching, data-parallel replicas, HSDP sharding, DiT ACLGraph
recapture, and NPU kernel / controlled-config hot-swaps are tracked in follow-up
slices under #863.

## Modules

| Module | Role |
| --- | --- |
| `config.py` | `VllmOmniConfig` and `parse_omni_workload` for `video_sync` and `models` checks. |
| `graphs.py` | Fail-closed eager & topology guard (`restart_required` for non-eager, graph capture, `torch.compile`, or multi-rank configs). |
| `graphs.py` | Fail-closed eager & topology guard (`restart_required` for non-eager, graph capture, `torch.compile`, DP > 1, HSDP, or inconsistent parallel factors). |
| `backend.py` | `AscendDiffusionBackend` validating `DiffusionWorker`, NPU device context, and synchronization. |
| `worker.py` | `DiffusionWorkerService` and `AscendDiffusionWorkerExtension` (`worker_extension_cls`) exposing `box_boot` and `box_group_rpc`. |
| `engine_hook.py` | Opt-in `sitecustomize` import hook injecting `worker_extension_cls`, `distributed_executor_backend`, and `DiffusionEngineHost` into `DiffusionEngine`. |
Expand Down
9 changes: 8 additions & 1 deletion src/inferrsi/box/repos/vllm_omni/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
VllmOmniConfig,
parse_omni_workload,
)
from .graphs import detect_diffusion_graph_mode, validate_eager_diffusion_worker
from .graphs import (
detect_diffusion_graph_mode,
diffusion_parallel_dimensions,
validate_diffusion_topology,
validate_eager_diffusion_worker,
)
from .server_lab import NativeOmniServeLab, encode_multipart_form
from .worker import (
AscendDiffusionWorkerExtension,
Expand All @@ -31,7 +36,9 @@
"WORKER_EXTENSION_CLS",
"WORKLOADS",
"detect_diffusion_graph_mode",
"diffusion_parallel_dimensions",
"encode_multipart_form",
"parse_omni_workload",
"validate_diffusion_topology",
"validate_eager_diffusion_worker",
]
2 changes: 1 addition & 1 deletion src/inferrsi/box/repos/vllm_omni/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class AscendDiffusionBackend:
"""Validate and synchronize a single-NPU eager vLLM-Omni Diffusion worker."""
"""Validate and synchronize an eager Ascend NPU vLLM-Omni Diffusion worker."""

name = "ascend_diffusion"
device_prefix = "npu"
Expand Down
8 changes: 5 additions & 3 deletions src/inferrsi/box/repos/vllm_omni/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ def _normalize_mapping(
class VllmOmniConfig:
"""Configuration for an owned native ``vllm serve --omni`` Diffusion Box instance.

Pilot scope is a single diffusion stage (``stage_id=0``) with single-device
eager execution (``num_gpus=1``) and explicit ``distributed_executor_backend="mp"``.
Pilot scope is a single diffusion stage (``stage_id=0``) with eager execution,
one replica spread over ``num_gpus`` ranks, and explicit
``distributed_executor_backend="mp"``. Data-parallel replicas and HSDP weight
sharding are refused by the topology guard.
Policy constraints (``allowed_modules``, ``allowed_targets``, ``source_roots``,
``expected_versions``) are opt-in; when omitted, the adapter records observed
runtime metadata without blocking startup.
Expand Down Expand Up @@ -130,7 +132,7 @@ def __post_init__(self) -> None:
object.__setattr__(self, name, value)

def effective_engine_args(self) -> dict[str, Any]:
"""Merge caller overrides over single-device eager diffusion defaults."""
"""Merge caller overrides over eager diffusion defaults."""
merged: dict[str, Any] = {
"model": self.model,
"enforce_eager": True,
Expand Down
104 changes: 84 additions & 20 deletions src/inferrsi/box/repos/vllm_omni/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@

from ...protocol import BoxError

_PARALLEL_ATTRS = (
"data_parallel_size",
"tensor_parallel_size",
_NON_DP_FACTORS = (
"pipeline_parallel_size",
"tensor_parallel_size",
"sequence_parallel_size",
"ulysses_degree",
"ring_degree",
"cfg_parallel_size",
)

Expand Down Expand Up @@ -86,6 +83,87 @@ def detect_diffusion_graph_mode(worker: Any) -> str | None:
return None


def _parallel_dimension(parallel: Any, name: str) -> int:
value = getattr(parallel, name, 1)
if value is None:
return 1
if type(value) is not int or value < 1:
raise BoxError(
"restart_required",
f"diffusion parallel {name} must be a positive integer, got {value!r}",
)
return value


def diffusion_parallel_dimensions(od_config: Any) -> dict[str, int]:
"""Return the vLLM-Omni parallelism factors that multiply to the world size.

vLLM-Omni resolves ``num_gpus`` as ``PP x DP x TP x SP x CFG``, where SP is
``ulysses_degree x ring_degree`` or ``allgather_degree`` when AllGather-KV is
enabled. Reading the same factors keeps the guard aligned with the engine
instead of hard-coding a device count.
"""
parallel = getattr(od_config, "parallel_config", None)
if parallel is None:
return dict.fromkeys(("data_parallel_size", *_NON_DP_FACTORS), 1)
allgather = _parallel_dimension(parallel, "allgather_degree")
ulysses = _parallel_dimension(parallel, "ulysses_degree")
ring = _parallel_dimension(parallel, "ring_degree")
sequence = allgather if allgather > 1 else ulysses * ring

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 拓扑准入公式漏乘 Ulysses。PR 固定的 vLLM-Omni 06a28821 配置校验 明确允许 Ulysses × AllGather(Ring=1),并要求 SP=Ulysses×Ring×AllGather。在本 head 直接调用 validate_diffusion_topology:仅 Ulysses=2 和仅 AllGather=2 都通过,但 Ulysses=2, Ring=1, AllGather=2, SP=4, num_gpus=4 被拒为 restart_required,这里把 SP 算成了 2。请对齐固定上游语义,并补一个合法 U2×AG2 四 rank 和一个非法 Ring×AG 的 CPU 对照,避免放行上游本身不支持的组合。

declared = getattr(parallel, "sequence_parallel_size", None)
if declared is not None and declared != sequence:
raise BoxError(
"restart_required",
f"diffusion sequence_parallel_size {declared} disagrees with Ulysses "
f"{ulysses} x Ring {ring} / AllGather {allgather} = {sequence}",
)
dimensions = {name: _parallel_dimension(parallel, name) for name in _NON_DP_FACTORS}
dimensions["sequence_parallel_size"] = sequence
dimensions["data_parallel_size"] = _parallel_dimension(parallel, "data_parallel_size")
return dimensions


def validate_diffusion_topology(od_config: Any, expected_num_gpus: int) -> dict[str, int]:
"""Refuse topologies outside single-stage single-replica scope; return the factors."""
parallel = getattr(od_config, "parallel_config", None)
if parallel is None:
if expected_num_gpus != 1:
raise BoxError(
"restart_required",
f"diffusion stage has no parallel config but num_gpus={expected_num_gpus}",
)
return diffusion_parallel_dimensions(od_config)
if bool(getattr(parallel, "use_hsdp", False)):
raise BoxError(
"restart_required",
"HSDP shards weights across ranks, so the eager patch pilot cannot assume "
"full weights on every rank",
)
dimensions = diffusion_parallel_dimensions(od_config)
non_dp = 1
for name in _NON_DP_FACTORS:
non_dp *= dimensions[name]
if expected_num_gpus % non_dp:
raise BoxError(
"restart_required",
f"num_gpus {expected_num_gpus} is not a multiple of PP x TP x SP x CFG = {non_dp}",
)
replica = expected_num_gpus // non_dp
if dimensions["data_parallel_size"] != replica:
raise BoxError(
"restart_required",
f"data_parallel_size {dimensions['data_parallel_size']} does not match "
f"num_gpus // (PP x TP x SP x CFG) = {replica}",
)
if replica != 1:
raise BoxError(
"restart_required",
f"data_parallel_size {replica} is not admitted: one stage patches one replica, "
"so request routing and the witness policy stay single-replica",
)
return dimensions


def validate_eager_diffusion_worker(
worker: Any,
*,
Expand Down Expand Up @@ -113,21 +191,7 @@ def validate_eager_diffusion_worker(
f"diffusion worker num_gpus {num_gpus} differs from expected {expected_num_gpus}",
)

if expected_num_gpus != 1:
raise BoxError(
"restart_required",
"eager diffusion pilot admits single-device num_gpus=1 only",
)

parallel = getattr(od_config, "parallel_config", None)
if parallel is not None:
for attr in _PARALLEL_ATTRS:
value = getattr(parallel, attr, 1)
if value is not None and value != 1:
raise BoxError(
"restart_required",
f"eager diffusion pilot requires {attr}=1, got {value}",
)
validate_diffusion_topology(od_config, expected_num_gpus)

device = getattr(worker, "device", None)
device_type = getattr(device, "type", None) or str(device).split(":", 1)[0]
Expand Down
31 changes: 23 additions & 8 deletions src/inferrsi/box/repos/vllm_omni/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ def __init__(self, engine, raw: dict):
od_config = getattr(engine, "od_config", None)
args = self.config.effective_engine_args()
world_size = int(args.get("num_gpus", 1))
if world_size != 1:
raise BoxError("restart_required", "eager diffusion pilot admits num_gpus=1 only")
if world_size < 1:
raise BoxError(
"restart_required",
f"diffusion num_gpus {world_size} is not a positive world size",
)
if od_config is not None and getattr(od_config, "num_gpus", 1) != world_size:
raise BoxError(
"restart_required",
Expand Down Expand Up @@ -122,10 +125,21 @@ def _boot_workers(self, raw: dict, expected: Identity) -> dict[int, dict]:
and type(value.get("pid")) is int
and value["pid"] > 0
and os.getpgid(value["pid"]) == self.process_group
and isinstance(value.get("device"), str)
and value["device"]
and Identity.parse(value["identity"]) == expected,
"diffusion worker did not prove boot ownership or stage identity",
)
boot[rank] = value
devices = [value["device"] for value in boot.values()]
_require(len(set(devices)) == len(devices), "diffusion workers share one device")
pids = [value["pid"] for value in boot.values()]
_require(len(set(pids)) == len(pids), "diffusion workers share one PID")
if len(boot) > 1:
_require(
os.getpid() not in pids,
"a multi-rank diffusion stage cannot host a worker in the engine process",
)
return boot

def call(self, action: str, command: Command, *args, valid_identities: tuple[dict, ...]):
Expand Down Expand Up @@ -493,12 +507,13 @@ def _wait_engine_idle(self, deadline: float) -> None:
while has_requests():
remaining(deadline)
sleep(min(remaining(deadline), 0.01))
self.engine.collective_rpc(
"synchronize_device",
timeout=remaining(deadline),
kwargs={"timeout": remaining(deadline)},
unique_reply_rank=0,
)
for rank in sorted(self.participants.ranks):
self.engine.collective_rpc(
"synchronize_device",
timeout=remaining(deadline),
kwargs={"timeout": remaining(deadline)},
unique_reply_rank=rank,
)

def _serve(self, listener: socket.socket, stopped: Event) -> None:
while not stopped.is_set():
Expand Down
4 changes: 3 additions & 1 deletion src/inferrsi/harness/executor/local_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
# Cancellation handles are polled at this interval; without one, wait is unchanged.
_POLL_SECONDS = 0.05
# Bound for confirming that a terminated process domain holds no live member.
_DRAIN_SECONDS = 10.0
# A multi-rank NPU worker set releases its device contexts well after SIGKILL:
# eight ranks still held the process group open 10 s after the kill.
_DRAIN_SECONDS = 30.0


class _Cancelled(Exception):
Expand Down
Loading
Loading