|
| 1 | +# GPTOSS-20B E2E TPU Testing Implementation Plan |
| 2 | + |
| 3 | +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | +
|
| 5 | +**Goal:** Create a modular suite of E2E TPU testing scripts for GPTOSS-20B, excluding multimodal capabilities and aligning with the structure used by Gemma3-4B. |
| 6 | + |
| 7 | +**Architecture:** Split the monolithic `test_gpt_oss.sh` into modular scripts: `test_gpt_oss_to_mt.sh` (which installs common dependencies), `test_gpt_oss.sh` (pre-training baseline), `test_gpt_oss_sft.sh` (supervised fine-tuning), `test_gpt_oss_rl.sh` (reinforcement learning), and `test_gpt_oss_to_hf.sh` (reverse checkpoint conversion running last). |
| 8 | + |
| 9 | +**Tech Stack:** Bash, Python, JAX, MaxText, PyTorch (for conversion). |
| 10 | + |
| 11 | +## Global Constraints |
| 12 | +- Target directory: `tests/end_to_end/tpu/gpt_oss/20b/` |
| 13 | +- No multimodal functionality (multimodal excluded). |
| 14 | +- Dependencies must be installed in `test_gpt_oss_to_mt.sh` first, so subsequent scripts do not repeat them. |
| 15 | +- Reverse conversion to Hugging Face (`test_gpt_oss_to_hf.sh`) must be the final pipeline step. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +### Task 1: Checkpoint Conversion to MaxText & Logit Verification |
| 20 | + |
| 21 | +**Files:** |
| 22 | +- Create: `tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_to_mt.sh` |
| 23 | + |
| 24 | +- [ ] **Step 1: Create and write the file** |
| 25 | +Write the following contents to `tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_to_mt.sh`: |
| 26 | +```bash |
| 27 | +#!/bin/bash |
| 28 | + |
| 29 | +# Converts GPTOSS-20B HuggingFace checkpoint to MaxText format and validates logit correctness. |
| 30 | + |
| 31 | +set -ex |
| 32 | + |
| 33 | +run_id=${1:-$(date +%Y-%m-%d-%H-%M-%S)} |
| 34 | +export MODEL_NAME='gpt-oss-20b' |
| 35 | +export TOKENIZER_PATH='openai/gpt-oss-20b' |
| 36 | + |
| 37 | +if [ -z "${BASE_OUTPUT_PATH}" ]; then |
| 38 | + export BASE_OUTPUT_PATH=gs://runner-maxtext-logs/${MODEL_NAME} |
| 39 | +fi |
| 40 | +BASE_OUTPUT_PATH=${BASE_OUTPUT_PATH%/} |
| 41 | +echo "Using BASE_OUTPUT_PATH = ${BASE_OUTPUT_PATH}" |
| 42 | + |
| 43 | +# Install dependencies (CPU) required for checkpoint conversion & logit check |
| 44 | +python3 -m pip install torch --index-url https://download.pytorch.org/whl/cpu |
| 45 | + |
| 46 | +if [ -z "${CKPT_DISK_LOCATION}" ]; then |
| 47 | + export CKPT_BUCKET=gs://maxtext-model-checkpoints/gpt-oss-20b/hf-bf16 |
| 48 | + gcloud storage cp -r ${CKPT_BUCKET} /tmp |
| 49 | + export CKPT_DISK_LOCATION=/tmp/hf-bf16 |
| 50 | +fi |
| 51 | + |
| 52 | +# 1. Convert to scanned checkpoint (for training) |
| 53 | +JAX_PLATFORMS=cpu python3 -m maxtext.checkpoint_conversion.standalone_scripts.convert_gpt_oss_ckpt \ |
| 54 | + --base-model-path ${CKPT_DISK_LOCATION} \ |
| 55 | + --maxtext-model-path ${BASE_OUTPUT_PATH}/scanned/${run_id} \ |
| 56 | + --model-size ${MODEL_NAME} |
| 57 | + |
| 58 | +SCANNED_CKPT_PATH=${BASE_OUTPUT_PATH}/scanned/${run_id}/0/items |
| 59 | +echo "Scanned checkpoint path: ${SCANNED_CKPT_PATH}" |
| 60 | + |
| 61 | +# 2. Convert to unscanned checkpoint (for inference) |
| 62 | +JAX_PLATFORMS=cpu python3 -m maxtext.checkpoint_conversion.standalone_scripts.convert_gpt_oss_unscanned_ckpt \ |
| 63 | + --base-model-path ${CKPT_DISK_LOCATION} \ |
| 64 | + --maxtext-model-path ${BASE_OUTPUT_PATH}/unscanned/${run_id} \ |
| 65 | + --model-size ${MODEL_NAME} |
| 66 | + |
| 67 | +UNSCANNED_CKPT_PATH=${BASE_OUTPUT_PATH}/unscanned/${run_id}/0/items |
| 68 | +echo "Unscanned checkpoint path: ${UNSCANNED_CKPT_PATH}" |
| 69 | + |
| 70 | +# 3. Logit correctness check |
| 71 | +python3 -m tests.utils.forward_pass_logit_checker \ |
| 72 | + "${MAXTEXT_CONFIGS_DIR:-${MAXTEXT_REPO_ROOT:-$PWD}/src/maxtext/configs}"/base.yml \ |
| 73 | + base_output_directory=${BASE_OUTPUT_PATH} \ |
| 74 | + run_name=forward_logits_check \ |
| 75 | + model_name=${MODEL_NAME} \ |
| 76 | + load_parameters_path=${UNSCANNED_CKPT_PATH} \ |
| 77 | + scan_layers=false \ |
| 78 | + attention=dot_product \ |
| 79 | + sparse_matmul=True \ |
| 80 | + megablox=True \ |
| 81 | + per_device_batch_size=1 \ |
| 82 | + max_target_length=4 \ |
| 83 | + max_prefill_predict_length=4 \ |
| 84 | + dtype=float32 \ |
| 85 | + --atol=0.1 --rtol=0.1 \ |
| 86 | + --max_kl_div=3e-4 |
| 87 | +``` |
| 88 | + |
| 89 | +- [ ] **Step 2: Make the script executable** |
| 90 | +Run: `chmod +x tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_to_mt.sh` |
| 91 | + |
| 92 | +- [ ] **Step 3: Run baseline logit check to verify conversion fails/passes properly** |
| 93 | +Run: `bash tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_to_mt.sh` |
| 94 | +Expected: Completion of dependencies installation and starting conversion. (If CPU OOMs, note it as an issue). |
| 95 | + |
| 96 | +- [ ] **Step 4: Commit** |
| 97 | +```bash |
| 98 | +git add tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_to_mt.sh |
| 99 | +git commit -m "test: add GPTOSS-20B HF to MT checkpoint conversion test script" |
| 100 | +``` |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +### Task 2: Refactor Baseline Pre-training Script |
| 105 | + |
| 106 | +**Files:** |
| 107 | +- Modify: `tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss.sh` |
| 108 | + |
| 109 | +- [ ] **Step 1: Refactor the file contents** |
| 110 | +Replace the content of `tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss.sh` with the following simplified pre-training flow: |
| 111 | +```bash |
| 112 | +#!/bin/bash |
| 113 | + |
| 114 | +# Validates the GPTOSS-20B pre-training pipeline starting from converted MaxText checkpoint. |
| 115 | + |
| 116 | +set -ex |
| 117 | + |
| 118 | +run_id=${1:-$(date +%Y-%m-%d-%H-%M-%S)} |
| 119 | +export MODEL_NAME='gpt-oss-20b' |
| 120 | +export TOKENIZER_PATH='openai/gpt-oss-20b' |
| 121 | + |
| 122 | +if [ -z "${BASE_OUTPUT_PATH}" ]; then |
| 123 | + export BASE_OUTPUT_PATH=gs://runner-maxtext-logs/${MODEL_NAME} |
| 124 | +fi |
| 125 | +BASE_OUTPUT_PATH=${BASE_OUTPUT_PATH%/} |
| 126 | + |
| 127 | +export SCANNED_CKPT_PATH=${BASE_OUTPUT_PATH}/scanned/${run_id}/0/items |
| 128 | +export UNSCANNED_CKPT_PATH=${BASE_OUTPUT_PATH}/unscanned/${run_id}/0/items |
| 129 | + |
| 130 | +# 1. Run Pre-training using synthetic dataset with Megablocks |
| 131 | +python3 -m maxtext.trainers.pre_train.train \ |
| 132 | + "${MAXTEXT_CONFIGS_DIR:-${MAXTEXT_REPO_ROOT:-$PWD}/src/maxtext/configs}"/base.yml \ |
| 133 | + base_output_directory=${BASE_OUTPUT_PATH}/train \ |
| 134 | + run_name=${run_id} \ |
| 135 | + model_name=${MODEL_NAME} \ |
| 136 | + tokenizer_type=huggingface \ |
| 137 | + tokenizer_path=${TOKENIZER_PATH} \ |
| 138 | + dataset_type=synthetic \ |
| 139 | + enable_checkpointing=true \ |
| 140 | + async_checkpointing=false \ |
| 141 | + load_parameters_path=${SCANNED_CKPT_PATH} \ |
| 142 | + attention=flash \ |
| 143 | + sparse_matmul=True \ |
| 144 | + megablox=True \ |
| 145 | + dtype=bfloat16 \ |
| 146 | + weight_dtype=bfloat16 \ |
| 147 | + per_device_batch_size=4 \ |
| 148 | + steps=5 \ |
| 149 | + max_target_length=1024 \ |
| 150 | + ici_fsdp_parallelism=4 \ |
| 151 | + gcs_metrics=true |
| 152 | + |
| 153 | +# 2. Run Verification Decoding from the converted checkpoint |
| 154 | +python3 -m maxtext.inference.decode \ |
| 155 | + "${MAXTEXT_CONFIGS_DIR:-${MAXTEXT_REPO_ROOT:-$PWD}/src/maxtext/configs}"/base.yml \ |
| 156 | + base_output_directory=${BASE_OUTPUT_PATH} \ |
| 157 | + run_name=decode \ |
| 158 | + model_name=${MODEL_NAME} \ |
| 159 | + tokenizer_type=huggingface \ |
| 160 | + tokenizer_path=${TOKENIZER_PATH} \ |
| 161 | + load_parameters_path=${UNSCANNED_CKPT_PATH} \ |
| 162 | + scan_layers=False \ |
| 163 | + attention=dot_product \ |
| 164 | + sparse_matmul=True \ |
| 165 | + megablox=True \ |
| 166 | + dtype=bfloat16 \ |
| 167 | + weight_dtype=bfloat16 \ |
| 168 | + per_device_batch_size=1 \ |
| 169 | + max_prefill_predict_length=64 \ |
| 170 | + max_target_length=128 \ |
| 171 | + prompt="I love to" \ |
| 172 | + ici_fsdp_parallelism=1 \ |
| 173 | + ici_tensor_parallelism=4 |
| 174 | +``` |
| 175 | + |
| 176 | +- [ ] **Step 2: Commit** |
| 177 | +```bash |
| 178 | +git add tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss.sh |
| 179 | +git commit -m "test: refactor GPTOSS-20B pre-training baseline test script" |
| 180 | +``` |
| 181 | + |
| 182 | +--- |
| 183 | + |
| 184 | +### Task 3: Supervised Fine-Tuning Pipeline |
| 185 | + |
| 186 | +**Files:** |
| 187 | +- Create: `tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_sft.sh` |
| 188 | + |
| 189 | +- [ ] **Step 1: Create and write the file** |
| 190 | +Write the following contents to `tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_sft.sh`: |
| 191 | +```bash |
| 192 | +#!/bin/bash |
| 193 | + |
| 194 | +# Validates the GPTOSS-20B Supervised Fine-Tuning (SFT) pipeline. |
| 195 | + |
| 196 | +set -ex |
| 197 | + |
| 198 | +run_id=${1:-$(date +%Y-%m-%d-%H-%M-%S)} |
| 199 | +export MODEL_NAME='gpt-oss-20b' |
| 200 | +export TOKENIZER_PATH='openai/gpt-oss-20b' |
| 201 | + |
| 202 | +if [ -z "${BASE_OUTPUT_PATH}" ]; then |
| 203 | + export BASE_OUTPUT_PATH=gs://runner-maxtext-logs/${MODEL_NAME} |
| 204 | +fi |
| 205 | +BASE_OUTPUT_PATH=${BASE_OUTPUT_PATH%/} |
| 206 | + |
| 207 | +export SCANNED_CKPT_PATH=${BASE_OUTPUT_PATH}/scanned/${run_id}/0/items |
| 208 | + |
| 209 | +# 1. Run Supervised Fine-Tuning |
| 210 | +python3 -m maxtext.trainers.post_train.sft.train_sft_native \ |
| 211 | + "${MAXTEXT_CONFIGS_DIR:-${MAXTEXT_REPO_ROOT:-$PWD}/src/maxtext/configs/post_train}"/sft.yml \ |
| 212 | + base_output_directory=${BASE_OUTPUT_PATH}/sft \ |
| 213 | + run_name=${run_id} \ |
| 214 | + model_name=${MODEL_NAME} \ |
| 215 | + tokenizer_type=huggingface \ |
| 216 | + tokenizer_path=${TOKENIZER_PATH} \ |
| 217 | + dataset_type=hf \ |
| 218 | + enable_checkpointing=true \ |
| 219 | + async_checkpointing=false \ |
| 220 | + load_parameters_path=${SCANNED_CKPT_PATH} \ |
| 221 | + scan_layers=True \ |
| 222 | + attention=flash \ |
| 223 | + sparse_matmul=True \ |
| 224 | + megablox=True \ |
| 225 | + dtype=bfloat16 \ |
| 226 | + weight_dtype=bfloat16 \ |
| 227 | + per_device_batch_size=4 \ |
| 228 | + steps=5 \ |
| 229 | + max_target_length=1024 \ |
| 230 | + ici_fsdp_parallelism=1 \ |
| 231 | + ici_expert_parallelism=4 \ |
| 232 | + gcs_metrics=true \ |
| 233 | + abort_on_nan_loss=false |
| 234 | + |
| 235 | +# 2. Run Decoding on the newly produced SFT checkpoint |
| 236 | +python3 -m maxtext.inference.decode \ |
| 237 | + "${MAXTEXT_CONFIGS_DIR:-${MAXTEXT_REPO_ROOT:-$PWD}/src/maxtext/configs}"/base.yml \ |
| 238 | + base_output_directory=${BASE_OUTPUT_PATH} \ |
| 239 | + run_name=decode_sft \ |
| 240 | + model_name=${MODEL_NAME} \ |
| 241 | + tokenizer_type=huggingface \ |
| 242 | + tokenizer_path=${TOKENIZER_PATH} \ |
| 243 | + load_parameters_path=${BASE_OUTPUT_PATH}/sft/${run_id}/checkpoints/4/items \ |
| 244 | + scan_layers=True \ |
| 245 | + attention=dot_product \ |
| 246 | + sparse_matmul=True \ |
| 247 | + megablox=True \ |
| 248 | + dtype=bfloat16 \ |
| 249 | + weight_dtype=bfloat16 \ |
| 250 | + per_device_batch_size=1 \ |
| 251 | + max_prefill_predict_length=64 \ |
| 252 | + max_target_length=128 \ |
| 253 | + prompt="I love to" \ |
| 254 | + ici_fsdp_parallelism=1 \ |
| 255 | + ici_tensor_parallelism=4 |
| 256 | +``` |
| 257 | + |
| 258 | +- [ ] **Step 2: Make the script executable** |
| 259 | +Run: `chmod +x tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_sft.sh` |
| 260 | + |
| 261 | +- [ ] **Step 3: Commit** |
| 262 | +```bash |
| 263 | +git add tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_sft.sh |
| 264 | +git commit -m "test: add GPTOSS-20B SFT pipeline test script" |
| 265 | +``` |
| 266 | + |
| 267 | +--- |
| 268 | + |
| 269 | +### Task 4: Reinforcement Learning Pipeline |
| 270 | + |
| 271 | +**Files:** |
| 272 | +- Create: `tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_rl.sh` |
| 273 | + |
| 274 | +- [ ] **Step 1: Create and write the file** |
| 275 | +Write the following contents to `tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_rl.sh`: |
| 276 | +```bash |
| 277 | +#!/bin/bash |
| 278 | + |
| 279 | +# Validates the GPTOSS-20B Reinforcement Learning (RL) pipeline using GRPO. |
| 280 | + |
| 281 | +set -ex |
| 282 | + |
| 283 | +run_id=${1:-$(date +%Y-%m-%d-%H-%M-%S)} |
| 284 | +export MODEL_NAME='gpt-oss-20b' |
| 285 | +export TOKENIZER_PATH='openai/gpt-oss-20b' |
| 286 | + |
| 287 | +if [ -z "${BASE_OUTPUT_PATH}" ]; then |
| 288 | + export BASE_OUTPUT_PATH=gs://runner-maxtext-logs/${MODEL_NAME} |
| 289 | +fi |
| 290 | +BASE_OUTPUT_PATH=${BASE_OUTPUT_PATH%/} |
| 291 | + |
| 292 | +export SCANNED_CKPT_PATH=${BASE_OUTPUT_PATH}/scanned/${run_id}/0/items |
| 293 | + |
| 294 | +# 1. Run GRPO Reinforcement Learning |
| 295 | +python3 -m maxtext.trainers.post_train.rl.train_rl \ |
| 296 | + base_output_directory=${BASE_OUTPUT_PATH}/rl \ |
| 297 | + load_parameters_path=${SCANNED_CKPT_PATH} \ |
| 298 | + run_name=${run_id} \ |
| 299 | + rl.loss_algo='grpo' \ |
| 300 | + scan_layers=true \ |
| 301 | + num_batches=5 \ |
| 302 | + batch_size=1 \ |
| 303 | + num_test_batches=5 \ |
| 304 | + model_name=${MODEL_NAME} \ |
| 305 | + checkpoint_storage_use_zarr3=False \ |
| 306 | + checkpoint_storage_use_ocdbt=False \ |
| 307 | + rollout_tensor_parallelism=1 \ |
| 308 | + vllm_hf_overrides='{architectures: ["MaxTextForCausalLM"]}' \ |
| 309 | + vllm_additional_config='{"maxtext_config": {"model_name": "gpt-oss-20b", "log_config": "false"}}' |
| 310 | + |
| 311 | +# 2. Run Verification Decoding on the newly produced actor checkpoint |
| 312 | +python3 -m maxtext.inference.decode \ |
| 313 | + "${MAXTEXT_CONFIGS_DIR:-${MAXTEXT_REPO_ROOT:-$PWD}/src/maxtext/configs}"/base.yml \ |
| 314 | + base_output_directory=${BASE_OUTPUT_PATH} \ |
| 315 | + run_name=decode_rl \ |
| 316 | + model_name=${MODEL_NAME} \ |
| 317 | + tokenizer_type=huggingface \ |
| 318 | + tokenizer_path=${TOKENIZER_PATH} \ |
| 319 | + load_parameters_path=${BASE_OUTPUT_PATH}/rl/${run_id}/checkpoints/actor/4/items \ |
| 320 | + scan_layers=True \ |
| 321 | + attention=dot_product \ |
| 322 | + sparse_matmul=True \ |
| 323 | + megablox=True \ |
| 324 | + dtype=bfloat16 \ |
| 325 | + weight_dtype=bfloat16 \ |
| 326 | + per_device_batch_size=1 \ |
| 327 | + max_prefill_predict_length=64 \ |
| 328 | + max_target_length=128 \ |
| 329 | + prompt="I love to" \ |
| 330 | + ici_fsdp_parallelism=1 \ |
| 331 | + ici_tensor_parallelism=4 |
| 332 | +``` |
| 333 | + |
| 334 | +- [ ] **Step 2: Make the script executable** |
| 335 | +Run: `chmod +x tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_rl.sh` |
| 336 | + |
| 337 | +- [ ] **Step 3: Commit** |
| 338 | +```bash |
| 339 | +git add tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_rl.sh |
| 340 | +git commit -m "test: add GPTOSS-20B RL pipeline test script" |
| 341 | +``` |
| 342 | + |
| 343 | +--- |
| 344 | + |
| 345 | +### Task 5: Checkpoint Conversion to Hugging Face |
| 346 | + |
| 347 | +**Files:** |
| 348 | +- Create: `tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_to_hf.sh` |
| 349 | + |
| 350 | +- [ ] **Step 1: Create and write the file** |
| 351 | +Write the following contents to `tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_to_hf.sh`: |
| 352 | +```bash |
| 353 | +#!/bin/bash |
| 354 | + |
| 355 | +# Converts a MaxText checkpoint to a Hugging Face model checkpoint for GPTOSS-20B. |
| 356 | + |
| 357 | +set -ex |
| 358 | + |
| 359 | +run_id=$1 |
| 360 | +CKPT_PATH=$2 |
| 361 | +SCAN_LAYERS=${3:-false} |
| 362 | + |
| 363 | +export MODEL_NAME='gpt-oss-20b' |
| 364 | + |
| 365 | +if [ -z "${BASE_OUTPUT_PATH}" ]; then |
| 366 | + export BASE_OUTPUT_PATH=gs://runner-maxtext-logs/${MODEL_NAME} |
| 367 | +fi |
| 368 | +BASE_OUTPUT_PATH=${BASE_OUTPUT_PATH%/} |
| 369 | + |
| 370 | +if [ "${SCAN_LAYERS,,}" = "true" ]; then |
| 371 | + scan_status="scanned" |
| 372 | +else |
| 373 | + scan_status="unscanned" |
| 374 | +fi |
| 375 | + |
| 376 | +python3 -m maxtext.checkpoint_conversion.to_huggingface \ |
| 377 | + model_name=${MODEL_NAME} \ |
| 378 | + tokenizer_type="huggingface" \ |
| 379 | + load_parameters_path=${CKPT_PATH} \ |
| 380 | + base_output_directory=${BASE_OUTPUT_PATH}/to_huggingface/${scan_status}/${run_id} \ |
| 381 | + use_multimodal=false \ |
| 382 | + scan_layers=$SCAN_LAYERS |
| 383 | +``` |
| 384 | + |
| 385 | +- [ ] **Step 2: Make the script executable** |
| 386 | +Run: `chmod +x tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_to_hf.sh` |
| 387 | + |
| 388 | +- [ ] **Step 3: Commit** |
| 389 | +```bash |
| 390 | +git add tests/end_to_end/tpu/gpt_oss/20b/test_gpt_oss_to_hf.sh |
| 391 | +git commit -m "test: add GPTOSS-20B to HF checkpoint conversion test script" |
| 392 | +``` |
0 commit comments