←back to thread

Using uv with PyTorch

(docs.astral.sh)
167 points charliermarsh | 2 comments | | HN request time: 0.412s | source
Show context
gdiamos ◴[] No.42189027[source]
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.
replies(3): >>42189326 #>>42189506 #>>42190557 #
1. orf ◴[] No.42189326[source]
Use —copy-from to make it even faster, and use a cache mount

https://docs.astral.sh/uv/guides/integration/docker/#install...

replies(1): >>42190399 #
2. odie5533 ◴[] No.42190399[source]
Also use pyproject.toml to specify dependencies, not manually installing stuff with uv pip