Skip to content
Closed
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
42 changes: 42 additions & 0 deletions setup.py
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

Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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)
Copy link

Copilot AI Feb 23, 2026

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 an AttributeError if torch.__version__ doesn’t match the expected x.y.z format (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., via packaging.version).

Suggested change
ver = re.match(r"(\d+\.\d+\.\d+)", torch.__version__).group(1)
version_match = re.match(r"(\d+\.\d+\.\d+)", torch.__version__)
if version_match is None:
raise RuntimeError(
f"Unable to parse torch version from '{torch.__version__}' "
"to determine the matching torchaudio version."
)
ver = version_match.group(1)

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running pip install via subprocess.check_call inside setup.py introduces build-time side effects (network access, mutating the build env) under the PEP 517 setuptools.build_meta backend. This will execute during wheel builds (e.g., bdist_wheel) and can break reproducible/offline builds and CI. Prefer moving this to an explicit install step (docs or a dedicated installer script/extra) rather than performing dependency installation from setup.py.

Suggested change
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."
)

Copilot uses AI. Check for mistakes.
Loading