Skip to content

Commit 18c5c3c

Browse files
authored
Merge branch 'pytorch:main' into pr_conv_combos
2 parents 5620410 + c731673 commit 18c5c3c

File tree

374 files changed

+19831
-1923
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

374 files changed

+19831
-1923
lines changed

.ci/scripts/build_llama_android.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -exu
9+
10+
# shellcheck source=/dev/null
11+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
12+
13+
install_executorch_and_backend_lib() {
14+
echo "Installing executorch and xnnpack backend"
15+
rm -rf cmake-android-out && mkdir cmake-android-out
16+
ANDROID_NDK=/opt/ndk
17+
BUCK2=buck2
18+
ANDROID_ABI=arm64-v8a
19+
cmake -DBUCK2="${BUCK2}" \
20+
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
21+
-DANDROID_ABI="${ANDROID_ABI}" \
22+
-DANDROID_PLATFORM=android-23 \
23+
-DCMAKE_INSTALL_PREFIX=cmake-android-out \
24+
-DCMAKE_BUILD_TYPE=Release \
25+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
26+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
27+
-DEXECUTORCH_BUILD_XNNPACK=ON \
28+
-DEXECUTORCH_BUILD_OPTIMIZED=ON \
29+
-DXNNPACK_ENABLE_ARM_BF16=OFF \
30+
-Bcmake-android-out .
31+
32+
cmake --build cmake-android-out -j4 --target install --config Release
33+
}
34+
35+
build_llama_runner() {
36+
echo "Building llama runner for Android..."
37+
ANDROID_ABI=arm64-v8a
38+
cmake -DBUCK2="${BUCK2}" \
39+
-DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK"/build/cmake/android.toolchain.cmake \
40+
-DANDROID_ABI="${ANDROID_ABI}" \
41+
-DANDROID_PLATFORM=android-23 \
42+
-DCMAKE_INSTALL_PREFIX=cmake-android-out \
43+
-DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=python \
44+
-DEXECUTORCH_BUILD_OPTIMIZED=ON \
45+
-Bcmake-android-out/examples/models/llama2 examples/models/llama2
46+
47+
cmake --build cmake-android-out/examples/models/llama2 -j4 --config Release
48+
}
49+
install_flatc_from_source
50+
install_executorch_and_backend_lib
51+
build_llama_runner

.ci/scripts/gather_test_models.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from examples.models import MODEL_NAME_TO_MODEL
1414
from examples.xnnpack import MODEL_NAME_TO_OPTIONS
1515

16-
1716
DEFAULT_RUNNERS = {
1817
"linux": "linux.2xlarge",
1918
"macos": "macos-m1-stable",
@@ -24,6 +23,7 @@
2423
"w2l": "linux.12xlarge",
2524
"ic4": "linux.12xlarge",
2625
"resnet50": "linux.12xlarge",
26+
"llava_encoder": "linux.4xlarge",
2727
# This one causes timeout on smaller runner, the root cause is unclear (T161064121)
2828
"dl3": "linux.12xlarge",
2929
"emformer_join": "linux.12xlarge",
@@ -83,7 +83,17 @@ def model_should_run_on_event(model: str, event: str) -> bool:
8383
We put higher priority and fast models to pull request and rest to push.
8484
"""
8585
if event == "pull_request":
86-
return model in ["add", "ic3", "mv2", "mv3", "resnet18", "vit"]
86+
return model in ["add", "ic3", "mv2", "mv3", "resnet18", "vit", "llava_encoder"]
87+
return True
88+
89+
90+
def model_should_run_on_target_os(model: str, target_os: str) -> bool:
91+
"""
92+
A helper function to decide whether a model should be tested on a target os (linux/macos).
93+
For example, a big model can be disabled in macos due to the limited macos resources.
94+
"""
95+
if target_os == "macos":
96+
return model not in ["llava_encoder"]
8797
return True
8898

8999

@@ -119,6 +129,9 @@ def export_models_for_ci() -> dict[str, dict]:
119129
if not model_should_run_on_event(name, event):
120130
continue
121131

132+
if not model_should_run_on_target_os(name, target_os):
133+
continue
134+
122135
if backend == "xnnpack":
123136
if name not in MODEL_NAME_TO_OPTIONS:
124137
continue

.ci/scripts/setup-macos.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ print_cmake_info() {
104104
codesign -f -s - "${CMAKE_EXEC}" || true
105105
}
106106

107+
setup_macos_env_variables() {
108+
CMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')
109+
export CMAKE_PREFIX_PATH
110+
}
111+
112+
setup_macos_env_variables
107113
# NB: we need buck2 in all cases because cmake build also depends on calling
108114
# buck2 atm
109115
install_buck

.ci/scripts/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ test_model() {
6767
run_portable_executor_runner
6868
rm "./${MODEL_NAME}.pte"
6969
fi
70+
if [[ "${MODEL_NAME}" == "llava_encoder" ]]; then
71+
# Install requirements for llava
72+
bash examples/models/llava_encoder/install_requirements.sh
73+
fi
7074
# python3 -m examples.portable.scripts.export --model_name="llama2" should works too
7175
"${PYTHON_EXECUTABLE}" -m examples.portable.scripts.export --model_name="${MODEL_NAME}"
7276
run_portable_executor_runner

.ci/scripts/test_llama.sh

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1212
MODEL_NAME=$1 # stories110M.pt
1313
BUILD_TOOL=$2 # buck2 or cmake
1414
DTYPE=$3 # fp16 or fp32
15-
15+
MODE=${4:-"xnnpack"} # portable or xnnpack
16+
if [[ $# -lt 4 ]]; then # Assuming 4 mandatory args
17+
echo "Expecting atleast 4 positional arguments"
18+
echo "Usage: [...]"
19+
fi
1620
if [[ -z "${MODEL_NAME:-}" ]]; then
1721
echo "Missing model name, exiting..."
1822
exit 1
@@ -28,6 +32,11 @@ if [[ -z "${DTYPE:-}" ]]; then
2832
exit 1
2933
fi
3034

35+
if [[ -z "${MODE:-}" ]]; then
36+
echo "Missing mode, choose portable or xnnpack, exiting..."
37+
exit 1
38+
fi
39+
3140
if [[ -z "${BUCK:-}" ]]; then
3241
BUCK=buck2
3342
fi
@@ -42,11 +51,18 @@ which "${PYTHON_EXECUTABLE}"
4251
cmake_install_executorch_libraries() {
4352
echo "Installing libexecutorch.a, libextension_module.so, libportable_ops_lib.a"
4453
rm -rf cmake-out
54+
if [[ "${MODE}" == "xnnpack" ]]; then
55+
XNNPACK=ON
56+
else
57+
XNNPACK=OFF
58+
fi
4559
retry cmake -DBUCK2="$BUCK" \
4660
-DCMAKE_INSTALL_PREFIX=cmake-out \
4761
-DCMAKE_BUILD_TYPE=Release \
4862
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
4963
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
64+
-DEXECUTORCH_BUILD_OPTIMIZED=ON \
65+
-DEXECUTORCH_BUILD_XNNPACK="$XNNPACK" \
5066
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
5167
-Bcmake-out .
5268
cmake --build cmake-out -j9 --target install --config Release
@@ -58,6 +74,7 @@ cmake_build_llama_runner() {
5874
retry cmake -DBUCK2="$BUCK" \
5975
-DCMAKE_INSTALL_PREFIX=cmake-out \
6076
-DCMAKE_BUILD_TYPE=Release \
77+
-DEXECUTORCH_BUILD_OPTIMIZED=ON \
6178
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
6279
-Bcmake-out/${dir} \
6380
${dir}
@@ -99,7 +116,11 @@ fi
99116
# Export model.
100117
EXPORTED_MODEL_NAME="${EXPORTED_MODEL_NAME}.pte"
101118
echo "Exporting ${EXPORTED_MODEL_NAME}"
102-
$PYTHON_EXECUTABLE -m examples.models.llama2.export_llama -c stories110M.pt -p "${PARAMS}" -d "${DTYPE}"
119+
EXPORT_ARGS="-c stories110M.pt -p ${PARAMS} -d ${DTYPE} -n ${EXPORTED_MODEL_NAME}"
120+
if [[ "${MODE}" == "xnnpack" ]]; then
121+
EXPORT_ARGS="${EXPORT_ARGS} --pt2e_quantize xnnpack_dynamic"
122+
fi
123+
$PYTHON_EXECUTABLE -m examples.models.llama2.export_llama ${EXPORT_ARGS}
103124

104125
# Create tokenizer.bin.
105126
echo "Creating tokenizer.bin"

.ci/scripts/test_quantized_aot_lib.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -exu
9+
10+
# shellcheck source=/dev/null
11+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
12+
13+
which "${PYTHON_EXECUTABLE}"
14+
# Just set this variable here, it's cheap even if we use buck2
15+
CMAKE_OUTPUT_DIR=cmake-out
16+
17+
build_cmake_quantized_aot_lib() {
18+
echo "Building quantized aot lib"
19+
SITE_PACKAGES="$(${PYTHON_EXECUTABLE} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
20+
CMAKE_PREFIX_PATH="${SITE_PACKAGES}/torch"
21+
(rm -rf ${CMAKE_OUTPUT_DIR} \
22+
&& mkdir ${CMAKE_OUTPUT_DIR} \
23+
&& cd ${CMAKE_OUTPUT_DIR} \
24+
&& retry cmake -DBUCK2=buck2 \
25+
-DCMAKE_BUILD_TYPE=Release \
26+
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
27+
-DEXECUTORCH_BUILD_QUANTIZED=ON \
28+
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)
29+
30+
cmake --build ${CMAKE_OUTPUT_DIR} -j4
31+
}
32+
33+
build_cmake_quantized_aot_lib

.ci/scripts/utils.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ cmake_install_executorch_lib() {
134134

135135
download_stories_model_artifacts() {
136136
# Download stories110M.pt and tokenizer from Github
137-
wget "https://huggingface.co/karpathy/tinyllamas/resolve/main/stories110M.pt"
138-
wget "https://raw.githubusercontent.com/karpathy/llama2.c/master/tokenizer.model"
137+
curl -Ls "https://huggingface.co/karpathy/tinyllamas/resolve/main/stories110M.pt" --output stories110M.pt
138+
curl -Ls "https://raw.githubusercontent.com/karpathy/llama2.c/master/tokenizer.model" --output tokenizer.model
139139
# Create params.json file
140140
touch params.json
141141
echo '{"dim": 768, "multiple_of": 32, "n_heads": 12, "n_layers": 12, "norm_eps": 1e-05, "vocab_size": 32000}' > params.json

0 commit comments

Comments
 (0)