Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uv lock locks incorrect torch cpu version on macOS #9209

Closed
MKVatinyan opened this issue Nov 18, 2024 · 6 comments
Closed

uv lock locks incorrect torch cpu version on macOS #9209

MKVatinyan opened this issue Nov 18, 2024 · 6 comments
Labels
question Asking for clarification or support

Comments

@MKVatinyan
Copy link

  • uv version : uv 0.5.2 (195f4b6 2024-11-14)
  • running on macOS 15.0.1, m1 chip, 2020

I am following a very simple workflow to test this situation :

  1. run uv init torch-uv
  2. add torch, torchaudio to pyproject.toml
[project]
name = "torch-uv"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
    "torch>=2.4, <2.5"
]

[tool.uv.sources]
torch = { index = "torch-cpu"}

[[tool.uv.index]]
name = "torch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true
  1. create .venv with uv venv
  2. install project with uv pip install .. When i run uv pip show torch i get Version: 2.4.1. I can successfully source .venv/bin/activate and run python, import torch etc.
  3. i run uv lock. Here is the problem, in the lock file i have
[[package]]
name = "torch"
version = "2.4.1+cpu"
  1. when i run uv run python i error with error: Distribution torch==2.4.1+cpu @ registry+https://download.pytorch.org/whl/cpu` can't be installed because it doesn't have a source distribution or wheel for the current platform`

If repeat the same process by having only "torchaudio>=2.4, <2.5" in my dependencies, torch will be downloaded but the lock file will be correct, without the +cpu. Am i missing something here ?

@MKVatinyan MKVatinyan changed the title uv lock locks incorrect torch version on macOS uv lock locks incorrect torch cpu version on macOS Nov 18, 2024
@charliermarsh
Copy link
Member

Unfortunately this is correct. Torch doesn't publish +cpu wheels for macOS. They expect you to just use the 2.4.1 without +cpu. But if you resolve against the https://download.pytorch.org/whl/cpu index, then it's correct to choose the +cpu version. It's a duplicate of #5182.

@charliermarsh
Copy link
Member

charliermarsh commented Nov 18, 2024

One option:

[project]
name = "torch-uv"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
    "torch>=2.4, <2.5"
]

[tool.uv.sources]
torch = { index = "torch-cpu", marker = "sys_platform != 'darwin'" }

[[tool.uv.index]]
name = "torch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true

@charliermarsh
Copy link
Member

Another:

[project]
name = "torch-uv"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
    "torch==2.4.1+cpu ; sys_platform != 'darwin'",
    "torch===2.4.1 ; sys_platform == 'darwin'"
]

[tool.uv.sources]
torch = { index = "torch-cpu" }

[[tool.uv.index]]
name = "torch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true

@charliermarsh
Copy link
Member

A third:

[project]
name = "torch-uv"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
    "torch==2.4.1",
    "torch!=2.4.1+cpu ; sys_platform == 'darwin'"
]

[tool.uv.sources]
torch = { index = "torch-cpu" }

[[tool.uv.index]]
name = "torch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true

@charliermarsh charliermarsh added the question Asking for clarification or support label Nov 18, 2024
@MKVatinyan
Copy link
Author

thanks you very much ! solved

@charliermarsh
Copy link
Member

No prob. I'm working on comprehensive docs for this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for clarification or support
Projects
None yet
Development

No branches or pull requests

2 participants