-
Notifications
You must be signed in to change notification settings - Fork 602
Bump torchao + add unit tests for torchao kernels #9396
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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,85 @@ | ||
#!/bin/bash | ||
# Copyright (c) Qualcomm Innovation Center, Inc. | ||
# All rights reserved | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
set -exu | ||
|
||
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh" | ||
|
||
export EXECUTORCH_ROOT="$(dirname "${BASH_SOURCE[0]}")/../.." | ||
|
||
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then | ||
PYTHON_EXECUTABLE=python3 | ||
fi | ||
|
||
which "${PYTHON_EXECUTABLE}" | ||
|
||
# Update tokenizers submodule | ||
pushd $EXECUTORCH_ROOT/extension/llm/tokenizers | ||
echo "Update tokenizers submodule" | ||
git submodule update --init | ||
popd | ||
|
||
# Install ET with CMake | ||
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_MODULE=ON \ | ||
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \ | ||
-DEXECUTORCH_BUILD_XNNPACK=OFF \ | ||
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \ | ||
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \ | ||
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \ | ||
-Bcmake-out . | ||
cmake --build cmake-out -j16 --target install --config Release | ||
|
||
# Install llama runner with torchao | ||
cmake -DPYTHON_EXECUTABLE=python \ | ||
-DCMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())') \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \ | ||
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \ | ||
-DEXECUTORCH_BUILD_XNNPACK=OFF \ | ||
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \ | ||
-DEXECUTORCH_BUILD_TORCHAO=ON \ | ||
-Bcmake-out/examples/models/llama \ | ||
examples/models/llama | ||
cmake --build cmake-out/examples/models/llama -j16 --config Release | ||
|
||
# Download stories llama110m artifacts | ||
download_stories_model_artifacts | ||
|
||
echo "Creating tokenizer.bin" | ||
$PYTHON_EXECUTABLE -m extension.llm.tokenizer.tokenizer -t tokenizer.model -o tokenizer.bin | ||
|
||
# Export model | ||
LLAMA_CHECKPOINT=stories110M.pt | ||
LLAMA_PARAMS=params.json | ||
MODEL_OUT=model.pte | ||
TOKENIZER=tokenizer.bin | ||
|
||
# Set low-bit quantization parameters | ||
QLINEAR_BITWIDTH=3 # Can be 1-8 | ||
QLINEAR_GROUP_SIZE=128 # Must be multiple of 16 | ||
QEMBEDDING_BITWIDTH=4 # Can be 1-8 | ||
QEMBEDDING_GROUP_SIZE=32 # Must be multiple of 16 | ||
|
||
${PYTHON_EXECUTABLE} -m examples.models.llama.export_llama \ | ||
--checkpoint "${LLAMA_CHECKPOINT:?}" \ | ||
--params "${LLAMA_PARAMS:?}" \ | ||
-kv \ | ||
--use_sdpa_with_kv_cache \ | ||
--output_name=${MODEL_OUT} \ | ||
-qmode "torchao:8da${QLINEAR_BITWIDTH}w" \ | ||
--group_size ${QLINEAR_GROUP_SIZE} \ | ||
-E "torchao:${QEMBEDDING_BITWIDTH},${QEMBEDDING_GROUP_SIZE}" \ | ||
--disable_dynamic_shape \ | ||
-d fp32 | ||
|
||
# Test run | ||
./cmake-out/examples/models/llama/llama_main --model_path=$MODEL_OUT --tokenizer_path=$TOKENIZER --prompt="Once upon a time," | ||
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
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
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.
Should we do a simple non-brittle sanity check? e.g. output length > 0 or something
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.
I think the main concern is whether it runs. If it runs, it will produce output.