From d48f9f841906e21ab99e098f8d3aaefd6842cea0 Mon Sep 17 00:00:00 2001 From: tzielinski-habana Date: Mon, 23 Feb 2026 19:37:21 +0200 Subject: [PATCH 1/3] Added torchaudio installation to setup.py Signed-off-by: tzielinski-habana --- setup.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/setup.py b/setup.py index 5673a4a47a..ce75cdbbec 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,8 @@ import logging import os +import re +import subprocess +import sys from setuptools import setup, find_packages from setuptools_scm import get_version @@ -40,6 +43,11 @@ def _read_requirements(filename: str) -> list[str]: requirements = _read_requirements("requirements.txt") except ValueError: print("Failed to read requirements.txt in vllm_gaudi.") + + # Exclude torchaudio from install_requires — it needs --no-deps to + # avoid pulling CUDA torch, which install_requires cannot express. + requirements = [r for r in requirements if not r.strip().startswith("torchaudio")] + return requirements @@ -71,3 +79,28 @@ def _read_requirements(filename: str) -> list[str]: ], }, ) + +# Install torchaudio with --no-deps to avoid pulling CUDA torch. +# Skipped during metadata generation (dist_info / egg_info). +if "dist_info" not in sys.argv and "egg_info" not in 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}", + ]) From 06cae19839eec03dbd0c753430a7dd89d492a2dc Mon Sep 17 00:00:00 2001 From: tzielinski-habana Date: Mon, 23 Feb 2026 20:06:49 +0200 Subject: [PATCH 2/3] Raise exception if torchaudio is found in requirements.txt Signed-off-by: tzielinski-habana --- setup.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index ce75cdbbec..92bb151d3e 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ import subprocess import sys +from packaging.requirements import InvalidRequirement, Requirement from setuptools import setup, find_packages from setuptools_scm import get_version @@ -26,6 +27,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") @@ -35,6 +43,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 @@ -44,10 +55,6 @@ def _read_requirements(filename: str) -> list[str]: except ValueError: print("Failed to read requirements.txt in vllm_gaudi.") - # Exclude torchaudio from install_requires — it needs --no-deps to - # avoid pulling CUDA torch, which install_requires cannot express. - requirements = [r for r in requirements if not r.strip().startswith("torchaudio")] - return requirements From d732b6e673dd12ac6d49c714e1949f313064f059 Mon Sep 17 00:00:00 2001 From: tzielinski-habana Date: Mon, 23 Feb 2026 20:37:35 +0200 Subject: [PATCH 3/3] Add guards for packaging commands Signed-off-by: tzielinski-habana --- setup.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 92bb151d3e..60b08f7773 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ import logging import os + import re import subprocess import sys @@ -88,8 +89,9 @@ def _read_requirements(filename: str) -> list[str]: ) # Install torchaudio with --no-deps to avoid pulling CUDA torch. -# Skipped during metadata generation (dist_info / egg_info). -if "dist_info" not in sys.argv and "egg_info" not in sys.argv: +# 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: