Live data from Hacker News

Using uv with PyTorch

docs.astral.sh

11–20 of 56 posts

Re: Using uv with PyTorch

#11
Kind of an aside as this doc is about the complexities of installing particular PyTorch versions, but will say that uv is way faster at installing PyTorch than pip.

We run internal benchmarks of our custom container image builder and in the 'install torch' benchmark the p50 time saved when using `uv` is 25 seconds! (71.4s vs. 43.74s)

---

Aside 2: Seems there's a missing "involves" in this sentence: "As such, installing PyTorch typically often configuring a project to use the PyTorch index."

Re: Using uv with PyTorch

#12
post #3

uv significantly speeds up my pytorch in docker builds # Setup virtual env ENV VIRTUAL_ENV=/app/.venv ENV PATH="$VIRTUAL_ENV/bin:$PATH" RUN python3 -m venv $VIRTUAL_ENV RUN . $VIRTUAL_ENV/bin/activate # install using uv RUN pip install uv RUN uv pip install torch==${TORCH_VERSION} --index-url https://download.pytorch.org/whl/cpu The index-url makes it really convenient.

Apparently, uv respects a key in project.toml:

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

Re: Using uv with PyTorch

#13
post #3

uv significantly speeds up my pytorch in docker builds # Setup virtual env ENV VIRTUAL_ENV=/app/.venv ENV PATH="$VIRTUAL_ENV/bin:$PATH" RUN python3 -m venv $VIRTUAL_ENV RUN . $VIRTUAL_ENV/bin/activate # install using uv RUN pip install uv RUN uv pip install torch==${TORCH_VERSION} --index-url https://download.pytorch.org/whl/cpu The index-url makes it really convenient.

Apparently, uv respects a key in project.toml: [[tool.uv.index]] name = "pytorch-cu124" url = "https://download.pytorch.org/whl/cu124" explicit = true

Nice, I wonder if there is a way to make it conditional, e.g. to pick a different key for a cpu vs cuda build.

Re: Using uv with PyTorch

#14
post #13

Earlier quoted context omitted.

Apparently, uv respects a key in project.toml: [[tool.uv.index]] name = "pytorch-cu124" url = "https://download.pytorch.org/whl/cu124" explicit = true

Nice, I wonder if there is a way to make it conditional, e.g. to pick a different key for a cpu vs cuda build.

Eh, in that case the environment variable is a bit more evident in a Dockerfile.

Re: Using uv with PyTorch

#15
post #13

Earlier quoted context omitted.

Apparently, uv respects a key in project.toml: [[tool.uv.index]] name = "pytorch-cu124" url = "https://download.pytorch.org/whl/cu124" explicit = true

Nice, I wonder if there is a way to make it conditional, e.g. to pick a different key for a cpu vs cuda build.

That’s basically what TFA is about? Set up multiple index urls, and use a bog-standard platform marker on the PyTorch dep to pick between them.

Re: Using uv with PyTorch

#18

Does uv support global Python install now? I need something like Mise for this.

uv python install 3.xx

That is not global. From the uv getting started docs:

"When Python is installed by uv, it will not be available globally (i.e. via the python command). Support for this feature is planned for a future release. In the meantime, use uv run or create and activate a virtual environment to use python directly."

So yes, one needs mise/asdf/pyenv or similar for global installs for now.

Re: Using uv with PyTorch

#19

Kind of an aside as this doc is about the complexities of installing particular PyTorch versions, but will say that uv is way faster at installing PyTorch than pip. We run internal benchmarks of our custom container image builder and in the 'install torch' benchmark the p50 time saved when using `uv` is 25 seconds! (71.4s vs. 43.74s) --- Aside 2: Seems there's a missing "involves" in this sentence: "As such, installi…

Joining your aside to tout the benefits of uv. We use uv combined with a simple proxy I wrote, to cache python dependencies, and then install them in parallel. UV also makes it simple to regenerate a requirements file and know who requires the dependencies, which in turn makes it easy to manage the ecosystem, analyze packages, and determine if we can reduce our footprint.

Between that latter feature, the proxy, the parallelization we've reduced build times across ~100 engineers by a solid 10 minutes. There are other things we do as well, but uv is a must have nowadays.

Post reply on HN