4 ms·
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
by gdiamos 2y ago
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.
- orf 2y agoUse —copy-from to make it even faster, and use a cache mount https://docs.astral.sh/uv/guides/integration/docker/#installing-uv https://docs.astral.sh/uv/guides/integration/docker/#install...
- odie5533 2y agoAlso use pyproject.toml to specify dependencies, not manually installing stuff with uv pip
- samtheprogram 2y agoSpeeds up installation, or speeds up PyTorch in general?
- gleenn 2y agoAlmost certainly only the install. Uv is basically a pip tool substitute with a few other bells and whistles too but shouldn't affect run time whatsoever.
- ttyprintk 2y agoApparently, uv respects a key in project.toml: [[tool.uv.index]] name = "pytorch-cu124" url = "https://download.pytorch.org/whl/cu124" explicit = true
- gdiamos 2y agoNice, I wonder if there is a way to make it conditional, e.g. to pick a different key for a cpu vs cuda build.
- ttyprintk 2y agoEh, in that case the environment variable is a bit more evident in a Dockerfile.
- kristjansson 2y agoThat’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.