Created
March 1, 2024 11:27
-
-
Save JGalego/272d990394b523c1a6b21a46c622293e to your computer and use it in GitHub Desktop.
PyTorch CPU-only installation with uv ⚡️ and Docker 🐋
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ARG TORCH_VERSION=2.2.1 | |
FROM python:3.12@sha256:35eff340c0acd837b7962f77ee4b8869385dd6fe7d3928375a08f0a3bdd18beb AS basic | |
# Install uv | |
# https://github.com/astral-sh/uv | |
ENV VIRTUAL_ENV=/usr/local | |
ADD --chmod=755 https://astral.sh/uv/install.sh /install.sh | |
RUN /install.sh && \ | |
rm install.sh | |
# Install PT (CPU-only) | |
ARG TORCH_VERSION | |
SHELL ["/bin/bash", "-c"] | |
RUN source "$HOME/.cargo/env" && \ | |
uv pip install "torch==${TORCH_VERSION}+cpu" --no-cache -f https://download.pytorch.org/whl/torch_stable.html | |
# Check installation | |
RUN wget --progress=dot:giga https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py | |
CMD ["python", "collect_env.py"] | |
FROM python:3.12-alpine3.19@sha256:849ed6079c9f797ca9c1b7d6aea1c00aea3ac35110cbd0d6003f15950017ea8d AS alpine | |
# Install uv | |
# https://github.com/astral-sh/uv | |
ENV VIRTUAL_ENV=/usr/local | |
ADD --chmod=755 https://astral.sh/uv/install.sh /install.sh | |
RUN /install.sh && \ | |
rm install.sh | |
# Install PT (CPU-only) | |
ARG TORCH_VERSION | |
RUN . "$HOME/.cargo/env" && \ | |
uv pip install "torch==${TORCH_VERSION}+cpu" --no-cache -f https://download.pytorch.org/whl/torch_stable.html | |
# Check installation | |
RUN wget -q https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py | |
CMD ["python", "collect_env.py"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just run
docker build -t test:basic --target basic .
to build the image anddocker run --rm test:basic
to check the installationOutput: