-
Notifications
You must be signed in to change notification settings - Fork 133
Added torchaudio installation to setup.py #1010
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,11 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import re | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import subprocess | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| from packaging.requirements import InvalidRequirement, Requirement | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from setuptools import setup, find_packages | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from setuptools_scm import get_version | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -23,6 +28,13 @@ def get_path(*filepath) -> str: | |||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_requirements() -> list[str]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Get Python package dependencies from requirements.txt.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _req_name(line: str) -> str: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Extract normalized project name from a PEP 508 requirement line.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Requirement(line).name.lower() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| except InvalidRequirement: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _read_requirements(filename: str) -> list[str]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| with open(get_path(filename)) as f: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| requirements = f.read().strip().split("\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -32,6 +44,9 @@ def _read_requirements(filename: str) -> list[str]: | |||||||||||||||||||||||||||||||||||||||||||||||||||
| resolved_requirements += _read_requirements(line.split()[1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif line.startswith("--"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif _req_name(line) == "torchaudio": | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise RuntimeError("To ensure proper installation, torchaudio is handled in setup.py\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Please remove it from requirements.txt") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| resolved_requirements.append(line) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return resolved_requirements | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -40,6 +55,7 @@ def _read_requirements(filename: str) -> list[str]: | |||||||||||||||||||||||||||||||||||||||||||||||||||
| requirements = _read_requirements("requirements.txt") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| except ValueError: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| print("Failed to read requirements.txt in vllm_gaudi.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return requirements | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -71,3 +87,29 @@ def _read_requirements(filename: str) -> list[str]: | |||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Install torchaudio with --no-deps to avoid pulling CUDA torch. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Only run during actual install/develop – skip metadata, wheel, and sdist builds. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| _PACKAGING_COMMANDS = {"dist_info", "egg_info", "bdist_wheel", "sdist", "build"} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not _PACKAGING_COMMANDS.intersection(sys.argv): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import torch | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| except ImportError: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise RuntimeError( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "torch is not importable - this is needed for torchaudio installation.\n\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "********************************************************************************\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Make sure torch is installed before installing vllm-gaudi\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "and add --no-build-isolation to pip install\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "********************************************************************************\n") from None | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Extract stable x.y.z from versions like 2.10.0a0+git... | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ver = re.match(r"(\d+\.\d+\.\d+)", torch.__version__).group(1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.check_call([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| sys.executable, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "-m", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "pip", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "install", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--no-deps", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--extra-index-url", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "https://download.pytorch.org/whl/cpu", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"torchaudio=={ver}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+106
to
+115
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.check_call([ | |
| sys.executable, | |
| "-m", | |
| "pip", | |
| "install", | |
| "--no-deps", | |
| "--extra-index-url", | |
| "https://download.pytorch.org/whl/cpu", | |
| f"torchaudio=={ver}", | |
| ]) | |
| # Building/installing this package should not perform network operations or | |
| # mutate the environment (e.g., by running `pip install`). Instead, tell the | |
| # user how to install a matching torchaudio version explicitly. | |
| cmd = ( | |
| f"{sys.executable} -m pip install --no-deps --extra-index-url " | |
| "https://download.pytorch.org/whl/cpu " | |
| f"torchaudio=={ver}" | |
| ) | |
| raise RuntimeError( | |
| "torchaudio is required but is not installed.\n\n" | |
| "To install a CPU-only torchaudio build matching your torch version, run:\n\n" | |
| f" {cmd}\n\n" | |
| "Note: This command must be run explicitly by the user; it is not executed\n" | |
| "automatically during the build to keep builds reproducible and side-effect free." | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re.match(...).group(1)will raise anAttributeErroriftorch.__version__doesn’t match the expectedx.y.zformat (e.g., unusual local builds). This would fail the package install even if torchaudio is otherwise optional. Handle the no-match case explicitly (raise a clear error or fall back to a safer version parsing approach, e.g., viapackaging.version).