uv: Cannot install the CPU version of torch

I tried to install the CPU version of torch but could not.

uv pip install torch==2.1.0+cpu --find-links https://download.pytorch.org/whl/torch_stable.html
# and next command gives the same result.
uv pip install torch==2.1.0 --index-url https://download.pytorch.org/whl/cpu
  × No solution found when resolving dependencies:
  ╰─▶ Because there is no version of torch==2.1.0+cpu and you require torch==2.1.0+cpu, we can conclude that the requirements are unsatisfiable.

uv version: v0.1.2 Python 3.11.7 Ubuntu 20.4 X86_64 Architecture


By the way, the install of the GPU version of torch is successful.

uv pip install torch==2.1.0
# success

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 35 (15 by maintainers)

Most upvoted comments

This should work as of the latest release:

@charliermarsh do you have any plans to add support for the most common case? uv pip install torch==2.1.0 --index-url https://download.pytorch.org/whl/cpu

The problem here is the behavior for installing CPU-only torch is different on arm64/aarch64 and x86_64/amd64 systems.

  • amd64 requires us to explicitly provide torch==x.x.x+cpu
  • meanwhile for arm64 we don’t need the moniker.

On amd64,

$ arch
x86_64


$ uv pip install torch==2.3.0 --index-url https://download.pytorch.org/whl/cpu
  × No solution found when resolving dependencies:
  ╰─▶ Because torch==2.3.0 is unusable because no wheels are available with a matching Python ABI and you require torch==2.3.0, we can conclude that the requirements are unsatisfiable.


# with +cpu moniker
$ uv pip install torch==2.3.0+cpu --index-url https://download.pytorch.org/whl/cpu
Resolved 9 packages in 4.33s
Downloaded 9 packages in 2.90s
Installed 9 packages in 114ms
 + filelock==3.13.1
 + fsspec==2024.2.0
 + jinja2==3.1.3
 + markupsafe==2.1.5
 + mpmath==1.3.0
 + networkx==3.2.1
 + sympy==1.12
 + torch==2.3.0+cpu
 + typing-extensions==4.9.0

On arm64, adding the +cpu fails & without it installs.

~ arch
arm64


# with +cpu moniker
~ uv pip install torch==2.3.0+cpu --index-url https://download.pytorch.org/whl/cpu
  × No solution found when resolving dependencies:
  ╰─▶ Because torch==2.3.0+cpu is unusable because no wheels are available with a matching Python ABI and you require torch==2.3.0+cpu, we can conclude that the requirements are
      unsatisfiable.


# without the moniker
~ uv pip install torch==2.3.0 --index-url https://download.pytorch.org/whl/cpu
Resolved 9 packages in 3.58s
Installed 9 packages in 210ms
 + filelock==3.13.1
 + fsspec==2024.2.0
 + jinja2==3.1.3
 + markupsafe==2.1.5
 + mpmath==1.3.0
 + networkx==3.2.1
 + sympy==1.12
 + torch==2.3.0
 + typing-extensions==4.9.0

uv has known limitations around local version identifiers but unsure why pip is able to make this work the way pytorch has documented https://pytorch.org/get-started/previous-versions/#v222 but uv can’t

Do you mind creating a new issue so that I remember to follow-up?

Perhaps it’s due to a lack of supported variants that they omitted the local identifier there? (here upstream PyTorch states they don’t intend to publish aarch64 variants with GPU accel)

# Torch 2.3.0 + Python 3.12 Linux x86_64/aarch64 wheels

# +cpu
# https://download.pytorch.org/whl/cpu/torch/
torch-2.3.0+cpu-cp312-cp312-linux_x86_64.whl
# No local identifier for arm64:
torch-2.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

# +cu121
# https://download.pytorch.org/whl/cu121/torch/
torch-2.3.0+cu121-cp312-cp312-linux_x86_64.whl

Reference

Using Docker from an AMD64 machine to test ARM64 environment:

# Base environment:
$ arch
x86_64
$ docker run --rm -it --platform linux/arm64 --workdir /tmp fedora:40 bash
$ arch
aarch64

# Install uv:
$ curl -LsSf https://astral.sh/uv/install.sh | sh && source $HOME/.cargo/env
# Create and enter venv:
$ uv venv && source .venv/bin/activate

# Install:
$ uv pip install \
    --extra-index-url https://download.pytorch.org/whl/cpu \
    torch torchvision torchaudio

Resolved 13 packages in 20.18s
Downloaded 13 packages in 12.26s
Installed 13 packages in 486ms
 + filelock==3.13.1
 + fsspec==2024.2.0
 + jinja2==3.1.3
 + markupsafe==2.1.5
 + mpmath==1.3.0
 + networkx==3.2.1
 + numpy==1.26.3
 + pillow==10.2.0
 + sympy==1.12
 + torch==2.3.0
 + torchaudio==2.3.0
 + torchvision==0.18.0
 + typing-extensions==4.9.0

You can kind of see why PyTorch has local identifier variants when comparing to PyPi?:

# ARM64 (PyPi instead of PyTorch)
# Slightly newer versions of the packages but otherwise equivalent
$ uv pip install torch torchvision torchaudio

Resolved 13 packages in 1.08s
Downloaded 13 packages in 23.73s
Installed 13 packages in 425ms
 + filelock==3.14.0
 + fsspec==2024.3.1
 + jinja2==3.1.4
 + markupsafe==2.1.5
 + mpmath==1.3.0
 + networkx==3.3
 + numpy==1.26.4
 + pillow==10.3.0
 + sympy==1.12
 + torch==2.3.0
 + torchaudio==2.3.0
 + torchvision==0.18.0
 + typing-extensions==4.11.0
# AMD64 (PyPi instead of PyTorch)
# Defaults to latest cuda variant (+cu121)
# Same nvidia specific deps as PyTorch +cu121, except for nvidia-nvjitlink-cu12 (Cuda 12.4 here instead of 12.1)
$ uv pip install torch torchvision torchaudio

Resolved 25 packages in 558ms
Downloaded 25 packages in 53.62s
Installed 25 packages in 189ms
 + filelock==3.14.0
 + fsspec==2024.3.1
 + jinja2==3.1.4
 + markupsafe==2.1.5
 + mpmath==1.3.0
 + networkx==3.3
 + numpy==1.26.4
 + nvidia-cublas-cu12==12.1.3.1
 + nvidia-cuda-cupti-cu12==12.1.105
 + nvidia-cuda-nvrtc-cu12==12.1.105
 + nvidia-cuda-runtime-cu12==12.1.105
 + nvidia-cudnn-cu12==8.9.2.26
 + nvidia-cufft-cu12==11.0.2.54
 + nvidia-curand-cu12==10.3.2.106
 + nvidia-cusolver-cu12==11.4.5.107
 + nvidia-cusparse-cu12==12.1.0.106
 + nvidia-nccl-cu12==2.20.5
 + nvidia-nvjitlink-cu12==12.4.127
 + nvidia-nvtx-cu12==12.1.105
 + pillow==10.3.0
 + sympy==1.12
 + torch==2.3.0
 + torchaudio==2.3.0
 + torchvision==0.18.0
 + typing-extensions==4.11.0

Resolve platform packaging inconsistency upstream

Maybe open an issue about it upstream since it seems to be more of a packaging concern unrelated to uv?:

https://github.com/pytorch/pytorch/issues/110791#issuecomment-1753334468

please do not hesitate to open a new issue (or a PR) if you want to propose dropping +cpu suffix for Linux and Windows wheels, as nobody seems to be relying on the old installation method anyway.

Which makes sense that CPU should be the default, with local identifiers only used for actual variants (eg: different cuda version support). Might introduce some friction to any existing CI perhaps, but you can see similar with nvidia’s own Docker images they publish where the naming convention isn’t always consistent 😅 (at least it broke a PyTorch docker build CI task recently)

Can you confirm that the environment you’re in is using Python 3.10, and that you’re on x86 Linux or Windows?

Ops, sorry, I am on ARM macOS. You are right.

uv pip install torch==2.1.0 --index-url https://download.pytorch.org/whl/cpu

This works for me! py3.10 and latest uv 0.1.35.

This should work as of the latest release:

uv pip install torch==2.1.0+cpu --find-links https://download.pytorch.org/whl/torch_stable.html

On the other hand, this raises:

uv pip install torch==2.1.0+cpu --find-links https://download.pytorch.org/whl/torch_stable.html
  × No solution found when resolving dependencies:
  ╰─▶ Because torch==2.1.0+cpu is unusable because no wheels are available with a matching Python implementation and you require torch==2.1.0+cpu, we can conclude that the requirements are unsatisfiable.

EDIT: for this last command I also tried with the latest stable uv, 0.1.39.

Thanks @baskervilski - that makes sense to me actually (that it works), I believe the bug here relates to our handling of local versions which we’ll need to fix.

Ok, found a workaround(?), using the --override option:

I created the overrides.txt file with the following content

# overrides.txt
torch==2.1.1+cpu
torchvision==0.16.1+cpu

Then called: uv pip compile pyproject.toml -o requirements.txt --override overrides.txt and uv pip install -e . --override overrides.txt

For now I can live with this.

I’m actually going on a two-day trip starting today. So I won’t be able to check it until after that. Sorry about that. If anyone is tracking this issue, I would be grateful if you could check on my behalf.

I got you fam 👌