mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-18 06:10:43 -07:00
* feat(windows): add native ROCm support for AMD GPUs Implements native ROCm architecture for Windows. - Adds backend build pipeline for voicebox-server-rocm.exe - Detects AMD GPUs dynamically and routes PyTorch allocations - Adds automatic download and update logic for ROCm dependencies - Refactors UI in GpuPage.tsx and GpuAcceleration.tsx to add AMD flows - Fixes 'Switch to CPU' lock on Windows via Tauri backend_override state - Resolves PyInstaller/rocm_sdk UnboundLocalError silent crashes - Resolves Numba/NumPy 2.x incompatibilities during Qwen3-TTS load - Resolves HF_HUB_OFFLINE Catch-22 for CustomVoice processor caching * fix(rocm): host libs archive under the app release tag, drop offline-load regression Align the ROCm libs download with the CUDA pattern: both the server core and the libs archive are published under the app-version release tag, with the libs content version encoded in the filename only. The previous code fetched libs from a separate rocm7.2-v1 tag, which disagreed with the download test. Also revert the unrelated Qwen CustomVoice changes that wrapped model loading in force_offline_if_cached (not imported — a NameError on load for every platform) and re-added a Base-model cache gate. The inference-path offline guard was deliberately removed previously. * feat(rocm): gate download on AMD detection and persist the backend variant The ROCm download section now only shows when the backend reports an AMD GPU on Windows (new supports_rocm health field, backed by the memoized is_amd_gpu_windows detection that was previously unused), or when ROCm is already downloaded/active. Make the backend override honor a pinned variant: set_backend_override persists the choice to disk so it survives an app restart, start_server reads it back, and a cuda/rocm pin now actually selects that variant instead of always preferring ROCm. A stale pin to a deleted backend self-heals to the default order rather than forcing CPU. Add the web no-op stub for the new method. * chore(rocm): drop incomplete vitest harness for the unused GpuAcceleration component GpuAcceleration.tsx is not routed anywhere (GpuPage is the live settings view), and the added vitest setup referenced testing-library/vitest deps that were not in the lockfile, breaking the web typecheck. Remove the dead component's test and its scaffolding to keep this PR scoped to the ROCm feature. * ci(rocm): add ROCm release-artifact pipeline Mirror the CUDA packaging path for ROCm so the runtime download has artifacts to fetch. scripts/package_rocm.py splits the PyInstaller --rocm onedir into voicebox-server-rocm.tar.gz (core) + rocm-libs-rocm7.2-v1.tar.gz (AMD runtime: HIP DLLs, rocBLAS Tensile data, MIOpen kernel DBs) + rocm-libs.json, matching the names services/rocm.py expects, both under the app-version release tag. The new build-rocm-windows job in release.yml builds on windows-latest/cp312 and lets build_binary.py --rocm pull the official AMD Radeon wheels. The file classifier can't be validated against a real AMD build on CI, so it has unit coverage (test_package_rocm.py) against a synthetic onedir layout. The prefixes/dir markers may need a tweak after the first real build on AMD hardware — the packager hard-fails loudly if it classifies zero ROCm files. --------- Co-authored-by: Jamie Pine <[email protected]>
This commit is contained in:
co-authored by
Jamie Pine
parent
c2282b256a
commit
e766c7cbfb
+249
-54
@@ -22,24 +22,34 @@ def is_apple_silicon():
|
||||
return platform.system() == "Darwin" and platform.machine() == "arm64"
|
||||
|
||||
|
||||
def build_server(cuda=False):
|
||||
def build_server(cuda=False, rocm=False):
|
||||
"""Build Python server as standalone binary.
|
||||
|
||||
Args:
|
||||
cuda: If True, build with CUDA support and name the binary
|
||||
voicebox-server-cuda instead of voicebox-server.
|
||||
rocm: If True, build with ROCm support and name the binary
|
||||
voicebox-server-rocm instead of voicebox-server.
|
||||
"""
|
||||
if cuda and rocm:
|
||||
raise ValueError("Cannot build with both CUDA and ROCm support")
|
||||
|
||||
backend_dir = Path(__file__).parent
|
||||
|
||||
binary_name = "voicebox-server-cuda" if cuda else "voicebox-server"
|
||||
if rocm:
|
||||
binary_name = "voicebox-server-rocm"
|
||||
elif cuda:
|
||||
binary_name = "voicebox-server-cuda"
|
||||
else:
|
||||
binary_name = "voicebox-server"
|
||||
|
||||
# PyInstaller arguments
|
||||
# CUDA builds use --onedir so we can split the output into two archives:
|
||||
# CUDA and ROCm builds use --onedir so we can split the output into two archives:
|
||||
# 1. Server core (~200-400MB) — versioned with the app
|
||||
# 2. CUDA libs (~2GB) — versioned independently (only redownloaded on
|
||||
# CUDA toolkit / torch major version changes)
|
||||
# 2. GPU libs (~2GB) — versioned independently (only redownloaded on
|
||||
# GPU toolkit / torch major version changes)
|
||||
# CPU builds remain --onefile for simplicity.
|
||||
pack_mode = "--onedir" if cuda else "--onefile"
|
||||
pack_mode = "--onedir" if (cuda or rocm) else "--onefile"
|
||||
args = [
|
||||
"server.py", # Use server.py as entry point instead of main.py
|
||||
pack_mode,
|
||||
@@ -320,22 +330,74 @@ def build_server(cuda=False):
|
||||
]
|
||||
)
|
||||
|
||||
# Add CUDA-specific hidden imports
|
||||
if cuda:
|
||||
logger.info("Building with CUDA support")
|
||||
# Add CUDA/ROCm-specific hidden imports
|
||||
if cuda or rocm:
|
||||
variant = "ROCm" if rocm else "CUDA"
|
||||
logger.info("Building with %s support", variant)
|
||||
gpu_hidden = [
|
||||
"--hidden-import",
|
||||
"torch.cuda",
|
||||
]
|
||||
# cudnn is NVIDIA-specific; ROCm uses MIOpen under the abstraction layer
|
||||
if cuda:
|
||||
gpu_hidden.extend(
|
||||
[
|
||||
"--hidden-import",
|
||||
"torch.backends.cudnn",
|
||||
]
|
||||
)
|
||||
args.extend(gpu_hidden)
|
||||
|
||||
if rocm:
|
||||
# rocm_sdk imports its backend packages dynamically via
|
||||
# importlib.import_module(py_package_name), which PyInstaller's
|
||||
# static analyzer cannot see. We must collect them explicitly —
|
||||
# otherwise only the pure-python rocm_sdk wrapper ships and
|
||||
# rocm_sdk.find_libraries crashes with UnboundLocalError at boot.
|
||||
#
|
||||
# The backend packages also contain the HIP/MIOpen/hipBLAS DLLs
|
||||
# under bin/ (plus ~750 MB of tensile kernel files under
|
||||
# bin/rocblas/library and bin/hipblaslt/library) — collect-all
|
||||
# walks the tree recursively so both DLLs and kernel data are
|
||||
# bundled. See rocm_sdk/_dist_info.py for the package mapping.
|
||||
args.extend(
|
||||
[
|
||||
"--collect-all",
|
||||
"rocm_sdk",
|
||||
"--collect-all",
|
||||
"_rocm_sdk_core",
|
||||
"--collect-all",
|
||||
"_rocm_sdk_libraries_custom",
|
||||
"--collect-all",
|
||||
"rocm_sdk_core",
|
||||
"--collect-all",
|
||||
"rocm_sdk_libraries_custom",
|
||||
"--hidden-import",
|
||||
"torch.cuda",
|
||||
"_rocm_sdk_core",
|
||||
"--hidden-import",
|
||||
"torch.backends.cudnn",
|
||||
"_rocm_sdk_libraries_custom",
|
||||
"--hidden-import",
|
||||
"rocm_sdk_core",
|
||||
"--hidden-import",
|
||||
"rocm_sdk_libraries_custom",
|
||||
"--copy-metadata",
|
||||
"rocm",
|
||||
"--copy-metadata",
|
||||
"rocm-sdk-core",
|
||||
"--copy-metadata",
|
||||
"rocm-sdk-libraries-custom",
|
||||
# Repair rocm_sdk.find_libraries (masks UnboundLocalError
|
||||
# with a readable ModuleNotFoundError on missing backends).
|
||||
"--runtime-hook",
|
||||
"pyi_rth_rocm_sdk.py",
|
||||
]
|
||||
)
|
||||
else:
|
||||
# Exclude NVIDIA CUDA packages from CPU-only builds to keep binary small.
|
||||
# When building from a venv with CUDA torch installed, PyInstaller would
|
||||
# bundle ~3GB of NVIDIA shared libraries. We exclude both the Python
|
||||
# modules and the binary DLLs.
|
||||
|
||||
# Exclude NVIDIA CUDA packages from non-CUDA builds to keep binary small.
|
||||
# When building from a venv with CUDA torch installed, PyInstaller would
|
||||
# bundle ~3GB of NVIDIA shared libraries. We exclude both the Python
|
||||
# modules and the binary DLLs. This applies to CPU and ROCm builds.
|
||||
if not cuda:
|
||||
nvidia_packages = [
|
||||
"nvidia",
|
||||
"nvidia.cublas",
|
||||
@@ -354,8 +416,8 @@ def build_server(cuda=False):
|
||||
for pkg in nvidia_packages:
|
||||
args.extend(["--exclude-module", pkg])
|
||||
|
||||
# Add MLX-specific imports if building on Apple Silicon (never for CUDA builds)
|
||||
if is_apple_silicon() and not cuda:
|
||||
# Add MLX-specific imports if building on Apple Silicon (never for GPU builds)
|
||||
if is_apple_silicon() and not cuda and not rocm:
|
||||
logger.info("Building for Apple Silicon - including MLX dependencies")
|
||||
args.extend(
|
||||
[
|
||||
@@ -399,7 +461,7 @@ def build_server(cuda=False):
|
||||
"mlx_lm",
|
||||
]
|
||||
)
|
||||
elif not cuda:
|
||||
elif not cuda and not rocm:
|
||||
logger.info("Building for non-Apple Silicon platform - PyTorch only")
|
||||
|
||||
dist_dir = str(backend_dir / "dist")
|
||||
@@ -420,43 +482,128 @@ def build_server(cuda=False):
|
||||
os.chdir(backend_dir)
|
||||
|
||||
# For CPU builds on Windows, ensure we're using CPU-only torch.
|
||||
# If CUDA torch is installed (local dev), swap to CPU torch before building,
|
||||
# then restore CUDA torch after. This prevents PyInstaller from bundling
|
||||
# ~3GB of CUDA DLLs into the CPU binary.
|
||||
restore_cuda = False
|
||||
if not cuda and platform.system() == "Windows":
|
||||
import subprocess
|
||||
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", "import torch; print(torch.version.cuda or '')"], capture_output=True, text=True
|
||||
)
|
||||
has_cuda_torch = bool(result.stdout.strip())
|
||||
if has_cuda_torch:
|
||||
logger.info("CUDA torch detected — installing CPU torch for CPU build...")
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"torch",
|
||||
"torchvision",
|
||||
"torchaudio",
|
||||
"--index-url",
|
||||
"https://download.pytorch.org/whl/cpu",
|
||||
"--force-reinstall",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
restore_cuda = True
|
||||
|
||||
# Run PyInstaller
|
||||
# If CUDA or ROCm torch is installed (local dev), swap to CPU torch before
|
||||
# building, then restore afterwards. This prevents PyInstaller from bundling
|
||||
# GPU libraries into the CPU binary.
|
||||
restore_torch = None
|
||||
try:
|
||||
if not cuda and not rocm and platform.system() == "Windows":
|
||||
import subprocess
|
||||
|
||||
cuda_result = subprocess.run(
|
||||
[sys.executable, "-c", "import torch; print(torch.version.cuda or '')"], capture_output=True, text=True
|
||||
)
|
||||
rocm_result = subprocess.run(
|
||||
[sys.executable, "-c", "import torch; print(torch.version.hip or '')"], capture_output=True, text=True
|
||||
)
|
||||
|
||||
if cuda_result.stdout.strip():
|
||||
restore_torch = "cuda"
|
||||
logger.info("CUDA torch detected — installing CPU torch for CPU build...")
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"torch",
|
||||
"torchvision",
|
||||
"torchaudio",
|
||||
"--index-url",
|
||||
"https://download.pytorch.org/whl/cpu",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
elif rocm_result.stdout.strip():
|
||||
restore_torch = "rocm"
|
||||
logger.info("ROCm torch detected — installing CPU torch for CPU build...")
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"torch",
|
||||
"torchvision",
|
||||
"torchaudio",
|
||||
"--index-url",
|
||||
"https://download.pytorch.org/whl/cpu",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
# For ROCm builds on Windows, ensure ROCm torch is installed.
|
||||
if rocm and platform.system() == "Windows":
|
||||
import subprocess
|
||||
|
||||
if sys.implementation.name != "cpython" or sys.version_info[:2] != (3, 12):
|
||||
raise RuntimeError(
|
||||
"ROCm wheels are cp312-cp312-specific; "
|
||||
f"got {sys.implementation.name} {sys.version.split()[0]}. "
|
||||
"Use CPython 3.12 to build the ROCm binary."
|
||||
)
|
||||
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", "import torch; print(torch.version.hip or '')"], capture_output=True, text=True
|
||||
)
|
||||
has_rocm_torch = bool(result.stdout.strip())
|
||||
if not has_rocm_torch:
|
||||
logger.info("ROCm torch not detected — installing ROCm torch for ROCm build...")
|
||||
|
||||
# Determine what to restore BEFORE overwriting the environment
|
||||
cuda_result = subprocess.run(
|
||||
[sys.executable, "-c", "import torch; print(torch.version.cuda or '')"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if cuda_result.stdout.strip():
|
||||
restore_torch = "cuda"
|
||||
else:
|
||||
restore_torch = "cpu"
|
||||
|
||||
# Now overwrite the environment safely
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/rocm_sdk_core-7.2.1-py3-none-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/rocm_sdk_devel-7.2.1-py3-none-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/rocm_sdk_libraries_custom-7.2.1-py3-none-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/rocm-7.2.1.tar.gz",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torch-2.9.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torchaudio-2.9.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torchvision-0.24.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
# Run PyInstaller
|
||||
PyInstaller.__main__.run(args)
|
||||
finally:
|
||||
# Restore CUDA torch if we swapped it out (even on build failure)
|
||||
if restore_cuda:
|
||||
# Restore torch if we swapped it out (even on build failure)
|
||||
if restore_torch == "cuda":
|
||||
logger.info("Restoring CUDA torch...")
|
||||
import subprocess
|
||||
|
||||
@@ -472,10 +619,52 @@ def build_server(cuda=False):
|
||||
"--index-url",
|
||||
"https://download.pytorch.org/whl/cu128",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
elif restore_torch == "rocm":
|
||||
logger.info("Restoring ROCm torch...")
|
||||
import subprocess
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torch-2.9.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torchaudio-2.9.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"https://repo.radeon.com/rocm/windows/rocm-rel-7.2.1/torchvision-0.24.1%2Brocm7.2.1-cp312-cp312-win_amd64.whl",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
elif restore_torch == "cpu":
|
||||
logger.info("Restoring CPU torch...")
|
||||
import subprocess
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"torch",
|
||||
"torchvision",
|
||||
"torchaudio",
|
||||
"--index-url",
|
||||
"https://download.pytorch.org/whl/cpu",
|
||||
"--force-reinstall",
|
||||
"--no-deps",
|
||||
"-q",
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
logger.info("Binary built in %s", backend_dir / "dist" / binary_name)
|
||||
|
||||
@@ -577,6 +766,11 @@ if __name__ == "__main__":
|
||||
action="store_true",
|
||||
help="Build CUDA-enabled binary (voicebox-server-cuda)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--rocm",
|
||||
action="store_true",
|
||||
help="Build ROCm-enabled binary (voicebox-server-rocm) for AMD GPUs",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--shim",
|
||||
action="store_true",
|
||||
@@ -586,4 +780,5 @@ if __name__ == "__main__":
|
||||
if cli_args.shim:
|
||||
build_shim()
|
||||
else:
|
||||
build_server(cuda=cli_args.cuda)
|
||||
build_server(cuda=cli_args.cuda, rocm=cli_args.rocm)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user