-
Notifications
You must be signed in to change notification settings - Fork 747
Add torchao checkpoint tests #14074
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
Merged
Add torchao checkpoint tests #14074
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
93d300e
Support pytorch_bin format
metascroy 7e2fbd5
up
metascroy ab15cf7
up
metascroy 024b0da
up
metascroy 57dbf96
lint
metascroy 51f41cb
Add quantized checkpoint tests
metascroy 3af11d6
up
metascroy ba6fb4b
up
metascroy c3b6f0e
up
metascroy ed15610
up
metascroy 62b25ca
up
metascroy e2a3abb
up
metascroy 13004c2
up
metascroy 1a8e1d7
up
metascroy 7647ed9
up
metascroy 2f47f54
up
metascroy 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # ------------------------- | ||
| # Args / flags | ||
| # ------------------------- | ||
| TEST_WITH_RUNNER=0 | ||
| MODEL_NAME="" | ||
|
|
||
| # Parse args | ||
| if [[ $# -lt 1 ]]; then | ||
| echo "Usage: $0 <model_name> [--test_with_runner]" | ||
| echo "Supported model_name values: qwen3_4b, phi_4_mini" | ||
| exit 1 | ||
| fi | ||
|
|
||
| MODEL_NAME="$1" | ||
| shift | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --test_with_runner) | ||
| TEST_WITH_RUNNER=1 | ||
| ;; | ||
| -h|--help) | ||
| echo "Usage: $0 <model_name> [--test_with_runner]" | ||
| echo " model_name: qwen3_4b | phi_4_mini" | ||
| echo " --test_with_runner: build ET + run llama_main to sanity-check the export" | ||
| exit 0 | ||
| ;; | ||
| *) | ||
| echo "Unknown option: $1" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| shift | ||
| done | ||
|
|
||
| if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then | ||
| PYTHON_EXECUTABLE=python3 | ||
| fi | ||
|
|
||
| MODEL_OUT=model.pte | ||
|
|
||
| case "$MODEL_NAME" in | ||
| qwen3_4b) | ||
| echo "Running Qwen3-4B export..." | ||
| HF_MODEL_DIR=$(hf download pytorch/Qwen3-4B-INT8-INT4) | ||
| EXPECTED_MODEL_SIZE_UPPER_BOUND=$((3 * 1024 * 1024 * 1024)) # 3GB | ||
| $PYTHON_EXECUTABLE -m executorch.examples.models.qwen3.convert_weights \ | ||
| $HF_MODEL_DIR \ | ||
| pytorch_model_converted.bin | ||
|
|
||
| $PYTHON_EXECUTABLE -m executorch.examples.models.llama.export_llama \ | ||
| --model "qwen3_4b" \ | ||
| --checkpoint pytorch_model_converted.bin \ | ||
| --params examples/models/qwen3/config/4b_config.json \ | ||
| --output_name $MODEL_OUT \ | ||
| -kv \ | ||
| --use_sdpa_with_kv_cache \ | ||
| -X \ | ||
| --xnnpack-extended-ops \ | ||
| --max_context_length 1024 \ | ||
| --max_seq_length 1024 \ | ||
| --dtype fp32 \ | ||
| --metadata '{"get_bos_id":199999, "get_eos_ids":[200020,199999]}' | ||
| ;; | ||
|
|
||
| phi_4_mini) | ||
| echo "Running Phi-4-mini export..." | ||
| HF_MODEL_DIR=$(hf download pytorch/Phi-4-mini-instruct-INT8-INT4) | ||
| EXPECTED_MODEL_SIZE_UPPER_BOUND=$((3 * 1024 * 1024 * 1024)) # 3GB | ||
| $PYTHON_EXECUTABLE -m executorch.examples.models.phi_4_mini.convert_weights \ | ||
| $HF_MODEL_DIR \ | ||
| pytorch_model_converted.bin | ||
|
|
||
| $PYTHON_EXECUTABLE -m executorch.examples.models.llama.export_llama \ | ||
| --model "phi_4_mini" \ | ||
| --checkpoint pytorch_model_converted.bin \ | ||
| --params examples/models/phi_4_mini/config/config.json \ | ||
| --output_name $MODEL_OUT \ | ||
| -kv \ | ||
| --use_sdpa_with_kv_cache \ | ||
| -X \ | ||
| --xnnpack-extended-ops \ | ||
| --max_context_length 1024 \ | ||
| --max_seq_length 1024 \ | ||
| --dtype fp32 \ | ||
| --metadata '{"get_bos_id":199999, "get_eos_ids":[200020,199999]}' | ||
| ;; | ||
|
|
||
| *) | ||
| echo "Error: unsupported model_name '$MODEL_NAME'" | ||
| echo "Supported values: qwen3_4b, phi_4_mini" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| # Check file size | ||
| MODEL_SIZE=$(stat --printf="%s" $MODEL_OUT 2>/dev/null || stat -f%z $MODEL_OUT) | ||
| if [[ $MODEL_SIZE -gt $EXPECTED_MODEL_SIZE_UPPER_BOUND ]]; then | ||
| echo "Error: model size $MODEL_SIZE is greater than expected upper bound $EXPECTED_MODEL_SIZE_UPPER_BOUND" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Install ET with CMake | ||
| if [[ "$TEST_WITH_RUNNER" -eq 1 ]]; then | ||
| echo "[runner] Building and testing llama_main ..." | ||
| cmake -DPYTHON_EXECUTABLE=python \ | ||
| -DCMAKE_INSTALL_PREFIX=cmake-out \ | ||
| -DEXECUTORCH_ENABLE_LOGGING=1 \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ | ||
| -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ | ||
| -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ | ||
| -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \ | ||
| -DEXECUTORCH_BUILD_XNNPACK=ON \ | ||
| -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \ | ||
| -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \ | ||
| -DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER=ON \ | ||
| -DEXECUTORCH_BUILD_EXTENSION_LLM=ON \ | ||
| -DEXECUTORCH_BUILD_KERNELS_LLM=ON \ | ||
| -Bcmake-out . | ||
| cmake --build cmake-out -j16 --config Release --target install | ||
|
Comment on lines
+109
to
+124
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we just test via the preset now?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to work. I'm reverting back to not using the preset. I filed an issue here: #14132 |
||
|
|
||
|
|
||
| # Install llama runner | ||
| cmake -DPYTHON_EXECUTABLE=python \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -Bcmake-out/examples/models/llama \ | ||
| examples/models/llama | ||
| cmake --build cmake-out/examples/models/llama -j16 --config Release | ||
|
|
||
| # Run the model | ||
| ./cmake-out/examples/models/llama/llama_main --model_path=$MODEL_OUT --tokenizer_path="${HF_MODEL_DIR}/tokenizer.json" --prompt="Once upon a time," | ||
| fi | ||
|
|
||
| # Clean up | ||
| rm -f pytorch_model_converted.bin "$MODEL_OUT" | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use -x as well for scripts that will run in CI; makes debugging easier