[Edge][WP3] Add CPU OmniPlatform (AR + generation stages on vLLM's CPU backend)

* vllm_omni/platforms/cpu/platform.py: CPUOmniPlatform(OmniPlatform, CpuPlatform)
  selected when VLLM_TARGET_DEVICE=cpu or a +cpu vLLM wheel is installed
  (builtin plugin "cpu"; explicit CPU target short-circuits accelerator probes
  like vLLM does). NUMA-based memory queries, one logical device, no graph
  wrapper (sentinel type for isinstance checks), inductor opt-in via
  VLLM_OMNI_CPU_INDUCTOR=1, diffusion stages unsupported.
* vllm_omni/platforms/cpu/worker: CPUARWorker / CPUGenerationWorker compose
  vLLM's CPUWorker with the Omni mixin (XPU pattern); CPUARModelRunner /
  CPUGenerationModelRunner compose the Omni runners with CPUModelRunner
  (no graphs, no async omni output; sleep/wake return error ACKs).
* patch.py skips the CuMem patch on CPU-only torch; Qwen3-TTS speaker encoder
  and prompt-embeds dtype follow the model dtype (float32/float16 on CPU).
* vllm_omni/deploy/qwen3_tts.yaml: `platforms: cpu:` overlay (eager, no async
  scheduling, absolute kv_cache_memory_bytes, disjoint OMP thread ranges).
* requirements/cpu.txt (+psutil, intel-openmp), docs/getting_started/installation/cpu.md.

Measured (this x86 Xeon 8480C host, vllm 0.28.0+cpu, bf16, 12+4 threads):
Qwen3-TTS 0.6B CustomVoice end-to-end on CPU, 12 prompts: TTFA p50 292 ms,
RTF ~1.7 (25-frame chunk ~4.6 s), init 185 s. Result JSON + init timeline
committed under benchmarks/tts/edge_results/.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
tzhouamandClaude Fable 5.1 committed 2026-09-09 11:02:14 +08:00
1 parent 55192de984
commit 35e43b9983
18 files changed
+1740 -7

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
+160
View File
@@ -0,0 +1,160 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""CPU OmniPlatform: AR / generation stages on vLLM's CPU backend.
Composes vLLM's ``CpuPlatform`` (device attributes, ``check_and_update_config``
forcing: no async scheduling, no CUDA graphs, ``CPU_ATTN``, thread binding,
LD_PRELOAD) with the Omni interface, exactly as ``CudaOmniPlatform`` composes
``CudaPlatformBase``. Diffusion stages are not supported on CPU.
Activate with ``VLLM_TARGET_DEVICE=cpu`` (or a ``+cpu`` vLLM wheel). Deploy
YAMLs can pin CPU values under ``platforms: cpu:``.
"""
from __future__ import annotations
import os
from typing import Any
import torch
from vllm.logger import init_logger
from vllm.platforms.cpu import CpuPlatform
from vllm_omni.platforms.interface import OmniPlatform, OmniPlatformEnum
logger = init_logger(__name__)
def _numa_memory(device: torch.device | None = None) -> tuple[int, int]:
"""(available, total) bytes of the NUMA node this process is allowed on, else host memory."""
try:
from vllm.utils.cpu_resource_utils import get_allowed_cpu_list, get_memory_node_info
node = get_allowed_cpu_list()[0].numa_node
info = get_memory_node_info(node)
return int(info.available_memory), int(info.total_memory)
except Exception:
try:
import psutil
vm = psutil.virtual_memory()
return int(vm.available), int(vm.total)
except Exception:
return 0, 0
class _NoGraphWrapper:
"""Sentinel graph-wrapper type for the CPU platform (never instantiated)."""
def __init__(self, *args: Any, **kwargs: Any) -> None: # pragma: no cover - guard
raise NotImplementedError("CUDA graphs are not available on the CPU OmniPlatform")
class CPUOmniPlatform(OmniPlatform, CpuPlatform):
"""CPU implementation of OmniPlatform (AR + generation stages only)."""
_omni_enum = OmniPlatformEnum.CPU
# ----------------------------------------------------------- workers
@classmethod
def get_omni_ar_worker_cls(cls) -> str:
return "vllm_omni.platforms.cpu.worker.cpu_ar_worker.CPUARWorker"
@classmethod
def get_omni_generation_worker_cls(cls) -> str:
return "vllm_omni.platforms.cpu.worker.cpu_generation_worker.CPUGenerationWorker"
@classmethod
def get_default_stage_config_path(cls) -> str:
return "vllm_omni/deploy"
# ---------------------------------------------------------- diffusion
@classmethod
def get_diffusion_worker_cls(cls) -> str:
raise NotImplementedError("Diffusion stages are not supported on the CPU OmniPlatform")
@classmethod
def get_diffusion_model_runner_cls(cls) -> str:
raise NotImplementedError("Diffusion stages are not supported on the CPU OmniPlatform")
@classmethod
def get_diffusion_attn_backend_cls(cls, *args: Any, **kwargs: Any) -> str:
raise NotImplementedError("Diffusion attention backends are not supported on the CPU OmniPlatform")
@classmethod
def supports_diffusion_dense_flash_attention(cls) -> bool:
return False
@classmethod
def has_flash_attn_package(cls) -> bool:
return False
# ------------------------------------------------------------ compile
@classmethod
def supports_torch_inductor(cls) -> bool:
# The code predictor's torch.compile costs a long C++ codegen on first
# use; keep it off unless explicitly requested (measured variant).
return os.environ.get("VLLM_OMNI_CPU_INDUCTOR", "0") == "1"
@classmethod
def supports_talker_mtp_graph_capture(cls) -> bool:
return False
@classmethod
def get_graph_wrapper_cls(cls) -> type:
# Runners use this in ``isinstance`` checks on every decode step
# (``_talker_mtp_forward``); on CPU nothing is ever wrapped, so return a
# sentinel class that no object is an instance of.
return _NoGraphWrapper
# ------------------------------------------------------------- device
@classmethod
def get_torch_device(cls, local_rank: int | None = None) -> torch.device:
return torch.device("cpu")
@classmethod
def get_device_count(cls) -> int:
# One logical device: stage device locks / admission iterate range(count).
return 1
@classmethod
def get_device_version(cls) -> str | None:
return None
@classmethod
def synchronize(cls) -> None:
return None
@classmethod
def record_device_event(cls):
return None
@classmethod
def get_free_memory(cls, device: torch.device | None = None) -> int:
return _numa_memory(device)[0]
@classmethod
def get_device_memory(cls, device: torch.device | None = None) -> tuple[int, int]:
return _numa_memory(device)
@classmethod
def get_device_total_memory(cls, device_id: int = 0) -> int:
try:
return int(CpuPlatform.get_device_total_memory(device_id))
except Exception:
return _numa_memory()[1]
@classmethod
def supports_cpu_offload(cls) -> bool:
return False
@classmethod
def is_fully_connected(cls, physical_device_ids: list[int] | None = None) -> bool:
return True
@classmethod
def get_default_ir_op_priority(cls, *args: Any, **kwargs: Any):
parent = getattr(CpuPlatform, "get_default_ir_op_priority", None)
if parent is not None:
return parent(*args, **kwargs)
return super().get_default_ir_op_priority(*args, **kwargs) # type: ignore[misc]
@@ -0,0 +1,2 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
@@ -0,0 +1,62 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""CPU model runners for Omni AR and generation stages.
MRO: ``CPUARModelRunner -> GPUARModelRunner -> OmniGPUModelRunner -> (omni
mixins) -> CPUModelRunner -> GPUModelRunner``. ``CPUModelRunner.__init__``
runs vLLM's CPU shims (torch.cuda placeholders, ``_postprocess_tensors``,
``_postprocess_triton``) around ``GPUModelRunner.__init__``; the Omni layers
then add their buffers on the CPU device. Nothing CUDA-graph related can be
reached because ``CpuPlatform.check_and_update_config`` forces
``cudagraph_capture_sizes=[]`` and ``async_scheduling=False``.
"""
from __future__ import annotations
from vllm.logger import init_logger
from vllm.v1.worker.cpu_model_runner import CPUModelRunner
from vllm_omni.worker.gpu_ar_model_runner import GPUARModelRunner
from vllm_omni.worker.gpu_generation_model_runner import GPUGenerationModelRunner
logger = init_logger(__name__)
class _CPUOmniRunnerMixin:
"""Overrides shared by the CPU AR and generation runners."""
def _assert_cpu_invariants(self) -> None:
if getattr(self, "use_async_scheduling", False):
raise RuntimeError(
"CPU Omni runners require async_scheduling=False (vLLM's CpuPlatform forces it); "
"the async omni-output path uses CUDA streams."
)
def _init_device_properties(self) -> None:
self.num_sms = None
def _sync_device(self) -> None:
return None
def capture_model(self) -> int:
# No graphs on CPU; keep the call cheap and explicit.
return 0
def _capture_talker_mtp_graphs(self) -> None:
return None
class CPUARModelRunner(_CPUOmniRunnerMixin, GPUARModelRunner, CPUModelRunner):
"""AR (talker / thinker) runner on CPU."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._assert_cpu_invariants()
class CPUGenerationModelRunner(_CPUOmniRunnerMixin, GPUGenerationModelRunner, CPUModelRunner):
"""Generation (code2wav / decoder) runner on CPU."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._assert_cpu_invariants()
@@ -0,0 +1,63 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""CPU workers for Omni AR and generation stages (XPU-worker pattern).
``CPUWorker`` owns the CPU specifics (NUMA binding, ``init_cpu_memory_env``,
gloo, NUMA-based ``determine_available_memory``, no cudagraph warm-up); the
Omni mixin only loads omni plugins in the worker process. Sleep/wake are not
supported on CPU and return an error ACK instead of raising in the RPC loop.
"""
from __future__ import annotations
import vllm.v1.worker.cpu.shm # noqa: F401 # patches torch.Event/torch.cuda.Stream; must be first
from vllm.logger import init_logger
from vllm.v1.worker.cpu_worker import CPUWorker
from vllm_omni.diffusion.data import OmniACK
from vllm_omni.engine.init_timeline import timed_phase
from vllm_omni.platforms.cpu.worker.cpu_ar_model_runner import CPUARModelRunner, CPUGenerationModelRunner
from vllm_omni.worker.mixins import OmniWorkerMixin
logger = init_logger(__name__)
class _CPUOmniWorkerMixin:
model_runner_cls: type
@timed_phase("init_device")
def init_device(self) -> None:
super().init_device() # type: ignore[misc]
if getattr(self, "use_v2_model_runner", False):
logger.warning("OMNI CPU worker forces v1 model runner for omni hooks.")
self.use_v2_model_runner = False
# CPUWorker.init_device built a plain CPUModelRunner; replace it with the omni runner.
self.model_runner = self.model_runner_cls(self.vllm_config, self.device)
@staticmethod
def _task_id(task) -> str:
if isinstance(task, dict):
return str(task.get("task_id", ""))
return str(getattr(task, "task_id", ""))
def handle_sleep_task(self, task) -> OmniACK:
return OmniACK(
task_id=self._task_id(task), status="ERROR", error_msg="sleep mode is not supported on the CPU OmniPlatform"
)
def handle_wake_task(self, task) -> OmniACK:
return OmniACK(
task_id=self._task_id(task), status="ERROR", error_msg="wake-up is not supported on the CPU OmniPlatform"
)
class CPUARWorker(_CPUOmniWorkerMixin, OmniWorkerMixin, CPUWorker):
"""CPU AR worker for thinker / talker stages."""
model_runner_cls = CPUARModelRunner
class CPUGenerationWorker(_CPUOmniWorkerMixin, OmniWorkerMixin, CPUWorker):
"""CPU generation worker for decoder / code2wav stages."""
model_runner_cls = CPUGenerationModelRunner
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""Import-path shim: the CPU generation worker lives next to the AR worker."""
from vllm_omni.platforms.cpu.worker.cpu_ar_worker import CPUGenerationWorker
__all__ = ["CPUGenerationWorker"]