.ci/docker/README.md
This directory contains everything needed to build the Docker images that are used in our CI.
The Dockerfiles located in subdirectories are parameterized to
conditionally run build stages depending on build arguments passed to
docker build. This lets us use only a few Dockerfiles for many
images. The different configurations are identified by a freeform
string that we call a build environment. This string is persisted in
each image as the BUILD_ENVIRONMENT environment variable.
See build.sh for valid build environments (it's the giant switch).
build.sh -- dispatch script to launch all buildscommon -- scripts used to execute individual Docker build stagesubuntu -- Dockerfile for Ubuntu image for CPU build and test jobsubuntu-cuda -- Dockerfile for Ubuntu image with CUDA support for nvidia-dockerubuntu-rocm -- Dockerfile for Ubuntu image with ROCm supportubuntu-xpu -- Dockerfile for Ubuntu image with XPU supportconda - Dockerfile and build.sh to build Docker images used in nightly conda buildsmanywheel - Dockerfile and build.sh to build Docker images used in nightly manywheel buildslibtorch - Dockerfile and build.sh to build Docker images used in nightly libtorch builds# Build a specific image
./build.sh pytorch-linux-bionic-py3.8-gcc9 -t myimage:latest
# Set flags (see build.sh) and build image
sudo bash -c 'TRITON=1 ./build.sh pytorch-linux-bionic-py3.8-gcc9 -t myimage:latest'
The base Docker images in directory .ci/docker/ are built by the docker-builds.yml workflow. Those images are used throughout the PyTorch CI/CD pipeline. You should only create or modify a base Docker image if you need specific environment changes or dependencies before building PyTorch on CI.
Automatic Rebuilding:
.ci/docker/* directoryImage Reuse in PyTorch Build Workflows (example: linux-build):
docker-builds.yml are reused in _linux-build.yml through the calculate-docker-image step_linux-build.yml workflow:
calculate-docker-image step.ci/pytorch/build.sh inside the container to build PyTorchUsage in Test Workflows (example: linux-test):
_linux-test.yml for running tests_linux-test.yml workflow follows a similar pattern:
calculate-docker-image step to determine which Docker image to use.ci/pytorch/test.sh or .ci/pytorch/multigpu-test.sh) inside the container.ci/docker/build.sh vs .ci/pytorch/build.sh.ci/docker/build.sh:
docker-builds.yml workflow to pre-build Docker images for CI.ci/pytorch/build.sh:
_linux-build.yml after the Docker container is started.ci/docker/ci_commit_pins/ vs .github/ci_commit_pins.ci/docker/ci_commit_pins/:
.github/ci_commit_pins:
We use pinned commits for build stability. The nightly.yml workflow checks and updates pinned commits for certain repository dependencies daily.
If your new Docker image needs a library installed from a specific pinned commit or built from source:
nightly.yml and merge-rules.yml.ci/docker/ci_commit_pins/. The text filename should match the one defined in step 1Add new Base Docker image configuration (if applicable):
Add the configuration in .ci/docker/build.sh. For example:
pytorch-linux-jammy-cuda12.8-cudnn9-py3.12-gcc11-new1)
CUDA_VERSION=12.8.1
ANACONDA_PYTHON_VERSION=3.12
GCC_VERSION=11
VISION=yes
KATEX=yes
UCX_COMMIT=${_UCX_COMMIT}
UCC_COMMIT=${_UCC_COMMIT}
TRITON=yes
NEW_ARG_1=yes
;;
Add build arguments to Docker build command:
If you're introducing a new argument to the Docker build, make sure to add it in the Docker build step in .ci/docker/build.sh:
docker build \
....
--build-arg "NEW_ARG_1=${NEW_ARG_1}"
Update Dockerfile logic:
Update the Dockerfile to use the new argument. For example, in ubuntu/Dockerfile:
ARG NEW_ARG_1
# Set up environment for NEW_ARG_1
RUN if [ -n "${NEW_ARG_1}" ]; then bash ./do_something.sh; fi
Add the Docker configuration in .github/workflows/docker-builds.yml:
The docker-builds.yml workflow pre-builds the Docker images whenever changes occur in the .ci/docker/ directory. This includes the
pinned commit updates.