❯ uv sync --dry-run Discovered existing environment at: .venv Resolved 107 packages in…
- User
❯ uv sync --dry-run
Discovered existing environment at: .venv Resolved 107 packages in 0.89ms Found up-to-date lockfile at: uv.lock Would uninstall 2 packages Would install 1 package- torch==2.7.1+cu126
- torch==2.7.1
- torch==2.7.1+cu126
I have this issue, every time I try to run anything using uv run, for some reason, it uninstall and reinstall pytorch, how can I update pyproject.toml or the uv.lock so that it doesn't happen anymore ?
- Assistant
The short version
uvdoesn’t really know which variant of PyTorch you want.
Your lock-file only says “torch == 2.7.1”, but the wheel that gets downloaded for your platform is actually
“torch == 2.7.1 + cu126”.
Because “2.7.1” and “2.7.1+cu126” are considered different builds,uv syncthinks the environment is out of date, so every run ends up doing:- uninstall the wheel it finds (2.7.1 + cu126)
- reinstall the wheel that solves the lock (which, again, is 2.7.1 + cu126)
- …repeat for ever 🙃
Pin the exact build you want (or upgrade
uv, see below) and the loop stops.Why it happens (a quick explainer)
PEP 440 treats the bit after a “+” as a local version:
• 2.7.1 and
• 2.7.1+cu126are considered the same public version, but different builds.
uv lockwrites only the public part (“2.7.1”) whileuv syncrecords the full string it actually installed (“2.7.1+cu126”).
Next time it compares lock vs env → mismatch → reinstall.How to fix it
1. Upgrade
uvfirst (the bug is fixed in recent releases)# Pick the method you originally used: cargo install --locked uv # Rust pipx install --force uv # pipx brew upgrade uv # Homebrew # check uv --versionAnything ≥ 0.2.4 correctly preserves the local version segment in the lock-file, so simply regenerating the lock is usually enough:
rm uv.lock # or `uv lock --recreate` once that sub-command lands uv sync --write-lockNow a second
uv sync --dry-runshould print:Found up-to-date lock-file at: uv.lock All good – nothing to do 🎉2. (If you can’t upgrade) pin the variant explicitly
Edit
pyproject.toml(orrequirements.in) so that the dependency says exactly what you want:[project] dependencies = [ # GPU build "torch==2.7.1+cu126", # or, if you really want the CPU wheel: # "torch==2.7.1", ]If you use the PyTorch CUDA wheels hosted on the PyTorch index, also give
uvthat URL so it can reliably find the same file every time:[tool.uv.indexes] pytorch = { url = "https://download.pytorch.org/whl/cu126", priority = "default" }Then rebuild the lock-file:
rm uv.lock uv sync --write-lock(Deleting the virtual-env once is often the easiest way to get a clean start:
rm -rf .venv && uv venv .venv && uv sync.)Take-aways
• Local-version segments (
+cuXXX) matter; pin them if you care.
• Neweruvversions already keep them in the lock-file, so upgrading is usually enough.
• After regeneratinguv.lock, a seconduv sync --dry-runshould show zero actions.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.