Repository navigation
Install torch per machine for an app that leaves it out of its lock - #45
Merged
Merged
Conversation
An app can leave torch out of uv.lock ([tool.uv] exclude-dependencies, recorded as [manifest] excludes) so each machine gets the build for its GPU. Setup only handled a locked torch: otherwise it ran an exact uv sync, which installed no torch on a first run and removed one installed by hand on every upgrade, and the backend died on import. Setup now reads the exclusion from the lock and, on every platform, syncs inexactly (an installed torch survives, nothing re-downloads), installs the app, then probes the env's torch: kept when it loads and has kernels for the GPU, installed with --torch-backend=auto when missing, reinstalled when it does not load, upgraded when it has no kernels for the GPU (2.6.0+cu124 on sm_120). A failed install is said in the overlay, not thrown: the backend starts, and the stamp is dropped so the next launch retries. From a wheelhouse torch comes from the folder or not at all. installTorchPerMachine works without a pin and takes reinstall/upgrade for a Fix button. A locked torch is unchanged. Claude-Session: https://claude.ai/code/session_01DzXsKAUJSM4XYpqqzrcuV5
…rogress
Per machine now needs the app to declare torch (a requires-dist entry)
as well as exclude it from the lock; torch merely absent from the lock
is an app with none, so Ground Crew keeps its exact sync and no pill.
Setup, the two-step and the setup window's PyTorch step all take the
case from readTorchSetup (setupHasTorchStep for the start message).
The requirement parser also missed a bare `{ name = "torch" }` entry,
which is how Autopilot's lock writes it.
A progress line rebuilt the setup state without the torch and
wheelhouse the start had set, so the pill came back for an app with no
torch and an offline install lost its folder line (#44). It now keeps
the rest of the state.
Claude-Session: https://claude.ai/code/session_01DzXsKAUJSM4XYpqqzrcuV5
…oading uv's --torch-backend=auto reads only the driver version, so a recent driver on a card older than sm_70 (Pascal, Maxwell) got a cu128+ build with no kernels for it. Read the compute capability from nvidia-smi first and use cu126 for such a card; <APPID>_TORCH_BACKEND overrides the choice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
An app can leave torch out of
uv.lock([tool.uv] exclude-dependencies = ["torch"], recorded in the lock as[manifest] excludes) so each machine gets the torch build for its GPU. A locked build can't serve every GPU: 2.6.0+cu124 has no kernels for sm_120. Setup decided "this app uses torch" asreadLockedTorchVersion(projectDir) !== null, treating "torch not in the lock" the same as "no torch". So an app like this got an exactuv sync: no torch on its first run, a hand-installed torch removed on every upgrade, and a backend that died on import (Autopilot, on a lab PC, 2026-11-16).Three cases
Michael Spilman's analysis in #30 (item 2) and #44 is the starting point: an app with no torch (Ground Crew) must show no PyTorch step, and the setup state must keep that through every progress line. This PR keeps his behavior for no-torch apps and separates the case that was being mistaken for it. One function,
readTorchSetup, decides the case for both setup and the setup window (setupHasTorchStepfor the start message'storchflag):uv sync, as todaytorch==<locked> --torch-backend=auto), unchangedrequires-dist) and excludes it from the lock ([manifest] excludes)uv sync --inexact, so an installed torch survives an upgrade and nothing re-downloads; then the app wheels; then a torch check (below)Exact sync stays the rule for the first two cases; only per-machine apps sync inexactly.
In the per-machine case, the check asks the env's Python (
python -I):uv pip install --no-config <requirement> --torch-backend=auto, where<requirement>istorchplus any version specifier the app declared.--reinstall-package torch.--upgrade-package torch, which does nothing when uv has no newer build, so it doesn't loop on every upgrade.--no-configkeeps the app's lock-time[tool.uv]settings out of the torch install (prerelease = "allow"would let a torch release candidate in).A failed torch install is reported in the overlay, not thrown: the backend starts and can say what it lacks, and the env stamp is removed so the next launch tries again. From a wheelhouse, torch comes from the wheelhouse folder or not at all, with a message saying what to do.
installTorchPerMachineworks without atorch==pin and takes{ reinstall }or{ upgrade }, so a "Fix PyTorch" button can replace a torch of the wrong build.Fixes #44:
ENV_SETUP_PROGRESSnow spreadsprev, sotorchandwheelhousefromENV_SETUP_STARTsurvive progress lines and a later failure, using Michael's proposed fix and test. Addresses #30 item 2: the pill decision now comes from the three cases above, so Ground Crew stays pill-free and Autopilot shows it.Tests
npm run typecheck: clean.npm run test:unit: 228 tests, 227 pass, 1 skipped (pre-existing), 0 fail. New tests cover each case:readTorchSetup: none, locked, per machine, and torch excluded but not declared (counts as none)setupHasTorchStepfor each casetorchInstallArgs, including no pin, reinstall, upgrade and wheelhouseensureTorchPerMachineuv run pytest: 138 passed.readTorchSetupgives Ground Crewnone, SpyDElocked 2.6.0, Autopilotper-machine.resolvePythonEnv:Pascal and other cards older than sm_70.
--torch-backend=autolooks only at the driver version, so on this driver it picks cu129, which has no sm_61 kernels; the first GPU operation fails even thoughtorch.cuda.is_available()is True. Setup now chooses the backend before downloading (torchBackend): it readsnvidia-smi --query-gpu=compute_cap, and a card below 7.0 gets cu126; otherwiseauto.<APPID>_TORCH_BACKENDoverrides it. Checked on the TITAN X: the probe picks cu126, one download installs 2.14.1+cu126 (sm_50 to sm_90), and a 2048x2048 matmul runs on the GPU. Unit tests: 232 passed, 1 skipped.Merging with #38
A trial merge with #38's head (30500e5) is clean: no conflicting files, and the merged tree typechecks and passes its tests. The two PRs edit neighboring code in
pythonEnv.ts(the stamp build,uvEnv,installAppWheelthere; the stamp write,setupEnvand new functions here) but never the same lines. Once both are in, the torch check doesn't need #38'swithoutPythonRedirects, becausepython -Ialready ignores PYTHONPATH and PYTHONHOME.