From c208a4a76dee8e318f8d5d6b19ab05e90682c730 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sun, 9 Feb 2025 08:33:15 +1100 Subject: [PATCH 1/4] Fix cannot start app - uv cmd invalid URL --- src/constants.ts | 1 + src/virtualEnvironment.ts | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 87e796d3..542b4bd2 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -128,3 +128,4 @@ export enum DownloadStatus { export const CUDA_TORCH_URL = 'https://download.pytorch.org/whl/cu124'; export const NIGHTLY_CPU_TORCH_URL = 'https://download.pytorch.org/whl/nightly/cpu'; +export const DEFAULT_PYTHON_URL = 'https://pypi.org/simple/'; diff --git a/src/virtualEnvironment.ts b/src/virtualEnvironment.ts index 4743186f..71f239b8 100644 --- a/src/virtualEnvironment.ts +++ b/src/virtualEnvironment.ts @@ -6,7 +6,7 @@ import { rm } from 'node:fs/promises'; import os, { EOL } from 'node:os'; import path from 'node:path'; -import { CUDA_TORCH_URL, NIGHTLY_CPU_TORCH_URL } from './constants'; +import { CUDA_TORCH_URL, DEFAULT_PYTHON_URL, NIGHTLY_CPU_TORCH_URL } from './constants'; import type { TorchDeviceType } from './preload'; import { HasTelemetry, ITelemetry, trackEvent } from './services/telemetry'; import { getDefaultShell, getDefaultShellArgs } from './shell/util'; @@ -65,13 +65,14 @@ export function getPipInstallArgs(config: PipInstallConfig): string[] { * @returns The default torch mirror */ const getDefaultTorchMirror = (device: TorchDeviceType): string => { + log.debug('Falling back to default torch mirror'); switch (device) { case 'mps': return NIGHTLY_CPU_TORCH_URL; case 'nvidia': return CUDA_TORCH_URL; default: - return ''; + return DEFAULT_PYTHON_URL; } }; @@ -460,7 +461,7 @@ export class VirtualEnvironment implements HasTelemetry { const config: PipInstallConfig = { packages: ['torch', 'torchvision', 'torchaudio'], indexUrl: torchMirror, - prerelease: torchMirror?.includes('nightly'), + prerelease: torchMirror.includes('nightly'), }; const installArgs = getPipInstallArgs(config); From 8b48edf5d2ff3647d71fa32a435db64b731919ec Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sun, 9 Feb 2025 08:44:23 +1100 Subject: [PATCH 2/4] nit --- src/virtualEnvironment.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/virtualEnvironment.ts b/src/virtualEnvironment.ts index 71f239b8..8d46139d 100644 --- a/src/virtualEnvironment.ts +++ b/src/virtualEnvironment.ts @@ -64,7 +64,7 @@ export function getPipInstallArgs(config: PipInstallConfig): string[] { * @param device The device type * @returns The default torch mirror */ -const getDefaultTorchMirror = (device: TorchDeviceType): string => { +function getDefaultTorchMirror(device: TorchDeviceType): string { log.debug('Falling back to default torch mirror'); switch (device) { case 'mps': @@ -74,7 +74,7 @@ const getDefaultTorchMirror = (device: TorchDeviceType): string => { default: return DEFAULT_PYTHON_URL; } -}; +} /** * Manages a virtual Python environment using uv. From 2857d0f50adbff647b2e745d028917c032a38f19 Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sun, 9 Feb 2025 08:47:47 +1100 Subject: [PATCH 3/4] Ensure users do not use the CPU mirror for non-CPU installs --- src/virtualEnvironment.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/virtualEnvironment.ts b/src/virtualEnvironment.ts index 8d46139d..8dc299aa 100644 --- a/src/virtualEnvironment.ts +++ b/src/virtualEnvironment.ts @@ -76,6 +76,15 @@ function getDefaultTorchMirror(device: TorchDeviceType): string { } } +/** Disallows using the default mirror (CPU torch) when the selected device is not CPU. */ +function fixDeviceMirrorMismatch(device: TorchDeviceType, mirror: string | undefined) { + if (mirror === DEFAULT_PYTHON_URL) { + if (device === 'nvidia') return CUDA_TORCH_URL; + else if (device === 'mps') return NIGHTLY_CPU_TORCH_URL; + } + return mirror; +} + /** * Manages a virtual Python environment using uv. * @@ -146,7 +155,7 @@ export class VirtualEnvironment implements HasTelemetry { this.selectedDevice = selectedDevice ?? 'cpu'; this.pythonMirror = pythonMirror; this.pypiMirror = pypiMirror; - this.torchMirror = torchMirror; + this.torchMirror = fixDeviceMirrorMismatch(selectedDevice!, torchMirror); // uv defaults to .venv this.venvPath = path.join(venvPath, '.venv'); From 24a42cf9ddaa91547461994a5eab9acd9ae3586c Mon Sep 17 00:00:00 2001 From: filtered <176114999+webfiltered@users.noreply.github.com> Date: Sun, 9 Feb 2025 09:00:56 +1100 Subject: [PATCH 4/4] nit --- src/constants.ts | 2 +- src/virtualEnvironment.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 542b4bd2..5830a9db 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -128,4 +128,4 @@ export enum DownloadStatus { export const CUDA_TORCH_URL = 'https://download.pytorch.org/whl/cu124'; export const NIGHTLY_CPU_TORCH_URL = 'https://download.pytorch.org/whl/nightly/cpu'; -export const DEFAULT_PYTHON_URL = 'https://pypi.org/simple/'; +export const DEFAULT_PYPI_INDEX_URL = 'https://pypi.org/simple/'; diff --git a/src/virtualEnvironment.ts b/src/virtualEnvironment.ts index 8dc299aa..ba08baee 100644 --- a/src/virtualEnvironment.ts +++ b/src/virtualEnvironment.ts @@ -6,7 +6,7 @@ import { rm } from 'node:fs/promises'; import os, { EOL } from 'node:os'; import path from 'node:path'; -import { CUDA_TORCH_URL, DEFAULT_PYTHON_URL, NIGHTLY_CPU_TORCH_URL } from './constants'; +import { CUDA_TORCH_URL, DEFAULT_PYPI_INDEX_URL, NIGHTLY_CPU_TORCH_URL } from './constants'; import type { TorchDeviceType } from './preload'; import { HasTelemetry, ITelemetry, trackEvent } from './services/telemetry'; import { getDefaultShell, getDefaultShellArgs } from './shell/util'; @@ -72,13 +72,13 @@ function getDefaultTorchMirror(device: TorchDeviceType): string { case 'nvidia': return CUDA_TORCH_URL; default: - return DEFAULT_PYTHON_URL; + return DEFAULT_PYPI_INDEX_URL; } } /** Disallows using the default mirror (CPU torch) when the selected device is not CPU. */ function fixDeviceMirrorMismatch(device: TorchDeviceType, mirror: string | undefined) { - if (mirror === DEFAULT_PYTHON_URL) { + if (mirror === DEFAULT_PYPI_INDEX_URL) { if (device === 'nvidia') return CUDA_TORCH_URL; else if (device === 'mps') return NIGHTLY_CPU_TORCH_URL; }