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

Configuring accelerators with optional dependencies and PyPI #9295

Closed
eginhard opened this issue Nov 20, 2024 · 5 comments · Fixed by #9302
Closed

Configuring accelerators with optional dependencies and PyPI #9295

eginhard opened this issue Nov 20, 2024 · 5 comments · Fixed by #9302
Assignees
Labels
bug Something isn't working

Comments

@eginhard
Copy link

Thank you for the quick fix for #9259! I have one more issue, but not sure if it's user error in this case. I removed the custom pytorch-cu214 index from the example at https://docs.astral.sh/uv/guides/integration/pytorch/#configuring-accelerators-with-optional-dependencies so that for the cu214 extra uv should just install whatever it gets from PyPI, i.e. CPU for Mac and Windows.

[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12.0"
dependencies = []

[project.optional-dependencies]
cpu = [
  "torch>=2.5.1",
  "torchvision>=0.20.1",
]
cu124 = [
  "torch>=2.5.1",
  "torchvision>=0.20.1",
]

[tool.uv]
conflicts = [
  [
    { extra = "cpu" },
    { extra = "cu124" },
  ],
]

[tool.uv.sources]
torch = [
  { index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin'" },
]
torchvision = [
  { index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin'" },
]

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

Now running uv sync --extra cpu with uv 0.5.4 on Ubuntu results in:

Resolved 29 packages in 866ms
error: Distribution `torch==2.5.1 @ 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
@charliermarsh
Copy link
Member

I think I see why this happening, though it's fairly complicated.

@charliermarsh charliermarsh added the bug Something isn't working label Nov 20, 2024
@charliermarsh
Copy link
Member

I think this might work?

[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12.0"
dependencies = []

[project.optional-dependencies]
cpu = [
  "torch===2.5.1 ; platform_system == 'Darwin'",
  "torch==2.5.1+cpu ; platform_system != 'Darwin'",
  "torchvision>=0.20.1",
]
cu124 = [
  "torch>=2.5.1",
  "torchvision>=0.20.1",
]

[tool.uv]
conflicts = [
  [
    { extra = "cpu" },
    { extra = "cu124" },
  ],
]

[tool.uv.sources]
torch = [
  { index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin'" },
]
torchvision = [
  { index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin'" },
]

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

@charliermarsh
Copy link
Member

But it should probably work as-is, with your configuration.

@eginhard
Copy link
Author

Yes, that works (when leaving out torchvision or I guess doing the same there). But then only a single version can be specified.

@charliermarsh
Copy link
Member

Yeah I gotta think on the right way to solve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants