Skip to content

Commit 8328cbd

Browse files
committed
Build MaxText docker image from PyPI
1 parent ff916b8 commit 8328cbd

3 files changed

Lines changed: 62 additions & 73 deletions

File tree

.github/workflows/UploadDockerImages.yml

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023–2025 Google LLC
1+
# Copyright 2023–2026 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -42,27 +42,16 @@ permissions:
4242
contents: read
4343

4444
jobs:
45-
setup:
46-
runs-on: ubuntu-latest
47-
outputs:
48-
maxtext_sha: ${{ steps.vars.outputs.maxtext_sha }}
49-
image_date: ${{ steps.vars.outputs.image_date }}
50-
steps:
51-
- name: Checkout MaxText
52-
uses: actions/checkout@v5
53-
54-
- name: Get metadata
55-
id: vars
56-
run: |
57-
# MaxText SHA
58-
echo "maxtext_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
59-
60-
# Image date
61-
echo "image_date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT
45+
build_and_upload_maxtext_package:
46+
uses: ./.github/workflows/build_package.yml
47+
with:
48+
device_type: tpu
49+
device_name: v4-8
50+
cloud_runner: linux-x86-n2-16-buildkit
6251

6352
build-and-push:
6453
name: ${{ matrix.image_name }}
65-
needs: setup
54+
needs: build_and_upload_maxtext_package
6655
strategy:
6756
fail-fast: false
6857
matrix:
@@ -71,36 +60,34 @@ jobs:
7160
build_mode: stable
7261
workflow: pre-training
7362
image_name: maxtext_jax_stable
74-
dockerfile: ./src/dependencies/dockerfiles/maxtext_tpu_dependencies.Dockerfile
63+
include_test_assets: true
7564
- device: tpu
7665
build_mode: nightly
7766
workflow: pre-training
7867
image_name: maxtext_jax_nightly
79-
dockerfile: ./src/dependencies/dockerfiles/maxtext_tpu_dependencies.Dockerfile
68+
include_test_assets: true
8069
- device: tpu
8170
build_mode: nightly
8271
workflow: post-training
8372
image_name: maxtext_post_training_nightly
84-
dockerfile: ./src/dependencies/dockerfiles/maxtext_tpu_dependencies.Dockerfile
73+
include_test_assets: true
8574
- device: gpu
8675
build_mode: stable
8776
workflow: pre-training
8877
image_name: maxtext_gpu_jax_stable
89-
dockerfile: ./src/dependencies/dockerfiles/maxtext_gpu_dependencies.Dockerfile
78+
include_test_assets: true
9079
- device: gpu
9180
build_mode: nightly
9281
workflow: pre-training
9382
image_name: maxtext_gpu_jax_nightly
94-
dockerfile: ./src/dependencies/dockerfiles/maxtext_gpu_dependencies.Dockerfile
83+
include_test_assets: true
9584
uses: ./.github/workflows/build_and_push_docker_image.yml
9685
with:
9786
image_name: ${{ matrix.image_name }}${{ inputs.image_suffix }}
9887
device: ${{ matrix.device }}
9988
build_mode: ${{ matrix.build_mode }}
10089
workflow: ${{ matrix.workflow }}
101-
dockerfile: ${{ matrix.dockerfile }}
102-
maxtext_sha: ${{ needs.setup.outputs.maxtext_sha }}
103-
image_date: ${{ needs.setup.outputs.image_date }}
90+
maxtext_sha: ${{ needs.build_and_upload_maxtext_package.outputs.maxtext_sha }}
10491
secrets:
10592
HF_TOKEN: ${{ secrets.HF_TOKEN }}
10693

@@ -131,7 +118,6 @@ jobs:
131118
build_mode: nightly
132119
workflow: pre-training
133120
image_name: maxtext_gpu_jax_nightly
134-
135121
uses: ./.github/workflows/promote_docker_image.yml
136122
with:
137123
image_name: ${{ matrix.image_name }}${{ inputs.image_suffix }}

.github/workflows/build_and_push_docker_image.yml

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Google LLC
1+
# Copyright 2023-2026 Google LLC
22

33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -28,15 +28,9 @@ on:
2828
build_mode:
2929
required: true
3030
type: string
31-
dockerfile:
32-
required: true
33-
type: string
3431
maxtext_sha:
3532
required: true
3633
type: string
37-
image_date:
38-
required: false
39-
type: string
4034
workflow:
4135
required: false
4236
type: string
@@ -45,6 +39,10 @@ on:
4539
required: false
4640
type: string
4741
default: ''
42+
include_test_assets:
43+
required: false
44+
type: boolean
45+
default: false
4846
secrets:
4947
HF_TOKEN:
5048
required: true
@@ -89,48 +87,57 @@ jobs:
8987
echo "workflow: ${{ inputs.workflow }}"
9088
echo "build_mode: ${{ inputs.build_mode }}"
9189
echo "image_name: ${{ inputs.image_name }}"
92-
echo "dockerfile: ${{ inputs.dockerfile }}"
9390
94-
- name: Checkout MaxText
95-
uses: actions/checkout@v5
91+
- name: Configure Docker
92+
run: gcloud auth configure-docker us-docker.pkg.dev,gcr.io -q
9693
if: steps.check.outputs.should_run == 'true'
97-
with:
98-
# This ensures that every job clones the exact same commit as "setup" job
99-
ref: ${{ inputs.maxtext_sha }}
10094

101-
- name: Mark git repositories as safe
102-
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
103-
if: steps.check.outputs.should_run == 'true'
95+
#- name: Set up Docker BuildX
96+
# uses: docker/setup-buildx-action@v3.11.1
97+
# if: steps.check.outputs.should_run == 'true'
98+
# with:
99+
# driver: remote
100+
# endpoint: tcp://localhost:1234
104101

105-
- name: Configure Docker
106-
run: gcloud auth configure-docker us-docker.pkg.dev,gcr.io -q
102+
- name: Download MaxText wheel
103+
uses: actions/download-artifact@v4
107104
if: steps.check.outputs.should_run == 'true'
105+
with:
106+
name: maxtext-wheel
108107

109-
- name: Set up Docker BuildX
110-
uses: docker/setup-buildx-action@v3.11.1
108+
- name: Install uv and set the Python version
109+
uses: astral-sh/setup-uv@v7
111110
if: steps.check.outputs.should_run == 'true'
112111
with:
113-
driver: remote
114-
endpoint: tcp://localhost:1234
112+
python-version: '3.12'
113+
enable-cache: true
114+
115+
- name: Install MaxText wheel
116+
if: steps.check.outputs.should_run == 'true'
117+
shell: bash
118+
run: |
119+
uv venv --seed
120+
source .venv/bin/activate
121+
maxtext_wheel=$(ls maxtext-*-py3-none-any.whl 2>/dev/null)
122+
uv pip install ${maxtext_wheel}[runner] --resolution=lowest
115123
116124
- name: Build and push Docker image
117-
uses: docker/build-push-action@v6
118125
if: steps.check.outputs.should_run == 'true'
119-
with:
120-
push: true
121-
context: .
122-
file: ${{ inputs.dockerfile }}
123-
tags: gcr.io/tpu-prod-env-multipod/${{ inputs.image_name }}:${{ github.run_id }}
124-
cache-from: type=gha
125-
outputs: type=image,compression=zstd,force-compression=true
126-
build-args: |
127-
DEVICE=${{ inputs.device }}
128-
MODE=${{ inputs.build_mode }}
126+
shell: bash
127+
env:
128+
IMAGE_TAG: "gcr.io/tpu-prod-env-multipod/${{ inputs.image_name }}:${{ github.run_id }}"
129+
INCLUDE_TEST_ASSETS: ${{ inputs.include_test_assets }}
130+
run: |
131+
source .venv/bin/activate
132+
echo "Building MaxText Docker image..."
133+
sudo .venv/bin/python3 -m dependencies.scripts.build_maxtext_docker_image \
134+
DEVICE=${{ inputs.device }} \
135+
MODE=${{ inputs.build_mode }} \
129136
WORKFLOW=${{ inputs.workflow }}
130-
PACKAGE_DIR=./src
131-
JAX_VERSION=NONE
132-
LIBTPU_VERSION=NONE
133-
INCLUDE_TEST_ASSETS=true
137+
138+
echo "Pushing MaxText Docker image..."
139+
docker push "${IMAGE_TAG}"
140+
echo "Successfully pushed ${IMAGE_TAG}"
134141
135142
- name: Add tags to Docker image
136143
if: steps.check.outputs.should_run == 'true'
@@ -146,16 +153,16 @@ jobs:
146153
echo "Tagging docker images corresponding to nightly release..."
147154
148155
# Add date tag
149-
gcloud container images add-tag "${TEMP_IMG}" "$SOURCE_IMAGE:${INPUTS_IMAGE_DATE}" --quiet
156+
IMAGE_DATE="$(date +%Y-%m-%d)"
157+
gcloud container images add-tag "${TEMP_IMG}" "$SOURCE_IMAGE:$IMAGE_DATE" --quiet
150158
151159
# Convert date to YYYYMMDD format
152-
clean_date=$(echo "${INPUTS_IMAGE_DATE}" | sed 's/[-:]//g' | cut -c1-8)
160+
clean_date=$(echo "$IMAGE_DATE" | sed 's/[-:]//g' | cut -c1-8)
153161
154162
# Add MaxText tag
155163
gcloud container images add-tag "${TEMP_IMG}" "${SOURCE_IMAGE}:maxtext_${MAXTEXT_SHA}_${clean_date}" --quiet
156164
fi
157165
env:
158166
INPUTS_IMAGE_NAME: ${{ inputs.image_name }}
159-
INPUTS_IMAGE_DATE: ${{ inputs.image_date }}
160167
INPUTS_VERSION_NAME: ${{ inputs.version_name }}
161168
MAXTEXT_SHA: ${{ inputs.maxtext_sha }}

.github/workflows/pypi_release.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Google LLC
1+
# Copyright 2023-2026 Google LLC
22

33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -103,24 +103,20 @@ jobs:
103103
build_mode: stable
104104
image_name: maxtext_jax_stable
105105
workflow: pre-training
106-
dockerfile: ./src/dependencies/dockerfiles/maxtext_tpu_dependencies.Dockerfile
107106
- device: gpu
108107
build_mode: stable
109108
image_name: maxtext_gpu_jax_stable
110109
workflow: pre-training
111-
dockerfile: ./src/dependencies/dockerfiles/maxtext_gpu_dependencies.Dockerfile
112110
- device: tpu
113111
build_mode: stable
114112
image_name: maxtext_post_training_stable
115113
workflow: post-training
116-
dockerfile: ./src/dependencies/dockerfiles/maxtext_tpu_dependencies.Dockerfile
117114
uses: ./.github/workflows/build_and_push_docker_image.yml
118115
with:
119116
image_name: ${{ matrix.image_name }}
120117
device: ${{ matrix.device }}
121118
build_mode: ${{ matrix.build_mode }}
122119
workflow: ${{ matrix.workflow }}
123-
dockerfile: ${{ matrix.dockerfile }}
124120
maxtext_sha: ${{ github.sha }}
125121
version_name: ${{ needs.get_latest_maxtext_pypi_version.outputs.latest_pypi_version }}
126122
secrets:

0 commit comments

Comments
 (0)