Closed sebastian-sz closed 5 hours ago
I think what you ultimately want is this (you need to edit yourself, not via uv add
):
[project]
name = "uv-torchmetrics"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
]
[project.optional-dependencies]
cpu = [
"torch>=2.5.1",
"torchvision>=0.20.1",
"torchmetrics",
]
cu124 = [
"torch>=2.5.1",
"torchvision>=0.20.1",
"torchmetrics",
]
[tool.uv]
conflicts = [
[
{ extra = "cpu" },
{ extra = "cu124" },
],
]
[tool.uv.sources]
torch = [
{ index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin'" },
{ index = "pytorch-cu124", extra = "cu124" },
]
torchvision = [
{ index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin'" },
{ index = "pytorch-cu124", extra = "cu124" },
]
torchmetrics = [
{ index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin'" },
{ index = "pytorch-cu124", extra = "cu124" },
]
[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true
[[tool.uv.index]]
name = "pytorch-cu124"
url = "https://download.pytorch.org/whl/cu124"
explicit = true
However, I think this is blocked on #9289. I'll come back to this once that issue is closed out.
Actually, sorry, I think what I posted above should work now?
@charliermarsh You are absolutely right. The above works. Thank you for the swift response!
Hi everyone. Thank you for the amazing work that has been done with uv and Pytorch integration.
I am following the official documentation to setup a Pytorch project. All works until I try to add a dependency that depends on Pytorch, e.g.
uv add torchmetrics
, which fails with:but running
uv pip install torchmetrics
works with no issues.To reproduce:
pyproject.toml
And the command:
uv add torchmetrics
Platform: Ubuntu 22.04 uv version: 0.5.3
If there is anything I could do to improve my workflow I'd appreciate the help!