Skip to content

Split any YouTube song into stems

TypeScript

gpu: CUDA 12.8 engine for Blackwell NVIDIA cards, torch.load shim, friendly crash messages (#20)

Daniel Ravinad181ee74b0d6
diff --git a/python/roformer.py b/python/roformer.py
index 07b1131..beef3cf 100644
--- a/python/roformer.py
+++ b/python/roformer.py
@@ -56,6 +56,18 @@ def fail(message):
sys.exit(1)
+def crash_message(e):
+ """top-level crash handler text: unreadable stderr tails (a bare python
+ traceback or an unrelated warnings.warn line) become actionable errors"""
+ msg = f"{e}"
+ if "no kernel image" in msg.lower():
+ return (
+ "GPU engine incompatible with this GPU (compute capability not supported by the "
+ "installed engine) — update StemKit or turn off GPU acceleration in Settings"
+ )
+ return msg[:400] or e.__class__.__name__
+
+
def load_wav(path):
try:
with wave.open(path, "rb") as w:
@@ -290,4 +302,9 @@ def main():
if __name__ == "__main__":
- main()
+ try:
+ main()
+ except SystemExit:
+ raise
+ except Exception as e:
+ fail(crash_message(e))
diff --git a/python/separate.py b/python/separate.py
index a333d34..d924680 100644
--- a/python/separate.py
+++ b/python/separate.py
@@ -17,6 +17,18 @@ def fail(message):
sys.exit(1)
+def crash_message(e):
+ """top-level crash handler text: unreadable stderr tails (a bare python
+ traceback or an unrelated warnings.warn line) become actionable errors"""
+ msg = f"{e}"
+ if "no kernel image" in msg.lower():
+ return (
+ "GPU engine incompatible with this GPU (compute capability not supported by the "
+ "installed engine) — update StemKit or turn off GPU acceleration in Settings"
+ )
+ return msg[:400] or e.__class__.__name__
+
+
def load_wav(path):
try:
with wave.open(path, "rb") as w:
@@ -67,6 +79,17 @@ def main():
import torch
import types
+ # torch>=2.6 defaults torch.load(weights_only=True), which rejects demucs's
+ # pickled full-model checkpoints (htdemucs.th / htdemucs_ft.th); restore
+ # the legacy behavior — the weights come from the official demucs releases
+ _torch_load = torch.load
+
+ def _load_any(*a, **k):
+ k.setdefault("weights_only", False)
+ return _torch_load(*a, **k)
+
+ torch.load = _load_any
+
import demucs.apply as dapply
raw_tqdm = dapply.tqdm
@@ -213,4 +236,9 @@ def main():
if __name__ == "__main__":
- main()
+ try:
+ main()
+ except SystemExit:
+ raise
+ except Exception as e:
+ fail(crash_message(e))
diff --git a/src/main/env.ts b/src/main/env.ts
index 516db60..8598de7 100644
--- a/src/main/env.ts
+++ b/src/main/env.ts
@@ -228,6 +228,45 @@ export function gpuVendorInfo(): GpuVendor | null | undefined {
return vendorInfo
}
+let nvidiaCapProbe: Promise<string | null> | null = null
+
+/* NVIDIA compute capability, e.g. "12.0" for an RTX 5090 (sm_120). Exposed by
+ nvidia-smi on driver 450+; null when absent or unreadable */
+export function detectNvidiaComputeCap(): Promise<string | null> {
+ if (!SUPPORTS_GPU) return Promise.resolve(null)
+ if (!nvidiaCapProbe) {
+ nvidiaCapProbe = runCapture(
+ 'nvidia-smi',
+ ['--query-gpu=compute_cap', '--format=csv,noheader'],
+ 10000
+ )
+ .then((out) => {
+ const m = out.match(/(\d+)\.(\d+)/)
+ return m ? `${m[1]}.${m[2]}` : null
+ })
+ .catch(() => null)
+ }
+ return nvidiaCapProbe
+}
+
+/* the torch build's CUDA runtime version, e.g. "12.1"; empty when unset or
+ the venv has no torch */
+async function torchCudaVersion(): Promise<string> {
+ return (
+ await runCapture(
+ venvPython(),
+ ['-c', 'import torch;print(torch.version.cuda or "")'],
+ 30000
+ ).catch(() => '')
+ ).trim()
+}
+
+function cudaVersionAtLeast(v: string, maj: number, min: number): boolean {
+ const m = v.match(/(\d+)\.(\d+)/)
+ if (!m) return false
+ return parseInt(m[1], 10) * 100 + parseInt(m[2], 10) >= maj * 100 + min
+}
+
/* venvs created before the roformer engine lack a few small packages;
verify and install them once per session */
export async function ensureEngineDeps(): Promise<boolean> {
@@ -760,6 +799,14 @@ function gfxOverride(gfx: string): string | null {
return null
}
+/* RTX 50-series and newer (compute capability 12.0/10.0) have no kernels in
+ cu121 torch — first launch dies with "no kernel image is available". The
+ cu128 build of torch 2.7.0 ships sm_100/120 kernels; every older NVIDIA
+ card stays on the long-tested 2.5.1 cu121 engine. torch 2.7 needs the
+ torch.load shim in separate.py (demucs ships pre-2.6 checkpoints) */
+const BLACKWELL_TORCH_VERSION = '2.7.0'
+const BLACKWELL_TORCH_INDEX = 'https://download.pytorch.org/whl/cu128'
+
/* the HSA override computed by the AMD preflight must survive restarts: the
informational gpu probe (torch.cuda.is_available) passes without it, so a
fresh session would otherwise skip the preflight and ship an override-less
@@ -797,8 +844,6 @@ export function ensureGpuEngine(
}
if (!gpuEnginePromise) {
gpuEnginePromise = (async () => {
- // already swapped in: the venv's torch speaks to a GPU, nothing to install
- if (await hasGpuAcceleration()) return true
// the Settings toggle is only rendered when a GPU was detected, but a
// stale setting or a failed probe could still land here — don't pull
// ~2.5GB of GPU torch on a machine that can't use it
@@ -813,7 +858,26 @@ export function ensureGpuEngine(
// no ROCm wheels for windows: an AMD card there stays on CPU
if (vendor === 'amd' && IS_WIN) return false
const label = vendor === 'amd' ? 'AMD' : 'NVIDIA'
- sendEnvEvent(`Downloading the ${label} GPU engine (~2.5GB, one time)`)
+ // wheel selection: Blackwell-class NVIDIA cards (compute cap 10+)
+ // need the cu128 build; anything already installed from cu121 must be
+ // upgraded to it. Without this, the early-return below would leave the
+ // older engine in place and separation would die mid-split
+ let torchVersion = GPU_TORCH_VERSION
+ let torchIndex = GPU_TORCH_INDEX[vendor]
+ let sizeLabel = '~2.5GB'
+ let needUpgrade = false
+ if (vendor === 'nvidia') {
+ const capMajor = parseInt(((await detectNvidiaComputeCap()) ?? '').split('.')[0], 10)
+ if (!Number.isNaN(capMajor) && capMajor >= 10) {
+ torchVersion = BLACKWELL_TORCH_VERSION
+ torchIndex = BLACKWELL_TORCH_INDEX
+ sizeLabel = '~3GB'
+ needUpgrade = !(await cudaVersionAtLeast(await torchCudaVersion(), 12, 8))
+ }
+ }
+ // already swapped in: the venv's torch speaks to a GPU, nothing to install
+ if (!needUpgrade && (await hasGpuAcceleration())) return true
+ sendEnvEvent(`Downloading the ${label} GPU engine (${sizeLabel}, one time)`)
await new Promise<void>((resolve, reject) => {
const child = spawn(
venvPython(),
@@ -826,10 +890,10 @@ export function ensureGpuEngine(
// the gpu build
'-U',
'--no-cache-dir',
- `torch==${GPU_TORCH_VERSION}`,
- `torchaudio==${GPU_TORCH_VERSION}`,
+ `torch==${torchVersion}`,
+ `torchaudio==${torchVersion}`,
'--index-url',
- GPU_TORCH_INDEX[vendor]
+ torchIndex
],
{ env: { ...process.env } }
)
diff --git a/src/renderer/src/components/Settings.tsx b/src/renderer/src/components/Settings.tsx
index a82486c..f8bfa09 100644
--- a/src/renderer/src/components/Settings.tsx
+++ b/src/renderer/src/components/Settings.tsx
@@ -271,7 +271,10 @@ export function Settings({ settings, gpu, gpuVendor, onChange, onClose }: Props)
</p>
<DownloadBar pct={gpuPct} starting={gpuBusy && gpuPct === null} error={gpuError} />
{showGpuConfirm && (
- <ConfirmButton label="Download now · ~2.5 GB" onClick={startGpu} />
+ <ConfirmButton
+ label={gpuVendor === 'amd' ? 'Download now · ~2.5 GB' : 'Download now · ~3 GB'}
+ onClick={startGpu}
+ />
)}
</div>
<Toggle