How to specify uv indices with prerelease?

I’m trying to automate how users will get their pytorch version in the pyproject, using uv.

Currently, the sources look like this:

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


[[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

which installs the correct torch on windows, linux, macos and also mac os on docker containers which may use linux/arm64.

but I want to install the pre-release as well, from a specific index. I can do it with pip using:

(pkg) a@b pkg % python -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu 

My idea was to add an extra index, without any extra:

[project.optional-dependencies]
prelease = ["torch"]
cpu = ["torch>=2.5.1"]
cu124 = ["torch>=2.5.1"]


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

[tool.uv.sources]
torch = [
    { index = "pytorch-prelease", extra = "prelease", marker = "platform_system=='Darwin' and platform_machine=='aarch64'" },
    { index = "pytorch-cpu", extra = "cpu", marker = "platform_system != 'Darwin' and platform_machine != 'aarch64'" },
    { index = "pytorch-cu124", extra = "cu124", marker = "platform_system != 'Darwin' and platform_machine != 'aarch64'" },
]


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

[[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, this downloads multiple dev versions.

How should this be done?

When issuing the install command, even in a simpler case, where I install the non-prerelease, and then issue:

uv lock -P torch --index https://download.pytorch.org/whl/nightly/cpu  --prerelease allow
Ignoring existing lockfile due to change in pre-release mode: `if-necessary-or-explicit` vs. `allow`

It returns:

⠸ pycparser==2.22                                                                                                                                                   
torchvision ------------------------------ 3.36 MiB/14.13 MiB
torchvision ------------------------------ 3.25 MiB/14.13 MiB
torchvision ------------------------------ 3.00 MiB/14.13 MiB
torchvision ------------------------------ 3.00 MiB/14.13 MiB
torch      ------------------------------ 5.00 MiB/63.47 MiB
torch      ------------------------------ 5.58 MiB/63.48 MiB
torch      ------------------------------ 5.56 MiB/63.48 MiB
torch      ------------------------------ 5.23 MiB/63.48 MiB
torch      ------------------------------ 3.25 MiB/113.45 MiB
torch      ------------------------------ 2.75 MiB/113.46 MiB
torch      ------------------------------ 3.18 MiB/113.46 MiB
torch      ------------------------------ 3.00 MiB/113.65 MiB                                                                                                       

There seems to be a lot of duplication.

And these are all the versions it downloads:

Updated torch v2.5.1, v2.5.1+cpu, v2.5.1+cu124 -> v2.5.1, v2.5.1+cpu, v2.5.1+cu124, v2.6.0.dev20241216+cpu
Updated torchvision v0.20.1, v0.20.1+cpu, v0.20.1+cu124 -> v0.20.1+cpu, v0.20.1+cu124, v0.22.0.dev20241216+cpu