Files
transformers/docker/README.md
Tarek ZiadeandClaude Opus 5.5 34f416369d CI: Move GPU images to python 3.11 (#49352)
* Move the GPU CI images to the Python in `.python-version`

The NVIDIA images (all-latest, quantization, deepspeed-latest) and the
AMD DeepSpeed image used Ubuntu 22.04's system Python 3.10. They now get
Python from uv at `PYTHON_VERSION`, in a venv on PATH (same setup as
transformers-intel-cpu), so `python`, `python3` and `pip` resolve to it.
`python-is-python3` is no longer needed for DeepSpeed's
`#!/usr/bin/env python` scripts.

transformers-pytorch-amd-gpu ships torch in its base image's Python, so
its base tag is picked from `PYTHON_VERSION`
(rocm7.2_ubuntu22.04_py3.11_pytorch_release_2.10.0). AMD only publishes
pre-built flash-attn wheels for Python 3.10, so flash-attn is now built
from source, from the commit AMD's wheel was built from (0e60e39) and for
the same gfx942/gfx950 targets.

The build workflows pass `PYTHON_VERSION` from `.python-version`.

Unused images (pytorch-gpu, transformers-gpu, pytorch-tpu,
deepspeed-nightly) are left as they are.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Allow building test GPU images with a postfix from workflow_dispatch

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Remove the GitHub API cache-bust from the AMD docker images

* Bust the AMD images' clone cache with the commit being built

Replaces the removed GitHub API `ADD`: the build workflow now passes
`REF=${{ github.sha }}` to the AMD images, so the `git checkout $REF`
step (and every layer after it) changes, and is rebuilt, for each new
commit. No network call, and the image is pinned to the commit it was
built from.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Share the common GPU image steps through a `gpu-common` build context

The GPU dockerfiles start from different CUDA/ROCm base images, so they
can't share a base image, but they repeated the same steps on top of them.
These now live in `docker/gpu-common/`, passed to the builds as the
`gpu-common` named build context:

- `install-python.sh`: Python from `PYTHON_VERSION` with uv, in a venv
  (all-latest, quantization, deepspeed-latest, deepspeed-amd)
- `finish-transformers-install.sh`: uninstall `kernels` + `setup.py
  develop` (all five images)
- `check-torch.sh`: import torch and check it still matches the `PYTORCH`
  pin (all-latest, quantization, and now deepspeed-latest)

The torch installs stay per image, their differences are intended.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Install a pre-built flash-attention wheel in the AMD image

AMD's mirror has no Python 3.11 flash-attention wheel, and building the CK backend from source on the image builder
takes hours. Use the torch 2.10 / cp311 ROCm wheel from mjun0812/flash-attention-prebuild-wheels instead, pinned by
checksum, and import it at build time to catch an ABI mismatch with the base image's torch.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Build flash-attention from source in the AMD image, tuned like the NVIDIA one

Drop the third-party pre-built wheel and build the CK backend from the upstream commit AMD's wheel was built from, with
the same tweaks as the NVIDIA FA2 build: MAX_JOBS derived from the runner's RAM (setup.py's default leaves most of the
runner idle) and a filtered build log, since hipify's output fills BuildKit's per-step log limit before compilation
starts. Give the AMD image job an explicit timeout below GitHub's 6h default.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Leave the AMD PyTorch image out of the Python move

#49460 moves `transformers-pytorch-amd-gpu` to a ROCm 10 / Python 3.14 base image that ships flash-attention, while
AMD only publishes Python 3.10 flash-attention wheels for the current base and building them from source takes hours.
Keep that image (Dockerfile and build job) as on main.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Drop the image postfix input of workflow_dispatch

It was only needed to build test images for this PR.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-14 08:28:44 +00:00

1.7 KiB

Dockers for transformers

In this folder you will find various docker files, and some subfolders.

  • dockerfiles (ex: consistency.dockerfile) present under ~/docker are used for our "fast" CIs. You should be able to use them for tasks that only need CPU. For example torch-light is a very light weights container (703MiB). They all build on top of ci-base.dockerfile, using the Python version from the repo's .python-version. Build them with docker buildx bake from the repository root, e.g. PYTHON_VERSION=$(cat .python-version) docker buildx bake -f docker/docker-bake.hcl torch-light (a plain docker build won't resolve the ci-base stage).
  • subfolders contain dockerfiles used for our slow CIs, which can be used for GPU tasks, but they are BIG as they were not specifically designed for a single model / single task. Thus the ~/docker/transformers-pytorch-gpu includes additional dependencies to allow us to run ALL model tests (say librosa or tesseract, which you do not need to run LLMs) The GPU ones share the steps in gpu-common/ (Python from the repo's .python-version, finishing the transformers install, checking the pinned torch) through a named build context, e.g. docker build --build-context gpu-common=docker/gpu-common --build-arg PYTHON_VERSION=$(cat .python-version) docker/transformers-all-latest-gpu.

Note that in both case, you need to run uv pip install -e ., which should take around 5 seconds. We do it outside the dockerfile for the need of our CI: we checkout a new branch each time, and the transformers code is thus updated.

We are open to contribution, and invite the community to create dockerfiles with potential arguments that properly choose extras depending on the model's dependencies! 🤗