astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
21.72k stars 636 forks source link

Issue with Installing Torch-TensorRT via `uv add` Command with External Repository Links #7735

Open ChenMoFeiJin opened 5 days ago

ChenMoFeiJin commented 5 days ago

Platform: Ubuntu 20.04 Version: uv 0.4.16

Description:

When attempting to install Torch-TensorRT using the uv add command, I encountered an error. The command I ran was:

uv add torch-tensorrt

The following error was returned:

###########################################################################################
The package you are trying to install is only a placeholder project on PyPI.org repository.
To install Torch-TensorRT please run the following command:

$ pip install torch-tensorrt -f https://github.com/NVIDIA/Torch-TensorRT/releases
###########################################################################################

Installing the package manually with pip works perfectly fine:

pip install torch-tensorrt -f https://github.com/NVIDIA/Torch-TensorRT/releases

However, when trying to use uv add with the same link, the following error occurs:

$ uv add torch-tensorrt -f https://github.com/pytorch/TensorRT/releases --verbose
DEBUG uv 0.4.16
DEBUG Found project root: `/path/to/project`
DEBUG Found workspace root: `/path/to/project`
DEBUG Adding current workspace member: `/path/to/project`
DEBUG Reading requests from `/path/to/project/.python-version`
DEBUG The virtual environment's Python version satisfies `Python 3.12`
DEBUG Using request timeout of 30s
DEBUG No cache entry for: https://github.com/pytorch/TensorRT/releases
error: Failed to read `--find-links` URL: https://github.com/pytorch/TensorRT/releases
  Caused by: Received some unexpected HTML from https://github.com/pytorch/TensorRT/releases
  Caused by: Unexpected fragment (expected `#sha256=...` or similar) on URL: start-of-content

It seems that uv is unable to properly handle external --find-links URLs when installing from sources like GitHub, as it encounters an unexpected HTML response.

konstin commented 5 days ago

It seems that torch-tensorrt doesn't publish wheels for Python 3.12 (only up to 3.11), so we fall back to the 0.0.0.post1 dummy package. On the github releases page there's a Python 3.12 wheel then (https://github.com/pytorch/TensorRT/releases/download/v2.4.0/torch_tensorrt-2.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_34_x86_64.whl).

While I'm open to extending uv's find links parser to work more like pip, i'm hesitant to specifically support github releases: The page at https://github.com/pytorch/TensorRT/releases only has a few recent releases, which means that uv lock could break in the future when the released you had lock is moved to the second releases page. Ideally, the would be a single flat html page with all torch-tensorrt github releases that we could use.

ChenMoFeiJin commented 5 days ago

Thank you for your feedback. You raise a good point about the limitations of GitHub releases. Indeed, since uv.lock records the exact .whl or .tar.gz download URL, we can rebuild the environment even if the release has moved beyond GitHub's first page. The file link stays active unless removed by GitHub. (I admit I may not fully grasp the workings of uv.lock.)

Hence, it would be wise to consider a more robust approach to managing GitHub releases. This could prove particularly useful for those dependent on specific versions not available on PyPI or other simple HTML pages. Although there's a slight risk of file removal, it's unlikely for widely used libraries such as Torch-TensorRT.

I understand if you find additional processing unnecessary. Thank you for explaining that Torch-TensorRT does not have a build for version 3.12 on PyPI, and it's not just a general placeholder. With this in mind, I'm thinking of downgrading to version 3.11 as a temporary workaround. If you think this issue warrants further discussion, please feel free to leave it open. Otherwise, we can consider it resolved.

matteo-bruni commented 5 days ago

torch-tensorrt is available on index https://download.pytorch.org/whl/cu124 so you can install it using --extra-index-url (you can also use https://download.pytorch.org/whl/cu118/ or https://download.pytorch.org/whl/cu121 for other cuda version)

you also need to use --index-strategy unsafe-best-match because it needs packaging>23 and in the pytorch index only packaging==22.0 is available (why they release 3rd party wheels?? same problem with pillow which is not up to date with upstream)