Skip to content

Configuring accelerators with optional dependencies does not work with build system #9259

@eginhard

Description

@eginhard

Thank you for the improvements for installing Pytorch! The example at https://docs.astral.sh/uv/guides/integration/pytorch/#configuring-accelerators-with-optional-dependencies works great. But it fails when I add a build system:

uv run --extra cpu python
  × Failed to build `project @ file:///home/.../project`
  ╰─▶ Source entry for `torch` only applies to extra `cpu`, but the `cpu` extra does not
      exist. When an extra is present on a source (e.g., `extra = "cpu"`), the relevant
      package must be included in the `project.optional-dependencies` section for that extra
      (e.g., `project.optional-dependencies = { "cpu" = ["torch"] }`).

Running on Ubuntu with uv 0.5.3. This is the pyproject.toml, with only the first 3 lines added to the example.

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[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'" },
  { index = "pytorch-cu124", extra = "cu124" },
]
torchvision = [
  { 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions