Repository navigation
Add end-to-end XLML test scripts and documentation for Qwen3.8-2.4T-A95B #5773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+187
−8
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
tests/end_to_end/tpu/qwen/moe/qwen3.8-2.4t-a95b/1_test_qwen3.8_2.4t_a95b.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #!/bin/bash | ||
|
|
||
| # This file is documentation for how to get started with Qwen3.8-2.4T. | ||
|
|
||
| # This file runs Step 1 on CPU. | ||
| # 1. Convert the HuggingFace checkpoint (bf16) to MaxText-compatible checkpoint (bf16): | ||
| # Scanned format is better for training; unscanned format is better for decoding. | ||
| # 2. Run logit check, pre-training, fine-tuning, and decoding. | ||
| # --- | ||
| # Example Usage: | ||
| # | ||
| # bash tests/end_to_end/tpu/qwen/moe/qwen3.8-2.4t-a95b/1_test_qwen3.8_2.4t_a95b.sh | ||
| # --- | ||
|
|
||
| set -ex | ||
|
|
||
| export MODEL_NAME="${MODEL_NAME:-qwen3.8-2.4t-a95b}" | ||
| export TOKENIZER_PATH="${TOKENIZER_PATH:-Qwen/Qwen3.8-2.4T-A95B}" | ||
|
|
||
| # (Optional) Path to your local Hugging Face checkpoint | ||
| export HF_MODEL_PATH="${HF_MODEL_PATH:-}" | ||
|
|
||
| # Base output path for MaxText generations. | ||
| export BASE_OUTPUT_PATH="${BASE_OUTPUT_PATH:-gs://your-gcs-bucket/qwen3.8-2.4t-a95b_maxtext_ckpt}" | ||
|
|
||
| if [ -z "${HF_TOKEN}" ] && [ -z "${HF_MODEL_PATH}" ]; then | ||
| echo "Error: HF_TOKEN environment variable is not set and HF_MODEL_PATH is not provided. Please export your Hugging Face token." | ||
| echo "Example: export HF_TOKEN=hf_..." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Strip trailing slash from base path to avoid malformed URIs | ||
| BASE_OUTPUT_PATH=${BASE_OUTPUT_PATH%/} | ||
| echo "Using BASE_OUTPUT_PATH = ${BASE_OUTPUT_PATH}" | ||
|
|
||
| # Install torch for checkpoint conversion and forward_pass_logit_checker.py | ||
| python3 -m pip install torch --index-url https://download.pytorch.org/whl/cpu | ||
|
|
||
| # Setup local HF path argument if one was provided | ||
| HF_LOCAL_ARG="" | ||
| if [ -n "${HF_MODEL_PATH}" ]; then | ||
| HF_LOCAL_ARG="hf_model_path=${HF_MODEL_PATH}" | ||
| fi | ||
|
|
||
| # 1.1 Convert checkpoint to `scanned` format, more suitable for training | ||
| JAX_PLATFORMS=cpu python3 -m maxtext.checkpoint_conversion.to_maxtext src/maxtext/configs/base.yml \ | ||
| model_name=${MODEL_NAME} \ | ||
| base_output_directory=${BASE_OUTPUT_PATH}/scanned \ | ||
| hf_access_token=${HF_TOKEN} \ | ||
| scan_layers=true \ | ||
| use_multimodal=false \ | ||
| ${HF_LOCAL_ARG} | ||
|
|
||
| # 1.2 Convert checkpoint to `unscanned` format, more suitable for decoding | ||
| JAX_PLATFORMS=cpu python3 -m maxtext.checkpoint_conversion.to_maxtext src/maxtext/configs/base.yml \ | ||
| model_name=${MODEL_NAME} \ | ||
| base_output_directory=${BASE_OUTPUT_PATH}/unscanned \ | ||
| hf_access_token=${HF_TOKEN} \ | ||
| scan_layers=false \ | ||
| use_multimodal=false \ | ||
| ${HF_LOCAL_ARG} |
71 changes: 71 additions & 0 deletions
71
tests/end_to_end/tpu/qwen/moe/qwen3.8-2.4t-a95b/2_test_qwen3.8_2.4t_a95b.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/bin/bash | ||
|
|
||
| # This file is documentation for how to get started with Qwen3.8-2.4T. | ||
|
|
||
| # This file runs Step 2 on v5p-512 on a daily basis. | ||
| # 1. Convert the HuggingFace checkpoint (bf16) to MaxText-compatible checkpoint (bf16): | ||
| # Scanned format is better for training; unscanned format is better for decoding. | ||
| # 2. Run logit check, pretraining, finetuning, and decoding. | ||
|
|
||
| # The golden logit can be generated by: | ||
| # python3 -m tests.assets.logits_generation.generate_hf_golden_logits --model-id=Qwen/Qwen3.8-2.4T-A95B --output-path=golden_data_qwen3.8-2.4t-a95b.jsonl --prompts='I love to' --hf-model-path=$local_bf16_path --trust-remote-code=False --hf-load-dtype=bfloat16 | ||
|
|
||
| set -ex | ||
|
|
||
| # Ensure JetStream and dependencies are installed for inference.decode | ||
| if ! python3 -c "import jetstream" &>/dev/null; then | ||
| python3 -m src.dependencies.scripts.install_pre_train_extra_deps --with-tf | ||
| fi | ||
|
|
||
| export LIBTPU_INIT_ARGS="--xla_tpu_scoped_vmem_limit_kib=65536" | ||
| export MODEL_NAME='qwen3.8-2.4t-a95b' | ||
| export TOKENIZER_PATH='Qwen/Qwen3.8-2.4T-A95B' | ||
|
|
||
| # Installing torch for checkpoint conversion and forward_pass_logit_checker.py | ||
| python3 -m pip install torch --index-url https://download.pytorch.org/whl/cpu | ||
|
|
||
| if [ -z "${HF_TOKEN}" ]; then | ||
| echo "Error: HF_TOKEN environment variable is not set. Please export your Hugging Face token." | ||
| echo "Example: export HF_TOKEN=hf_..." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -z "${BASE_OUTPUT_PATH}" ]; then | ||
| # Non-Googlers please remember to point `BASE_OUTPUT_PATH` to GCS buckets that you own, this script uses internal buckets for testing. | ||
| # this bucket will store all the files generated by MaxText during a run | ||
| export BASE_OUTPUT_PATH=gs://runner-maxtext-logs/$(date +%Y-%m-%d-%H-%M) | ||
| echo "BASE_OUTPUT_PATH is not set" | ||
| fi | ||
| BASE_OUTPUT_PATH=${BASE_OUTPUT_PATH%/} | ||
| echo using BASE_OUTPUT_PATH = ${BASE_OUTPUT_PATH} | ||
|
|
||
| # Step 2: | ||
| # We define the checkpoint paths. This way it is easier to use these paths in the `train.py` and `decode.py` commands | ||
| # export SCANNED_CKPT_PATH=${BASE_OUTPUT_PATH}/scanned/0/items | ||
| # export UNSCANNED_CKPT_PATH=${BASE_OUTPUT_PATH}/unscanned/0/items | ||
| # Use a hard-coded golden checkpoint, rather than checkpoints generated by Step 1 as it is not in daily test. | ||
| SCANNED_CKPT_PATH=gs://maxtext-model-checkpoints/qwen3.8-2.4t-a95b/scanned/0/items | ||
| UNSCANNED_CKPT_PATH=gs://maxtext-model-checkpoints/qwen3.8-2.4t-a95b/unscanned/0/items | ||
| # Non-Googlers please remember to point `DATASET_PATH` to the GCS bucket where you have your training data | ||
| export DATASET_PATH=gs://maxtext-dataset | ||
|
|
||
| # Test whether the forward pass logits match the golden logits | ||
| # default golden_logits_path=/deps/tests/assets/golden_logits/golden_data_{MODEL_NAME}.jsonl, copied from gs://maxtext-test-assets/golden_data_${MODEL_NAME}.jsonl | ||
| GOLDEN_LOGITS_DISK_LOCATION="/deps/tests/assets/golden_logits/golden_data_${MODEL_NAME}.jsonl" | ||
| if [ ! -f "${GOLDEN_LOGITS_DISK_LOCATION}" ]; then | ||
| GOLDEN_LOGITS_PATH="gs://maxtext-test-assets/golden_data_${MODEL_NAME}.jsonl" | ||
| GOLDEN_LOGITS_DISK_LOCATION=/tmp/golden_data.jsonl | ||
| gcloud storage cp ${GOLDEN_LOGITS_PATH} ${GOLDEN_LOGITS_DISK_LOCATION} | ||
| fi | ||
|
|
||
| python3 -m tests.utils.forward_pass_logit_checker ${MAXTEXT_CONFIGS_DIR:-${MAXTEXT_REPO_ROOT:-$PWD}/src/maxtext/configs}/base.yml base_output_directory=${BASE_OUTPUT_PATH} run_name=forward_logits_check load_parameters_path=${SCANNED_CKPT_PATH} scan_layers=true attention=dot_product per_device_batch_size=1 model_name=${MODEL_NAME} max_prefill_predict_length=4 max_target_length=4 async_checkpointing=false sparse_matmul=True megablox=True ici_fsdp_parallelism=64 ici_expert_parallelism=-1 weight_dtype=float32 dtype=float32 activations_in_float32=true matmul_precision=highest float32_logits=true float32_qk_product=true --golden_logits_path=${GOLDEN_LOGITS_DISK_LOCATION} --atol=1.5 --rtol=1.5 --max_kl_div=0.2 --skip_first_token | ||
|
|
||
| # Run pre-training | ||
| python3 -m maxtext.trainers.pre_train.train ${MAXTEXT_CONFIGS_DIR:-${MAXTEXT_REPO_ROOT:-$PWD}/src/maxtext/configs}/base.yml base_output_directory=${BASE_OUTPUT_PATH} run_name=q38_pre_training model_name=${MODEL_NAME} tokenizer_type=huggingface tokenizer_path=${TOKENIZER_PATH} dataset_type=grain grain_file_type=tfrecord dataset_path=${DATASET_PATH} enable_checkpointing=false attention=flash sparse_matmul=True megablox=True dtype=bfloat16 weight_dtype=bfloat16 per_device_batch_size=1 steps=5 max_target_length=256 ici_fsdp_parallelism=64 ici_expert_parallelism=-1 | ||
|
|
||
| # Run fine-tuning | ||
| python3 -m maxtext.trainers.pre_train.train ${MAXTEXT_CONFIGS_DIR:-${MAXTEXT_REPO_ROOT:-$PWD}/src/maxtext/configs}/base.yml base_output_directory=${BASE_OUTPUT_PATH} run_name=q38_fine_tuning model_name=${MODEL_NAME} tokenizer_type=huggingface tokenizer_path=${TOKENIZER_PATH} dataset_type=grain grain_file_type=tfrecord dataset_path=${DATASET_PATH} enable_checkpointing=false load_parameters_path=${SCANNED_CKPT_PATH} scan_layers=True attention=flash sparse_matmul=True megablox=True dtype=bfloat16 weight_dtype=bfloat16 per_device_batch_size=1 steps=5 max_target_length=256 ici_fsdp_parallelism=64 ici_expert_parallelism=-1 | ||
|
|
||
| # Run decoding | ||
| # Note decode requires the access token for huggingface tokenizer even if the model is not gated | ||
| python3 -m maxtext.inference.decode ${MAXTEXT_CONFIGS_DIR:-${MAXTEXT_REPO_ROOT:-$PWD}/src/maxtext/configs}/base.yml base_output_directory=${BASE_OUTPUT_PATH} run_name=decode model_name=${MODEL_NAME} tokenizer_type=huggingface tokenizer_path=${TOKENIZER_PATH} hf_access_token=${HF_TOKEN} load_parameters_path=${UNSCANNED_CKPT_PATH} scan_layers=False attention=dot_product sparse_matmul=True megablox=True dtype=bfloat16 weight_dtype=bfloat16 per_device_batch_size=1 max_prefill_predict_length=64 max_target_length=128 ici_fsdp_parallelism=1 ici_tensor_parallelism=1 ici_expert_parallelism=-1 prompt="An attention function can be described as mapping a query and a set of key-value pairs to an output, where the query, keys, values, and outputs are all vectors. The output is " | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.