1+ #! /bin/bash
2+
3+ # Validates the Gemma4-26B pre-training pipeline using a pre-converted MaxText checkpoint.
4+
5+ # The flow of this script is as follows:
6+ # 1. Run inference on the pre-converted checkpoint.
7+ # 2. Run pre-training starting from the pre-converted checkpoint.
8+ # 3. Run inference on the checkpoint produced by the pre-training run.
9+
10+ # Usage:
11+ # export HF_TOKEN=<your Hugging Face access token>
12+ # export RUN_ID=$(date +%Y-%m-%d-%H-%M-%S)
13+ # bash test_gemma4_to_mt.sh $RUN_ID
14+ # bash test_gemma4.sh $RUN_ID
15+
16+
17+ set -ex
18+
19+ run_id=${1:- $(date +% Y-% m-% d-% H-% M-% S)}
20+ MODEL_NAME=' gemma4-26b'
21+
22+ # To convert the multimodal model, make sure the use_multimodal is set to be true
23+ USE_MULTIMODAL=false
24+
25+ # Non-Googlers please remember to point `BASE_OUTPUT_DIRECTORY` to the GCS paths where you have the scanned and unscanned checkpoints stored
26+ BASE_OUTPUT_DIRECTORY=gs://runner-maxtext-logs/${MODEL_NAME}
27+ UNSCANNED_CKPT_PATH=${BASE_OUTPUT_DIRECTORY} /to_maxtext/unscanned/${run_id} /0/items
28+
29+ # Non-Googlers please remember to point `DATASET_PATH` to the GCS bucket where you have your training data
30+ DATASET_PATH=gs://maxtext-dataset
31+
32+ # Step 1: Run inference on the original checkpoint converted from Hugging Face
33+ if [ ${USE_MULTIMODAL} == true ]; then
34+ python3 -m maxtext.inference.decode \
35+ model_name=${MODEL_NAME} tokenizer_type=" huggingface" \
36+ load_parameters_path=${UNSCANNED_CKPT_PATH} \
37+ per_device_batch_size=1 run_name=${run_id} \
38+ max_prefill_predict_length=272 max_target_length=300 steps=1 async_checkpointing=false \
39+ scan_layers=false use_multimodal=true \
40+ checkpoint_storage_use_zarr3=False checkpoint_storage_use_ocdbt=False \
41+ prompt=\' Describe\ image\ \< start_of_image\>\' image_path=\' tests/assets/test_image.jpg\' attention=\' dot_product\'
42+ else
43+ python3 -m maxtext.inference.decode \
44+ model_name=${MODEL_NAME} tokenizer_type=" huggingface" \
45+ load_parameters_path=${UNSCANNED_CKPT_PATH} \
46+ per_device_batch_size=1 run_name=${run_id} \
47+ max_prefill_predict_length=8 max_target_length=16 steps=1 async_checkpointing=false \
48+ checkpoint_storage_use_zarr3=False checkpoint_storage_use_ocdbt=False \
49+ scan_layers=false prompt=' I love to' attention=\' dot_product\'
50+ fi
51+
52+ # Step 2: Run Pre-training on the converted checkpoint
53+ # We can also run training by using the scanned converted checkpoint
54+ # Note that scanned checkpoint helps with efficient training
55+ python3 -m maxtext.trainers.pre_train.train \
56+ base_output_directory=${BASE_OUTPUT_DIRECTORY} /train \
57+ dataset_path=${DATASET_PATH} tokenizer_type=" huggingface" \
58+ load_parameters_path=${UNSCANNED_CKPT_PATH} \
59+ per_device_batch_size=1 run_name=${run_id} \
60+ max_target_length=8192 steps=5 async_checkpointing=false \
61+ checkpoint_storage_use_zarr3=False checkpoint_storage_use_ocdbt=False \
62+ model_name=${MODEL_NAME} scan_layers=false use_multimodal=${USE_MULTIMODAL}
63+
64+ # Step 3: Run inference on the checkpoint generated from the previous run
65+ if [ ${USE_MULTIMODAL} == true ]; then
66+ python3 -m maxtext.inference.decode \
67+ model_name=${MODEL_NAME} tokenizer_type=" huggingface" \
68+ load_parameters_path=${BASE_OUTPUT_DIRECTORY} /train/${run_id} /checkpoints/4/items \
69+ per_device_batch_size=1 run_name=${run_id} \
70+ max_prefill_predict_length=272 max_target_length=300 steps=1 async_checkpointing=false \
71+ scan_layers=false use_multimodal=true \
72+ checkpoint_storage_use_zarr3=False checkpoint_storage_use_ocdbt=False \
73+ prompt=\' Describe\ image\ \< start_of_image\>\' image_path=\' tests/assets/test_image.jpg\' attention=\' dot_product\'
74+ else
75+ python3 -m maxtext.inference.decode \
76+ model_name=${MODEL_NAME} tokenizer_type=" huggingface" \
77+ load_parameters_path=${BASE_OUTPUT_DIRECTORY} /train/${run_id} /checkpoints/4/items \
78+ per_device_batch_size=1 run_name=${run_id} \
79+ max_prefill_predict_length=8 max_target_length=16 steps=1 async_checkpointing=false \
80+ checkpoint_storage_use_zarr3=False checkpoint_storage_use_ocdbt=False \
81+ scan_layers=false prompt=' I love to' attention=\' dot_product\'
82+ fi
0 commit comments