build(docker): compile SageAttention 2.2 on slim trixie using Debian CUDA toolkit; install wheel into runtime and enable flag

Switch to a two-stage Dockerfile that builds SageAttention 2.2 from source on python:3.12-slim-trixie by explicitly enabling contrib/non-free/non-free-firmware in APT and installing Debian’s nvidia-cuda-toolkit (nvcc) for compilation, then installs the produced cp312 wheel into the slim runtime so --use-sage-attention works at startup. The builder installs Torch cu129 to match the runtime for ABI compatibility and uses pip’s --break-system-packages to avoid a venv while respecting PEP 668 in a controlled way, keeping layers lean and avoiding the prior sources.list and space issues seen on GitHub runners. The final image remains minimal while bundling an up-to-date SageAttention build aligned with the Torch/CUDA stack in use.
This commit is contained in:
clsferguson 2025-09-21 22:54:12 -06:00 committed by GitHub
parent 4369ba2e3d
commit 97b4d164ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,19 +7,18 @@ ENV DEBIAN_FRONTEND=noninteractive \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1
# Enable contrib/non-free/non-free-firmware, install CUDA toolkit + build deps
# Write explicit Debian sources with contrib/non-free/non-free-firmware, then install CUDA toolkit + build deps
RUN set -eux; \
sed -i 's/ main$/ main contrib non-free non-free-firmware/g' /etc/apt/sources.list; \
printf 'deb http://deb.debian.org/debian trixie main contrib non-free non-free-firmware\n' > /etc/apt/sources.list; \
printf 'deb http://deb.debian.org/debian trixie-updates main contrib non-free non-free-firmware\n' >> /etc/apt/sources.list; \
printf 'deb http://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware\n' >> /etc/apt/sources.list; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates curl git build-essential cmake \
nvidia-cuda-toolkit \
; \
apt-get install -y --no-install-recommends ca-certificates curl git build-essential cmake nvidia-cuda-toolkit; \
rm -rf /var/lib/apt/lists/*
WORKDIR /tmp/sage
# Install Torch cu129 in system site (PEP 668: allow system installs)
# Install Torch cu129 in builder (matches runtime) and build wheel (PEP 668: allow system installs here)
RUN python -m pip install --upgrade pip setuptools wheel --break-system-packages && \
python -m pip install torch torchvision torchaudio \
--extra-index-url https://download.pytorch.org/whl/cu129 \