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

Installing PyTorch: An index URL could not be queried #8344

Open
Leon0402 opened this issue Oct 18, 2024 · 8 comments
Open

Installing PyTorch: An index URL could not be queried #8344

Leon0402 opened this issue Oct 18, 2024 · 8 comments

Comments

@Leon0402
Copy link

Setup is:

uv init
uv venv --python 3.10

Leading to the simple pyproject.toml:

[project]
name = "test2"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"

Trying to install torch with:

uv add torch torchvision torchaudio --default-index https://download.pytorch.org/whl/cu118

leads to the error:

error: Distribution `torchaudio==2.0.0 @ registry+https://download.pytorch.org/whl/cu118` can't be installed because it doesn't have a source distribution or wheel for the current platform

Alternatively using pip:

uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

leads to a different error:

⠋ lit==15.0.7                                                                                                                                                                     × Failed to download and build `lit==15.0.7`
  ├─▶ Failed to resolve requirements from `build-system.requires`
  ├─▶ No solution found when resolving: `setuptools>=40.8.0`, `wheel`
  ╰─▶ Because wheel was not found in the package registry and you require wheel, we can conclude that your requirements are unsatisfiable.

      hint: An index URL (https://download.pytorch.org/whl/cu118) could not be queried due to a lack of valid authentication credentials (403 Forbidden).

I am on a Linux System and use uv 0.4.24.

Using virtualenv and normal pip works fine, thus I suspect a problem with uv here.

@charliermarsh
Copy link
Member

You probably need torchaudio==2.0.0+cu118 and the same for torchvision and torch.

@charliermarsh
Copy link
Member

The hint at the end looks like a red herring. I guess the PyTorch index is (for some reason) returning a 403 for packages that aren't found, which seems wrong to me, but that's a PyTorch bug:

❯ curl https://download.pytorch.org/whl/cu118/wheel
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>2KHYSPNC38BWED53</RequestId><HostId>ZeNiFBKyzFyAMNNKZisld1Oxq9ZnHyJ9oOroNvEfZKp6iibw+ma7UpFTmg5Fs5EFZ//XafwMZ3k=</HostId></Error>%

@Leon0402
Copy link
Author

You probably need torchaudio==2.0.0+cu118 and the same for torchvision and torch.

That seems to work. And it is necessary because of the pytorch bug? Because in theory pip should be able to find that version itself automatically, right?
Can uv deal with the incorrectly returned 403 anyway?

@Leon0402
Copy link
Author

Leon0402 commented Oct 18, 2024

@charliermarsh My bad, actually doesn't work.

uv pip install torch==2.0.0+cu118 torchvision==0.15.0+cu118 torchaudio==2.0.0+cu118 --index-url https://download.pytorch.org/whl/cu118

Same error as before.

@FishAlchemist
Copy link
Contributor

FishAlchemist commented Oct 18, 2024

@charliermarsh My bad, actually doesn't work.

uv pip install torch==2.0.0+cu118 torchvision==0.15.0+cu118 torchaudio==2.0.0+cu118 --index-url https://download.pytorch.org/whl/cu118

Same error as before.

@Leon0402 Use --extra-index-url instead of --index-url

uv pip install torch==2.0.0+cu118 torchvision==0.15.0+cu118 torchaudio==2.0.0+cu118 --extra-index-url https://download.pytorch.org/whl/cu118

There are actually differences between uv and pip in terms of index resolution. I think the problem here. It's not a bug, but they're just not exactly the same.
https://docs.astral.sh/uv/pip/compatibility/#packages-that-exist-on-multiple-indexes

Edit:
It doesn't seem to work, it's not very stable.

@Leon0402
Copy link
Author

@FishAlchemist It seems to generally work quite well when manually editing the toml file. Here is a version that works for me for instance:

[project]
name = "name"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
    "torch==2.4.0+cu118",
    "torchvision==0.19.0+cu118",
]

[tool.uv.sources]
torch = { index = "pytorch" }
torchvision = { index = "pytorch" }

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

Related to #8341 I think. Probably the CLI tools need a little bit more work and then UV could have some special documentation for torch. I know that torch always is a great source of confusion, because getting it right with cuda is not easy (and probably also not possible right now in the most generic way).
I have not yet tested how well this approach works in transitive setups though (where a dependency specifies torch, but we need to overwrite it with a specific cuda version) or in a more generic way (where different people need different cuda versions).

@FishAlchemist
Copy link
Contributor

@Leon0402 There is a PR (#6523) document about installing PyTorch for UV.
Perhaps you could also participate in the discussion and share your insights. Considering the complexities of PyTorch, additional perspectives would be beneficial for refining the documentation.

@Leon0402
Copy link
Author

@FishAlchemist Love it! I'll have a look later.

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

No branches or pull requests

3 participants