Skip to content

Commit a8bc6ae

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

3 files changed

Lines changed: 67 additions & 72 deletions

File tree

.github/workflows/UploadDockerImages.yml

Lines changed: 15 additions & 29 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:
97-
image_name: ${{ matrix.image_name }}${{ inputs.image_suffix }}
86+
image_name: ${{ inputs.image_suffix != '' && format('{0}_{1}', matrix.image_name, inputs.image_suffix) || matrix.image_name }}
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: 51 additions & 38 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
@@ -54,7 +52,7 @@ permissions:
5452

5553
jobs:
5654
build_and_push:
57-
runs-on: linux-x86-n2-16-buildkit
55+
runs-on: ubuntu-latest
5856
container: google/cloud-sdk:524.0.0
5957
if: >
6058
github.event_name == 'release' ||
@@ -89,18 +87,6 @@ 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 }}"
93-
94-
- name: Checkout MaxText
95-
uses: actions/checkout@v5
96-
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 }}
100-
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'
10490
10591
- name: Configure Docker
10692
run: gcloud auth configure-docker us-docker.pkg.dev,gcr.io -q
@@ -113,24 +99,51 @@ jobs:
11399
driver: remote
114100
endpoint: tcp://localhost:1234
115101

116-
- name: Build and push Docker image
117-
uses: docker/build-push-action@v6
102+
- name: Download MaxText wheel
103+
uses: actions/download-artifact@v4
118104
if: steps.check.outputs.should_run == 'true'
119105
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 }}
106+
name: maxtext-wheel
107+
108+
- name: Install uv and set the Python version
109+
uses: astral-sh/setup-uv@v7
110+
if: steps.check.outputs.should_run == 'true'
111+
with:
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
123+
124+
- name: Build and push Docker image
125+
if: steps.check.outputs.should_run == 'true'
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+
PROJECT: tpu-prod-env-multipod
131+
run: |
132+
source .venv/bin/activate
133+
echo "Building MaxText Docker image..."
134+
#apt-get update && apt-get install -y sudo
135+
#sudo .venv/bin/python3 -m dependencies.scripts.build_maxtext_docker_image \
136+
build_maxtext_docker_image \
137+
DEVICE=${{ inputs.device }} \
138+
MODE=${{ inputs.build_mode }} \
129139
WORKFLOW=${{ inputs.workflow }}
130-
PACKAGE_DIR=./src
131-
JAX_VERSION=NONE
132-
LIBTPU_VERSION=NONE
133-
INCLUDE_TEST_ASSETS=true
140+
141+
echo "Pushing MaxText Docker image..."
142+
#sudo .venv/bin/python3 -m dependencies.scripts.upload_maxtext_docker_image \
143+
upload_maxtext_docker_image \
144+
CLOUD_IMAGE_NAME=${{ inputs.image_name }}
145+
docker push "${IMAGE_TAG}"
146+
echo "Successfully pushed ${IMAGE_TAG}"
134147
135148
- name: Add tags to Docker image
136149
if: steps.check.outputs.should_run == 'true'
@@ -146,16 +159,16 @@ jobs:
146159
echo "Tagging docker images corresponding to nightly release..."
147160
148161
# Add date tag
149-
gcloud container images add-tag "${TEMP_IMG}" "$SOURCE_IMAGE:${INPUTS_IMAGE_DATE}" --quiet
162+
IMAGE_DATE="$(date +%Y-%m-%d)"
163+
gcloud container images add-tag "${TEMP_IMG}" "$SOURCE_IMAGE:$IMAGE_DATE" --quiet
150164
151165
# Convert date to YYYYMMDD format
152-
clean_date=$(echo "${INPUTS_IMAGE_DATE}" | sed 's/[-:]//g' | cut -c1-8)
166+
clean_date=$(echo "$IMAGE_DATE" | sed 's/[-:]//g' | cut -c1-8)
153167
154168
# Add MaxText tag
155169
gcloud container images add-tag "${TEMP_IMG}" "${SOURCE_IMAGE}:maxtext_${MAXTEXT_SHA}_${clean_date}" --quiet
156170
fi
157171
env:
158172
INPUTS_IMAGE_NAME: ${{ inputs.image_name }}
159-
INPUTS_IMAGE_DATE: ${{ inputs.image_date }}
160173
INPUTS_VERSION_NAME: ${{ inputs.version_name }}
161174
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)