-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate ExecuTorch path for more models in CI
- Loading branch information
Showing
3 changed files
with
283 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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,124 @@ | ||
name: executorch | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
gather-models: | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
models: ${{ steps.gather-models.outputs.models }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: 'false' | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
- name: Extract the list of models to test | ||
id: gather-models | ||
run: | | ||
set -eux | ||
PYTHONPATH="${PWD}" python ./scripts/gather_test_models.py | ||
test-models-mobile-linux: | ||
name: test-models-mobile-linux | ||
needs: gather-models | ||
strategy: | ||
matrix: ${{ fromJSON(needs.gather-models.outputs.models) }} | ||
runs-on: "32-core-ubuntu" | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
- name: Print machine info | ||
run: | | ||
uname -a | ||
if [ $(uname -s) == Linux ]; then | ||
cat /proc/cpuinfo | grep name | head -n 1 | cut -d ':' -f2 # CPU brand string (model name) | ||
cat /proc/cpuinfo | grep physical id | wc -l # Number of physical cores | ||
fi | ||
- name: Install ExecuTorch | ||
run: | | ||
export LLAMA_FAST_ROOT=${PWD} | ||
bash ${LLAMA_FAST_ROOT}/scripts/install_et.sh | ||
- name: Download checkpoints | ||
run: | | ||
CHECKPOINT_NAME = ${{ matrix.checkpoint_name }} | ||
pushd ${LLAMA_FAST_ROOT} | ||
mkdir -p checkpoints/${CHECKPOINT_NAME} | ||
cd checkpoints/${CHECKPOINT_NAME} | ||
for resource in ${{ matrix.resource }} | ||
do | ||
wget $resource | ||
done | ||
popd | ||
- name: Run inference | ||
run: | | ||
pushd ${LLAMA_FAST_ROOT} | ||
export CHECKPOINT_PATH=${LLAMA_FAST_ROOT}/checkpoints/${CHECKPOINT_NAME}/${CHECKPOINT_NAME}.pt | ||
export MODEL_NAME=${CHECKPOINT_NAME} | ||
python generate.py --checkpoint-path ${CHECKPOINT_PATH} --temperature 0 > ${PWD}/output_eager | ||
cat ${PWD}/output_eager | ||
python export.py --checkpoint-path ${CHECKPOINT_PATH} --output-pte-path ${PWD}/${MODEL_NAME}.pte | ||
python generate.py --checkpoint-path ${CHECKPOINT_PATH} --temperature 0 --pte-path ${PWD}/${MODEL_NAME}.pte > ${PWD}/output_et | ||
cat ${PWD}/output_et | ||
echo "Tests complete." | ||
test-models-mobile-macos-m1: | ||
name: test-models-mobile-macos-m1 | ||
needs: gather-models | ||
strategy: | ||
matrix: ${{ fromJSON(needs.gather-models.outputs.models) }} | ||
runs-on: "macos-m1-12" | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
- name: Setup Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
- name: Print machine info | ||
run: | | ||
uname -a | ||
if [ $(uname -s) == Darwin ]; then | ||
sysctl machdep.cpu.brand_string | ||
sysctl machdep.cpu.core_count | ||
fi | ||
- name: Install ExecuTorch | ||
run: | | ||
export LLAMA_FAST_ROOT=${PWD} | ||
bash ${LLAMA_FAST_ROOT}/scripts/install_et.sh | ||
- name: Download checkpoints | ||
run: | | ||
CHECKPOINT_NAME = ${{ matrix.checkpoint_name }} | ||
pushd ${LLAMA_FAST_ROOT} | ||
mkdir -p checkpoints/${CHECKPOINT_NAME} | ||
cd checkpoints/${CHECKPOINT_NAME} | ||
for resource in ${{ matrix.resource }} | ||
do | ||
wget $resource | ||
done | ||
popd | ||
- name: Run inference | ||
run: | | ||
pushd ${LLAMA_FAST_ROOT} | ||
export CHECKPOINT_PATH=${LLAMA_FAST_ROOT}/checkpoints/${CHECKPOINT_NAME}/${CHECKPOINT_NAME}.pt | ||
export MODEL_NAME=${CHECKPOINT_NAME} | ||
python generate.py --checkpoint-path ${CHECKPOINT_PATH} --temperature 0 > ${PWD}/output_eager | ||
cat ${PWD}/output_eager | ||
python export.py --checkpoint-path ${CHECKPOINT_PATH} --output-pte-path ${PWD}/${MODEL_NAME}.pte | ||
python generate.py --checkpoint-path ${CHECKPOINT_PATH} --temperature 0 --pte-path ${PWD}/${MODEL_NAME}.pte > ${PWD}/output_et | ||
cat ${PWD}/output_et | ||
echo "Tests complete." |
This file contains 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,106 @@ | ||
#!/usr/bin/env python | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# 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. | ||
|
||
import itertools | ||
import json | ||
import os | ||
from typing import Any | ||
|
||
|
||
MODEL_CHECKPOINT_NAMES = { | ||
"stories15M" : [ | ||
"https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.pt", | ||
"https://github.com/karpathy/llama2.c/raw/master/tokenizer.model", | ||
"https://github.com/karpathy/llama2.c/raw/master/tokenizer.bin", | ||
], | ||
"stories42M": [ | ||
"https://huggingface.co/karpathy/tinyllamas/resolve/main/stories42M.pt", | ||
"https://github.com/karpathy/llama2.c/raw/master/tokenizer.model", | ||
"https://github.com/karpathy/llama2.c/raw/master/tokenizer.bin", | ||
], | ||
"stories100M": [ | ||
"https://huggingface.co/karpathy/tinyllamas/resolve/main/stories100M.pt", | ||
"https://github.com/karpathy/llama2.c/raw/master/tokenizer.model", | ||
"https://github.com/karpathy/llama2.c/raw/master/tokenizer.bin", | ||
], | ||
# "open_llama_7b", | ||
# "Llama-2-7b-chat-hf", | ||
# "Llama-2-13b-chat-hf", | ||
# "Llama-2-70b-chat-hf", | ||
# "CodeLlama-7b-Python-hf", | ||
# "CodeLlama-34b-Python-hf", | ||
# "Mistral-7B-v0.1", | ||
# "Mistral-7B-Instruct-v0.1", | ||
# "Mistral-7B-Instruct-v0.2", | ||
} | ||
|
||
|
||
DEFAULT_RUNNERS = { | ||
"linux": "32-core-ubuntu", | ||
"macos": "macos-m1-12", | ||
} | ||
|
||
|
||
def parse_args() -> Any: | ||
from argparse import ArgumentParser | ||
|
||
parser = ArgumentParser("Gather all models to test on CI for the target OS") | ||
parser.add_argument( | ||
"--target-os", | ||
type=str, | ||
default="linux", | ||
help="the target OS", | ||
) | ||
|
||
return parser.parse_args() | ||
|
||
|
||
def set_output(name: str, val: Any) -> None: | ||
""" | ||
Set the GitHb output so that it can be accessed by other jobs | ||
""" | ||
print(f"Setting {val} to GitHub output") | ||
|
||
if os.getenv("GITHUB_OUTPUT"): | ||
with open(str(os.getenv("GITHUB_OUTPUT")), "a") as env: | ||
print(f"{name}={val}", file=env) | ||
else: | ||
print(f"::set-output name={name}::{val}") | ||
|
||
|
||
def export_models_for_ci() -> dict[str, dict]: | ||
""" | ||
This gathers all the models that we want to test on GitHub OSS CI | ||
""" | ||
args = parse_args() | ||
target_os = args.target_os | ||
|
||
# This is the JSON syntax for configuration matrix used by GitHub | ||
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs | ||
models = {"include": []} | ||
|
||
for checkpoint_name, export_config in itertools.product( | ||
MODEL_CHECKPOINT_NAMES, | ||
[ | ||
"xnnpack", | ||
] | ||
): | ||
record = { | ||
"checkpoint_name": checkpoint_name, | ||
"resources": MODEL_CHECKPOINT_NAMES[checkpoint_name], | ||
"export_config": export_config, | ||
"runner": DEFAULT_RUNNERS.get(target_os), | ||
"timeout": 90, | ||
} | ||
|
||
models["include"].append(record) | ||
|
||
set_output("models", json.dumps(models)) | ||
|
||
|
||
if __name__ == "__main__": | ||
export_models_for_ci() |
This file contains 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 |
---|---|---|
@@ -1,26 +1,53 @@ | ||
cd ${LLAMA_FAST_ROOT} | ||
echo "Inside: $LLAMA_FAST_ROOT" | ||
|
||
echo "Cloning executorch to ${LLAMA_FAST_ROOT}/build/src" | ||
rm -rf ${LLAMA_FAST_ROOT}/build | ||
mkdir -p ${LLAMA_FAST_ROOT}/build/src | ||
cd ${LLAMA_FAST_ROOT}/build/src | ||
git clone https://github.com/pytorch/executorch.git | ||
cd executorch | ||
echo "Install executorch: submodule update" | ||
git submodule sync | ||
git submodule update --init | ||
|
||
echo "Applying fixes" | ||
cp ${LLAMA_FAST_ROOT}/scripts/fixes_et/module.cpp ${LLAMA_FAST_ROOT}/build/src/executorch/extension/module/module.cpp # ET uses non-standard C++ that does not compile in GCC | ||
cp ${LLAMA_FAST_ROOT}/scripts/fixes_et/managed_tensor.h ${LLAMA_FAST_ROOT}/build/src/executorch/extension/runner_util/managed_tensor.h # ET is missing headers for vector/memory. This causes downstream issues when building runner-et. | ||
|
||
echo "Building and installing python libraries" | ||
./install_requirements.sh --pybind xnnpack | ||
|
||
echo "Building and installing C++ libraries" | ||
echo "Inside: ${PWD}" | ||
mkdir cmake-out | ||
cmake -DCMAKE_BUILD_TYPE=Release -DEXECUTORCH_BUILD_OPTIMIZED=ON -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON -DEXECUTORCH_BUILD_XNNPACK=ON -S . -B cmake-out -G Ninja | ||
cmake --build cmake-out | ||
cmake --install cmake-out --prefix ${LLAMA_FAST_ROOT}/build/install | ||
#!/bin/bash | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# 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 | ||
|
||
install_pip_dependencies() { | ||
echo "Intalling common pip packages" | ||
|
||
pip install wheel | ||
pip install cmake | ||
pip install ninja | ||
pip install zstd | ||
pushd ${LLAMA_FAST_ROOT} | ||
pip install -r ./requirements.txt | ||
popd | ||
} | ||
|
||
install_executorch() { | ||
echo "Cloning executorch to ${LLAMA_FAST_ROOT}/build/src" | ||
rm -rf ${LLAMA_FAST_ROOT}/build | ||
mkdir -p ${LLAMA_FAST_ROOT}/build/src | ||
pushd ${LLAMA_FAST_ROOT}/build/src | ||
git clone https://github.com/pytorch/executorch.git | ||
cd executorch | ||
echo "Install executorch: submodule update" | ||
git submodule sync | ||
git submodule update --init | ||
|
||
echo "Applying fixes" | ||
cp ${LLAMA_FAST_ROOT}/scripts/fixes_et/module.cpp ${LLAMA_FAST_ROOT}/build/src/executorch/extension/module/module.cpp # ET uses non-standard C++ that does not compile in GCC | ||
cp ${LLAMA_FAST_ROOT}/scripts/fixes_et/managed_tensor.h ${LLAMA_FAST_ROOT}/build/src/executorch/extension/runner_util/managed_tensor.h # ET is missing headers for vector/memory. This causes downstream issues when building runner-et. | ||
|
||
echo "Building and installing python libraries" | ||
bash ./install_requirements.sh --pybind xnnpack | ||
pip list | ||
|
||
echo "Building and installing C++ libraries" | ||
echo "Inside: ${PWD}" | ||
mkdir cmake-out | ||
cmake -DCMAKE_BUILD_TYPE=Release -DEXECUTORCH_BUILD_OPTIMIZED=ON -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON -DEXECUTORCH_BUILD_XNNPACK=ON -S . -B cmake-out -G Ninja | ||
cmake --build cmake-out | ||
cmake --install cmake-out --prefix ${LLAMA_FAST_ROOT}/build/install | ||
popd | ||
} | ||
|
||
pushd ${LLAMA_FAST_ROOT} | ||
install_pip_dependencies | ||
install_executorch | ||
popd |