[Edge][CPU] Admit CPU stages against host memory so parallel init can run

`parallel_stage_init` was structurally impossible on a CPU deployment.
`resolve_stage_physical_devices` returns None for `devices: "cpu"`, and the
admission resolver fails closed on None -- correctly, for a GPU replica whose
devices cannot be accounted -- so every CPU pipeline raised
StageAdmissionError and fell back to sequential stage startup. The edge
profile sets parallel_stage_init: true, so that profile was broken on CPU
rather than merely slower.

Measured on Qwen3-TTS 0.6B (Xeon 8480C, 24 threads, init only):

    sequential   64.57 s
    parallel     30.54 s      2.1x

The fix is not to skip admission. The per-device ledger is vacuous on CPU --
there is no device to overcommit -- but the resource concurrent CPU init
contends for is host memory, and two stages allocating KV caches at once can
exhaust it exactly as two GPU stages exhaust a card. So there is now a host
ledger with the same discipline: sum the declared KV budgets, compare against
available RAM with a margin, refuse to start if it does not fit, and fail
closed on a stage that declares no budget at all. The arithmetic is pure
(`evaluate_host`) so it is testable without a device, matching the existing
design.

Which ledger applies is decided by where the stages are *placed*, not by what
platform the process reports: a first version keyed on
`current_platform.is_cpu()` and broke five existing GPU-path tests, because a
CPU-only test host still has to admit GPU-shaped plans correctly. It now
routes on the replicas' own `devices`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
tzhouamandClaude Opus 5 committed 2026-09-12 21:16:11 +08:00
1 parent bc7f8237e3
commit a51461c131
3 files changed
+223

No files matched your search

+92
View File
@@ -839,3 +839,95 @@ def test_device_ledger_required_and_fits():
assert led.fits
led.kv_budget_bytes = 90
assert not led.fits
# --------------------------------------------------------------------------- #
# Host-memory admission: parallel init on a CPU platform
# --------------------------------------------------------------------------- #
def _cpu_vllm_config(kv_bytes: int | None):
return types.SimpleNamespace(
cache_config=types.SimpleNamespace(kv_cache_memory_bytes=kv_bytes),
compilation_config=types.SimpleNamespace(cudagraph_capture_sizes=[]),
)
def test_host_ledger_arithmetic():
from vllm_omni.engine.stage_admission import evaluate_host
led = evaluate_host([("s0", 4 << 30), ("s1", 2 << 30)],
available_bytes=16 << 30, safety_margin_bytes=1 << 30)
assert led.kv_bytes == 6 << 30
assert led.required_bytes == 7 << 30
assert led.fits
assert evaluate_host([("s0", 20 << 30)], available_bytes=16 << 30).fits is False
def test_cpu_stages_are_admitted_against_host_memory():
"""The per-device ledger is vacuous on CPU; host RAM is the real resource."""
from vllm_omni.engine.stage_admission import check_host_admission
plans = [
LogicalStageInitPlan(stage_idx=0, stage_id=0, replicas=[
_llm_replica(0, 0, "cpu", vllm_config=_cpu_vllm_config(1 << 30))]),
LogicalStageInitPlan(stage_idx=1, stage_id=1, replicas=[
_llm_replica(1, 0, "cpu", vllm_config=_cpu_vllm_config(2 << 30))]),
]
led = check_host_admission(plans, available_memory=lambda: 32 << 30)
assert led.kv_bytes == 3 << 30
assert led.contributors == ["stage0/replica0", "stage1/replica0"]
def test_cpu_admission_fails_fast_when_host_memory_is_short():
from vllm_omni.engine.stage_admission import check_host_admission
plans = [LogicalStageInitPlan(stage_idx=0, stage_id=0, replicas=[
_llm_replica(0, 0, "cpu", vllm_config=_cpu_vllm_config(30 << 30))])]
with pytest.raises(StageAdmissionError, match="host memory"):
check_host_admission(plans, available_memory=lambda: 8 << 30)
def test_cpu_admission_fails_closed_on_an_undeclared_budget():
"""Same discipline as the device ledger: an unbounded stage cannot be
admitted to initialize concurrently with others."""
from vllm_omni.engine.stage_admission import check_host_admission
plans = [LogicalStageInitPlan(stage_idx=0, stage_id=0, replicas=[
_llm_replica(0, 0, "cpu", vllm_config=_cpu_vllm_config(None))])]
with pytest.raises(StageAdmissionError, match="cannot account for CPU replicas"):
check_host_admission(plans, available_memory=lambda: 64 << 30)
def test_cpu_diffusion_stage_allocates_no_kv_and_is_skipped():
from vllm_omni.engine.stage_admission import check_host_admission
replica = _llm_replica(0, 0, "cpu", vllm_config=None)
plans = [LogicalStageInitPlan(stage_idx=0, stage_id=0, replicas=[replica])]
led = check_host_admission(plans, available_memory=lambda: 16 << 30)
assert led.kv_bytes == 0 and led.contributors == []
def test_runtime_routes_cpu_platforms_to_the_host_ledger(monkeypatch):
"""Before this, `devices: "cpu"` resolved to no physical ids and the device
resolver failed closed, so parallel_stage_init could never run on CPU."""
import vllm_omni.engine.stage_admission as admission_mod
seen: dict = {}
def _fake_host(stage_plans, *, available_memory, **kw):
seen["plans"] = stage_plans
seen["available"] = available_memory()
return None
monkeypatch.setattr(admission_mod, "check_host_admission", _fake_host)
def _explode(*a, **k):
raise AssertionError("device ledger must not run on a CPU platform")
monkeypatch.setattr(admission_mod, "check_admission", _explode)
runtime = _runtime(parallel_stage_init=True)
plans = [LogicalStageInitPlan(stage_idx=0, stage_id=0, replicas=[
_llm_replica(0, 0, "cpu", vllm_config=_cpu_vllm_config(1 << 30))])]
runtime._run_stage_admission(plans)
assert seen["plans"] is plans
assert seen["available"] > 0