-
Notifications
You must be signed in to change notification settings - Fork 1k
[Hardware] Support platform-aware dependency routing #1040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
056101e
[Hardware] Support platform-aware dependency routing
gcanlin edf811e
fix lint
gcanlin f028674
Add requirements
gcanlin b366fc2
fix lint
gcanlin 657581b
fix
gcanlin 185f219
typo
gcanlin 4b990f5
fix lint
gcanlin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # CPU-specific dependencies | ||
| # Add CPU-specific optimization libraries here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| fa3-fwd | ||
| onnxruntime>=1.19.0 | ||
| sox>=1.5.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
| 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) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.