|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Validates the Qwen3 RL 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 RL starting from the pre-converted checkpoint. |
| 8 | +# 3. Run inference on the checkpoint produced by the RL 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_qwen3_to_mt.sh $RUN_ID |
| 14 | +# bash test_qwen3_rl.sh $RUN_ID |
| 15 | + |
| 16 | +set -ex |
| 17 | + |
| 18 | +export VLLM_WORKER_MULTIPROC_METHOD=spawn |
| 19 | +export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=upb |
| 20 | +export VLLM_RAY_EXTRA_ENV_VARS_TO_COPY="PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION" |
| 21 | +export VLLM_ENABLE_V1_MULTIPROCESSING=0 |
| 22 | +export JAX_RANDOM_WEIGHTS=1 |
| 23 | +export SKIP_JAX_PRECOMPILE=1 |
| 24 | +export NEW_MODEL_DESIGN=1 |
| 25 | +export TPU_MIN_LOG_LEVEL=0 |
| 26 | +export TF_CPP_MIN_LOG_LEVEL=0 |
| 27 | +export TPU_STDERR_LOG_LEVEL=0 |
| 28 | + |
| 29 | +# Force Python to use "spawn" instead of "fork" for multiprocessing to prevent gRPC socket corruption |
| 30 | +cat << 'EOF' > usercustomize.py |
| 31 | +import multiprocessing |
| 32 | +try: |
| 33 | + multiprocessing.set_start_method("spawn", force=True) |
| 34 | +except Exception: |
| 35 | + pass |
| 36 | +EOF |
| 37 | +export PYTHONPATH=${PYTHONPATH:-.}:$(pwd) |
| 38 | +run_id=${1:-$(date +%Y-%m-%d-%H-%M-%S)} |
| 39 | +MODEL_NAME='qwen3-30b-a3b-base' |
| 40 | + |
| 41 | +BASE_OUTPUT_DIRECTORY=gs://runner-maxtext-logs/${MODEL_NAME} |
| 42 | +UNSCANNED_CKPT_PATH=${BASE_OUTPUT_DIRECTORY}/to_maxtext/unscanned/${run_id}/0/items |
| 43 | +SCANNED_CKPT_PATH=${BASE_OUTPUT_DIRECTORY}/to_maxtext/scanned/${run_id}/0/items |
| 44 | + |
| 45 | +# Step 1: Run inference on the pre-converted checkpoint |
| 46 | +python3 -m maxtext.inference.vllm_decode \ |
| 47 | + model_name=${MODEL_NAME} \ |
| 48 | + load_parameters_path=${SCANNED_CKPT_PATH} \ |
| 49 | + vllm_hf_overrides='{architectures: ["MaxTextForCausalLM"]}' \ |
| 50 | + hbm_utilization_vllm=0.85 \ |
| 51 | + prompt='Suggest some famous landmarks in London.' \ |
| 52 | + max_target_length=256 max_num_batched_tokens=256 \ |
| 53 | + ici_tensor_parallelism=8 \ |
| 54 | + allow_split_physical_axes=True prefuse_moe_weights=True \ |
| 55 | + use_chat_template=True scan_layers=True enable_single_controller=True |
| 56 | + |
| 57 | +# Step 2: Run RL starting from the pre-converted checkpoint |
| 58 | +python3 -m maxtext.trainers.post_train.rl.train_rl \ |
| 59 | + base_output_directory=${BASE_OUTPUT_DIRECTORY}/rl \ |
| 60 | + load_parameters_path=${SCANNED_CKPT_PATH} \ |
| 61 | + run_name=${run_id} rl.loss_algo='grpo' scan_layers=True \ |
| 62 | + num_batches=5 batch_size=4 train_micro_batch_size=1 num_test_batches=5 \ |
| 63 | + model_name=${MODEL_NAME} enable_single_controller=True \ |
| 64 | + checkpoint_storage_use_zarr3=False checkpoint_storage_use_ocdbt=False \ |
| 65 | + rollout_tensor_parallelism=8 \ |
| 66 | + vllm_hf_overrides='{architectures: ["MaxTextForCausalLM"]}' \ |
| 67 | + vllm_additional_config='{"maxtext_config": {"model_name": "'${MODEL_NAME}'", "allow_split_physical_axes": true, "scan_layers": false, "prefuse_moe_weights": True}}' \ |
| 68 | + remat_policy=full hbm_utilization_vllm=0.55 use_pathways=True \ |
| 69 | + chips_per_vm=8 ici_tensor_parallelism=4\ |
| 70 | + max_target_length=512 weight_dtype=bfloat16 dtype=bfloat16 opt_type=sgd \ |
| 71 | + enable_tunix_perf_metrics=True rl.num_generations=16 \ |
| 72 | + debug.rl=False rl.reshard_chunk_size=1 |
| 73 | + |
| 74 | +# Step 3: Run inference on the checkpoint produced by the RL run |
| 75 | +python3 -m maxtext.inference.vllm_decode \ |
| 76 | + model_name=${MODEL_NAME} \ |
| 77 | + load_parameters_path=${BASE_OUTPUT_DIRECTORY}/rl/${run_id}/checkpoints/actor/4/items \ |
| 78 | + vllm_hf_overrides='{architectures: ["MaxTextForCausalLM"]}' \ |
| 79 | + hbm_utilization_vllm=0.85 \ |
| 80 | + prompt='Suggest some famous landmarks in London.' \ |
| 81 | + max_target_length=256 max_num_batched_tokens=256 \ |
| 82 | + ici_tensor_parallelism=8 \ |
| 83 | + allow_split_physical_axes=True prefuse_moe_weights=True \ |
| 84 | + use_chat_template=True scan_layers=True enable_single_controller=True |
0 commit comments