mirror of
https://github.com/debpalash/VoiceStudio.git
synced 2026-12-04 09:28:22 +00:00
scripts/windows-rocm-recipe.json is the reviewed record of the interpreter the Windows ROCm wheels and HIP runtime were tested against. scripts/setup-api.mjs spelled the uv request out (cpython-3.12-windows-x86_64) and repeated 3.12 in its x64 error, and the desktop readiness constant spells it out again, so a recipe bump would leave both asking for an interpreter the recipe no longer pins. Add a shared helper that turns the recipe into the uv request and the displayed version, use it in the setup script, and add a test that runs the helper through node against the shipped recipe and compares it with the desktop constant. tests/test_windows_rocm_recipe_pin.py runs 3 passed; reverting the setup script makes it fail with "the ROCm branch retypes the interpreter version instead of reading the recipe".
103 lines
4.3 KiB
JavaScript
103 lines
4.3 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 { assertSupportedNode } from "../electron/scripts/node-version.mjs";
|
|
import { repairSourceNativeLibraries } from "../electron/scripts/native-compat.mjs";
|
|
import { asciiSafePthFiles } from "../electron/scripts/pth-ascii.mjs";
|
|
import {
|
|
selectTorchVariant,
|
|
torchSyncArgs,
|
|
windowsRocmSyncArgs,
|
|
} from "../electron/scripts/torch-variant.mjs";
|
|
import {
|
|
windowsRocmPythonRequest,
|
|
windowsRocmPythonVersion,
|
|
} from "../electron/scripts/windows-rocm-python.mjs";
|
|
|
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
|
|
/** Validate Node, then provision the selected local Python runtime. */
|
|
export async function setupApi({
|
|
nodeVersion = process.versions.node,
|
|
env = process.env,
|
|
platform = process.platform,
|
|
arch = process.arch,
|
|
run = spawnSync,
|
|
selectVariant = selectTorchVariant,
|
|
log = console.log,
|
|
repairNativeLibraries = repairSourceNativeLibraries,
|
|
healPthFiles = asciiSafePthFiles,
|
|
} = {}) {
|
|
assertSupportedNode(nodeVersion);
|
|
// PyTorch publishes no Intel-Mac wheels, so the locked sync can only fail
|
|
// part-way and leave an environment the app reports as incomplete (#3584).
|
|
if (platform === "darwin" && arch === "x64")
|
|
throw new Error(
|
|
"Intel Macs cannot install the local backend: PyTorch publishes no Intel-Mac (macOS x86_64) wheels. " +
|
|
"Connect the app to a VoiceStudio backend on another computer (docs/install/macos.md). " +
|
|
"On an Apple Silicon Mac, run this from a native arm64 terminal with an arm64 Bun or Node.",
|
|
);
|
|
const variant = await selectVariant({ env, platform, arch });
|
|
const windowsRocm = platform === "win32" && variant === "rocm";
|
|
// The reviewed interpreter comes from the recipe, never from a literal here.
|
|
const rocmRecipe = windowsRocm
|
|
? JSON.parse(readFileSync(resolve(root, "scripts/windows-rocm-recipe.json"), "utf8"))
|
|
: null;
|
|
if (windowsRocm && arch !== "x64")
|
|
throw new Error(
|
|
`Windows ROCm requires Windows x64 Python ${windowsRocmPythonVersion(rocmRecipe)} ` +
|
|
`(${rocmRecipe.python.abi}).`,
|
|
);
|
|
const environment = windowsRocm ? { ...env, OMNIVOICE_TORCH_VARIANT: "rocm" } : env;
|
|
// The matched torch stack has no native Windows ARM64 torchaudio wheel.
|
|
const pythonArgs = windowsRocm
|
|
? ["--python", windowsRocmPythonRequest(rocmRecipe)]
|
|
: 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"],
|
|
]) {
|
|
// uv starts the existing .venv interpreter before every command, and each
|
|
// sync rewrites the editable .pth with the checkout path. Under a non-ASCII
|
|
// folder on a non-UTF-8 Windows code page that interpreter cannot start
|
|
// (#1783), so heal before each call. Best effort: a failure must not block setup.
|
|
await healPthFiles(resolve(root, ".venv")).catch(() => []);
|
|
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;
|
|
});
|
|
}
|