|
| 1 | +# This Dockerfile is used to build a Docker image containing all the |
| 2 | +# system-level dependencies required for maxtext. Since the maxtext |
| 3 | +# package itself includes all the necessary Python dependencies, this |
| 4 | +# image is designed to have a clean Python environment with just pip |
| 5 | +# and uv installed. |
| 6 | +# |
| 7 | +# Build a docker image by running: |
| 8 | +# `docker build --build-arg DEVICE=cuda12 -t <docker_image_name>:<tag> -f clean_py_env_gpu.Dockerfile .` |
| 9 | +# Or |
| 10 | +# `docker build --build-arg PYTHON_VERSION=3.11 --build-arg DEVICE=cuda12 -t <docker_image_name>:<tag> -f clean_py_env_gpu.Dockerfile .` |
| 11 | +# |
| 12 | +# How to upload the image to Google Container Registry (GCR): |
| 13 | +# e.g., DEVICE=cuda12 and PYTHON_VERSION=3.12 |
| 14 | +#. gcloud init |
| 15 | +# gcloud auth configure-docker |
| 16 | +# docker tag <docker_image_name>:<tag> gcr.io/tpu-prod-env-multipod/maxtext-unit-test-cuda12:py312 |
| 17 | +# docker push gcr.io/tpu-prod-env-multipod/maxtext-unit-test-cuda12:py312 |
| 18 | + |
| 19 | +# Default to Python 3.12. |
| 20 | +ARG PYTHON_VERSION=3.12 |
| 21 | + |
| 22 | +FROM nvcr.io/nvidia/cuda-dl-base:25.06-cuda12.9-devel-ubuntu24.04 |
| 23 | +# TODO: enable cuda 13, e.g., nvcr.io/nvidia/cuda-dl-base:25.08-cuda13.0-devel-ubuntu24.04. |
| 24 | + |
| 25 | +# Set the working directory in the container |
| 26 | +WORKDIR /maxtext |
| 27 | + |
| 28 | +# Arguments |
| 29 | +ARG DEVICE |
| 30 | + |
| 31 | +# Environment variables |
| 32 | +ENV DEVICE=$DEVICE |
| 33 | +ENV PYTHON_VERSION=${PYTHON_VERSION} |
| 34 | +ENV PIP_NO_CACHE_DIR=1 |
| 35 | +ENV PIP_ROOT_USER_ACTION=ignore |
| 36 | +ENV PIP_BREAK_SYSTEM_PACKAGES=1 |
| 37 | +ENV CLOUD_SDK_VERSION=latest |
| 38 | +# Ensure apt package installations run without manual intervention |
| 39 | +ENV DEBIAN_FRONTEND=noninteractive |
| 40 | +# See all env variables |
| 41 | +RUN env |
| 42 | + |
| 43 | +# Update the package lists and install Python 3 and pip |
| 44 | +RUN apt-get update && apt-get install -y python3 python3-pip |
| 45 | +# Remove any existing pip at /usr/bin/pip |
| 46 | +RUN rm -f /usr/bin/pip |
| 47 | +# Set python3 and pip3 as the default python and pip commands |
| 48 | +RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \ |
| 49 | + update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 |
| 50 | + |
| 51 | + |
| 52 | +# System level dependencies |
| 53 | +RUN apt-get update && apt-get install -y apt-utils git build-essential cmake curl pkg-config gnupg procps iproute2 ethtool lsb-release && rm -rf /var/lib/apt/lists/* |
| 54 | +# Add the Google Cloud SDK package repository |
| 55 | +RUN curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg && \ |
| 56 | + echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee /etc/apt/sources.list.d/google-cloud-sdk.list |
| 57 | +# Install the Google Cloud SDK |
| 58 | +RUN apt-get update && apt-get install -y google-cloud-sdk && rm -rf /var/lib/apt/lists/* |
| 59 | +# Install gcsfuse |
| 60 | +RUN export GCSFUSE_REPO=gcsfuse-bullseye && \ |
| 61 | + echo "deb https://packages.cloud.google.com/apt $GCSFUSE_REPO main" | tee /etc/apt/sources.list.d/gcsfuse.list && \ |
| 62 | + curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \ |
| 63 | + apt update -y && apt -y install gcsfuse && \ |
| 64 | + rm -rf /var/lib/apt/lists/* |
| 65 | +# See all installed system level packages |
| 66 | +RUN apt list --installed |
| 67 | + |
| 68 | +RUN python3 --version |
| 69 | +RUN python3 -m pip list |
| 70 | +RUN python3 -m pip install uv |
| 71 | +RUN rm -rf /root/.cache/pip |
| 72 | + |
| 73 | +# Clean python env |
| 74 | +RUN python3 -m uv pip list |
0 commit comments