Skip to content
Closed
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
28 changes: 7 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -203,4 +188,5 @@ extend-ignore-identifiers-re = [
".*NOTHINK.*",
".*nin.*",
"Ono_Anna",
".*cann.*",
]
13 changes: 13 additions & 0 deletions requirements/common.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions requirements/cpu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# CPU-specific dependencies
# Add CPU-specific optimization libraries here
3 changes: 3 additions & 0 deletions requirements/cuda.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fa3-fwd
onnxruntime>=1.19.0
sox>=1.5.0
4 changes: 4 additions & 0 deletions requirements/npu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# NPU-specific dependencies (Ascend)
# Add NPU-specific acceleration libraries here
onnxruntime-cann>=1.23.2
sox>=1.5.0
4 changes: 4 additions & 0 deletions requirements/rocm.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ROCm-specific dependencies
# Add AMD-specific acceleration libraries here
onnxruntime-rocm>=1.22.2
sox>=1.5.0
2 changes: 2 additions & 0 deletions requirements/xpu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# XPU-specific dependencies (Intel)
# Add Intel XPU-specific acceleration libraries here
127 changes: 127 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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:
Comment thread
gcanlin marked this conversation as resolved.
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)