Files
VoiceStudio/scripts/setup-api.mjs
T
Michael Maertzdorfanddebpalash d6d17c81d4 feat(gpu): add opt-in native Windows ROCm installation (#3045)
* feat(gpu): add opt-in native Windows ROCm installation

Use one pinned Windows recipe for source and Electron setup, verify native packages before reuse, and preserve explicit opt-in and sidecar compatibility boundaries.

* docs(rocm): drop agent-instruction plan files; move the entry to a changelog fragment

* fix(rocm): hash-pin every AMD artifact and keep dependencies at their locked versions

Each repo.radeon.com wheel/sdist now carries a sha256 in the recipe, the loader
refuses one without it, and the installer installs from a --hash requirements
file (uv verifies; UV_NO_VERIFY_HASHES is stripped). A constraints file pins
every installed package except the overlay (torch family, rocm*, triton*,
ctranslate2), so transitive deps no longer resolve fresh from the index. The
rocm sdist builds with the locked setuptools.

* fix(rocm): ask before switching an existing runtime to Windows ROCm

OMNIVOICE_TORCH_VARIANT=rocm used to be ignored on Windows; with this PR it
would fail readiness on update and auto-repair into a multi-GB download from
new hosts. A successful install now records its torch build (.runtime-torch);
a runtime never installed with Windows ROCm goes to the setup screen instead
of auto-repair. ROCm on Windows ARM64 reports not-ready instead of rejecting
readiness, and the setup screen names repo.radeon.com as the Windows ROCm
torch source.

* fix(rocm): resolve ROCm packages from site-packages and remember a failed GPU probe

package_root() finds torch, ctranslate2 and the ROCm SDK packages through
their distribution records in this interpreter's site-packages, so a stray
folder in the working directory of a -m child can't choose the DLL
directories. A failed HIP CT2 probe (up to 90 s) is remembered for the
process instead of 5 s, so catalogue refreshes don't re-run it; a restart,
recipe or package change runs it again.

* docs(rocm): record the owner-approved Windows ROCm endpoints and how setup checks them

* docs(structure): count the pyannote compat service module

* test(rocm): pin the host architecture in the setup-reuse readiness test

* fix(repo): untrack the committed .venv symlink and ignore symlinked envs; follow the new ROCm copy in the GPU panel test

.gitignore's '.venv/' only matches directories, so a worktree's symlinked
.venv was committed and CI's uv sync failed on it. Ignore '.venv' without the
slash and add a guard that no local environment path is ever tracked.

* test(audio-io): allow the pyannote torchaudio shim, which applies the gate's own fix to third-party calls

---------

Co-authored-by: debpalash <4178343+debpalash@users.noreply.github.com>
2026-10-26 07:29:37 +05:30

73 lines
2.6 KiB
JavaScript

import { spawnSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { repairSourceNativeLibraries } from "../electron/scripts/native-compat.mjs";
import {
selectTorchVariant,
torchSyncArgs,
windowsRocmSyncArgs,
} from "../electron/scripts/torch-variant.mjs";
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
export async function setupApi({
env = process.env,
platform = process.platform,
arch = process.arch,
run = spawnSync,
selectVariant = selectTorchVariant,
log = console.log,
repairNativeLibraries = repairSourceNativeLibraries,
} = {}) {
const variant = await selectVariant({ env, platform, arch });
const windowsRocm = platform === "win32" && variant === "rocm";
if (windowsRocm && arch !== "x64")
throw new Error("Windows ROCm requires Windows x64 Python 3.12 (cp312).");
const environment = windowsRocm ? { ...env, OMNIVOICE_TORCH_VARIANT: "rocm" } : env;
// The matched torch stack has no native Windows ARM64 torchaudio wheel.
const pythonArgs = windowsRocm
? ["--python", "cpython-3.12-windows-x86_64"]
: platform === "win32" && arch === "arm64"
? ["--python", "cpython-3.11-windows-x86_64"]
: [];
const syncArgs = windowsRocm
? windowsRocmSyncArgs(readFileSync(resolve(root, "uv.lock"), "utf8"))
: torchSyncArgs(variant);
log(
`[setup] PyTorch: ${variant}${variant === "cpu" ? " (GPU acceleration unavailable or disabled; inference will be slower)" : ""}`,
);
for (const args of [
["sync", "--locked", ...syncArgs, ...pythonArgs],
...(windowsRocm
? [
["run", "--no-sync", "python", "scripts/setup.py", "--windows-prerequisites-only"],
["run", "--no-sync", "python", "-m", "backend.core.windows_rocm.install", "--uv", "uv"],
]
: []),
["run", "--no-sync", "python", "scripts/setup.py"],
]) {
const result = run("uv", args, { cwd: root, env: environment, stdio: "inherit" });
if (result.error) throw result.error;
if (result.status !== 0) return result.status ?? 1;
if (
(windowsRocm && args.includes("backend.core.windows_rocm.install")) ||
(!windowsRocm && args[0] === "sync")
) {
await repairNativeLibraries(root, platform, { env: environment });
}
}
return 0;
}
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
setupApi()
.then((code) => {
process.exitCode = code;
})
.catch((error) => {
console.error(`[setup] ${error.message}`);
process.exitCode = 1;
});
}