diff --git a/pyproject.toml b/pyproject.toml index 809d1f53cd1..016b05d606a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,27 +25,12 @@ classifiers = [ "Topic :: Scientific/Engineering :: Artificial Intelligence", "Topic :: Software Development :: Libraries :: Python Modules", ] - - -dependencies = [ - # Core runtime dependencies (required for actual usage) - "omegaconf>=2.3.0", - "librosa>=0.11.0", - "resampy>=0.4.3", - "diffusers>=0.36.0", - "accelerate==1.12.0", - "gradio==5.50", - "soundfile>=0.13.1", - "cache-dit==1.2.0", - "tqdm>=4.66.0", - "torchsde>=0.2.6", # Required for Stable Audio scheduler - "fa3-fwd", # flash attention 3, maintained by @ZJY0516 - "openai-whisper>=20250625", - "imageio[ffmpeg]>=2.37.2", - "onnxruntime>=1.19.0", - "sox>=1.5.0", - # "vllm==0.14.0", # TODO: fix the entrypoints overwrite problem -] +# NOTE: dependencies are managed via setup.py for platform-aware routing +# See requirements/common.txt for common dependencies +# See requirements/{cuda,rocm,npu,xpu,cpu}.txt for platform-specific dependencies +# Platform detection happens at install time via VLLM_OMNI_TARGET_DEVICE env var +# or torch backend auto-detection +dynamic = ["dependencies"] [project.optional-dependencies] @@ -203,4 +188,5 @@ extend-ignore-identifiers-re = [ ".*NOTHINK.*", ".*nin.*", "Ono_Anna", + ".*cann.*", ] diff --git a/requirements/common.txt b/requirements/common.txt new file mode 100644 index 00000000000..99d356199cf --- /dev/null +++ b/requirements/common.txt @@ -0,0 +1,13 @@ +# Common dependencies (platform-independent) +omegaconf>=2.3.0 +librosa>=0.11.0 +resampy>=0.4.3 +diffusers>=0.36.0 +accelerate==1.12.0 +gradio==5.50 +soundfile>=0.13.1 +cache-dit==1.2.0 +tqdm>=4.66.0 +torchsde>=0.2.6 +openai-whisper>=20250625 +imageio[ffmpeg]>=2.37.2 diff --git a/requirements/cpu.txt b/requirements/cpu.txt new file mode 100644 index 00000000000..d5bb9e30474 --- /dev/null +++ b/requirements/cpu.txt @@ -0,0 +1,2 @@ +# CPU-specific dependencies +# Add CPU-specific optimization libraries here diff --git a/requirements/cuda.txt b/requirements/cuda.txt new file mode 100644 index 00000000000..0c3c178f520 --- /dev/null +++ b/requirements/cuda.txt @@ -0,0 +1,3 @@ +fa3-fwd +onnxruntime>=1.19.0 +sox>=1.5.0 diff --git a/requirements/npu.txt b/requirements/npu.txt new file mode 100644 index 00000000000..363cb4eb8fc --- /dev/null +++ b/requirements/npu.txt @@ -0,0 +1,4 @@ +# NPU-specific dependencies (Ascend) +# Add NPU-specific acceleration libraries here +onnxruntime-cann>=1.23.2 +sox>=1.5.0 diff --git a/requirements/rocm.txt b/requirements/rocm.txt new file mode 100644 index 00000000000..65f4133a44f --- /dev/null +++ b/requirements/rocm.txt @@ -0,0 +1,4 @@ +# ROCm-specific dependencies +# Add AMD-specific acceleration libraries here +onnxruntime-rocm>=1.22.2 +sox>=1.5.0 diff --git a/requirements/xpu.txt b/requirements/xpu.txt new file mode 100644 index 00000000000..c103a8a89cf --- /dev/null +++ b/requirements/xpu.txt @@ -0,0 +1,2 @@ +# XPU-specific dependencies (Intel) +# Add Intel XPU-specific acceleration libraries here diff --git a/setup.py b/setup.py new file mode 100644 index 00000000000..a556df33e46 --- /dev/null +++ b/setup.py @@ -0,0 +1,127 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project +""" +Platform-aware dependency routing for vLLM-Omni. + +This module implements install-time detection of the target hardware platform +and automatically selects the appropriate platform-specific dependencies. + +Detection Priority: +1. Explicit override via VLLM_OMNI_TARGET_DEVICE environment variable +2. Torch backend detection (CUDA, ROCm, NPU, XPU) +3. Fallback to common dependencies only (treated as CPU) + +Supported platforms: cuda, rocm, npu, xpu, cpu +""" + +from __future__ import annotations + +import os +from pathlib import Path +from typing import Literal + +from setuptools import setup + +try: + import torch +except Exception: # pragma: no cover - torch may not be installed at build time + torch = None + +ROOT = Path(__file__).parent + +# Supported target devices +TargetDevice = Literal["cuda", "rocm", "npu", "xpu", "cpu"] + + +def _read_requirements(filename: str) -> list[str]: + """Read and resolve requirements from a file, handling -r includes.""" + requirements_path = ROOT / "requirements" / filename + if not requirements_path.exists(): + return [] + lines = requirements_path.read_text().splitlines() + resolved: list[str] = [] + for line in lines: + line = line.strip() + if not line or line.startswith("#"): + continue + if line.startswith("-r "): + resolved += _read_requirements(line.split()[1]) + else: + resolved.append(line) + return resolved + + +def _detect_target_device() -> TargetDevice | None: + """ + Detect the target device platform for dependency selection. + + Priority rules: + 1. VLLM_OMNI_TARGET_DEVICE environment variable (highest priority) + 2. Torch backend detection via torch.version.cuda/hip and device availability + 3. None (fallback - only common dependencies will be installed) + + Returns: + The detected target device, or None if no platform can be determined. + """ + # Priority 1: Explicit environment variable override + env_target = os.getenv("VLLM_OMNI_TARGET_DEVICE", "").lower() + if env_target: + valid_devices = {"cuda", "rocm", "npu", "xpu", "cpu"} + if env_target in valid_devices: + return env_target # type: ignore[return-value] + # Invalid value - log warning and continue with auto-detection + print( + f"Warning: Invalid VLLM_OMNI_TARGET_DEVICE='{env_target}'. " + f"Valid values: {valid_devices}. Falling back to auto-detection." + ) + + # Priority 2: Torch backend detection + if torch is not None: + # Check CUDA + if getattr(torch.version, "cuda", None) is not None: + return "cuda" + + # Check ROCm + if getattr(torch.version, "hip", None) is not None: + return "rocm" + + # Check NPU + try: + if hasattr(torch, "npu") and torch.npu.is_available(): + return "npu" + except Exception: + pass + + # Check XPU + try: + if hasattr(torch, "xpu") and torch.xpu.is_available(): + return "xpu" + except Exception: + pass + + # Priority 3: Fallback - no specific platform detected + return None + + +def _get_install_requires() -> list[str]: + """ + Build the complete list of install requirements based on detected platform. + + Always includes common.txt, then adds platform-specific dependencies + based on the detected target device. + """ + install_requires = _read_requirements("common.txt") + + target_device = _detect_target_device() + + if target_device is not None: + platform_requirements_file = f"{target_device}.txt" + platform_requirements = _read_requirements(platform_requirements_file) + install_requires += platform_requirements + + return install_requires + + +install_requires = _get_install_requires() + +setup(install_requires=install_requires)