Skip to content
TheChatArchiveThe Chat Archive
o3-2025-04-16· OpenAIHugging Face LMArena Human Preference 140K

❯ uv sync --dry-run Discovered existing environment at: .venv Resolved 107 packages in…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with DeepSeekdeepseek-r1-0528’s answer.
  1. 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 ?

  2. Assistant

    The short version

    uv doesn’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 sync thinks the environment is out of date, so every run ends up doing:

    1. uninstall the wheel it finds (2.7.1 + cu126)
    2. reinstall the wheel that solves the lock (which, again, is 2.7.1 + cu126)
    3. …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+cu126

    are considered the same public version, but different builds.
    uv lock writes only the public part (“2.7.1”) while uv sync records 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 uv first (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 --version
    

    Anything ≥ 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-lock
    

    Now a second uv sync --dry-run should 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 (or requirements.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 uv that 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.
    • Newer uv versions already keep them in the lock-file, so upgrading is usually enough.
    • After regenerating uv.lock, a second uv sync --dry-run should show zero actions.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.