Skip to content

Commit 3226daa

Browse files
authored
[llava][18/N] Move token generation loop to a class
Differential Revision: D61047601 Pull Request resolved: #4652
1 parent 02050de commit 3226daa

File tree

1,836 files changed

+363551
-28289
lines changed

Some content is hidden

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

1,836 files changed

+363551
-28289
lines changed

.buckconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@
2323

2424
[parser]
2525
target_platform_detector_spec = target:root//...->prelude//platforms:default target:shim//...->prelude//platforms:default
26+
27+
# Limit the number of files that the buck daemon needs to monitor. If every
28+
# submodule is cloned recursively, some system can fail to build with "OS file
29+
# watch limit reached".
30+
[project]
31+
ignore = \
32+
.git, \
33+
**/.git, \
34+
cmake-out, \
35+
pip-out

.ci/docker/build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ case "${IMAGE_NAME}" in
3737
ARM_SDK=yes
3838
CLANG_VERSION=12
3939
;;
40+
executorch-ubuntu-22.04-qnn-sdk)
41+
QNN_SDK=yes
42+
CLANG_VERSION=12
43+
;;
4044
executorch-ubuntu-22.04-clang12-android)
4145
LINTRUNNER=""
4246
CLANG_VERSION=12
@@ -59,6 +63,9 @@ cp ../../requirements-lintrunner.txt ./
5963
# with a new image hash when the content here is updated
6064
cp -r ../../examples/arm/ ./arm
6165

66+
# Copy qnn setup script from root to here
67+
cp -r ../../backends/qualcomm/ ./qualcomm
68+
6269
docker build \
6370
--no-cache \
6471
--progress=plain \
@@ -72,6 +79,7 @@ docker build \
7279
--build-arg "LINTRUNNER=${LINTRUNNER:-}" \
7380
--build-arg "BUILD_DOCS=${BUILD_DOCS}" \
7481
--build-arg "ARM_SDK=${ARM_SDK:-}" \
82+
--build-arg "QNN_SDK=${QNN_SDK:-}" \
7583
--build-arg "ANDROID_NDK_VERSION=${ANDROID_NDK_VERSION:-}" \
7684
-f "${OS}"/Dockerfile \
7785
"$@" \

.ci/docker/ci_commit_pins/buck2.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2024-02-15
1+
2024-05-15

.ci/docker/ci_commit_pins/pytorch.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a52b4e22571507abc35c2d47de138497190d2e0a
1+
b556d31586845fb1e296a975d2b85d9d325205c9

.ci/docker/common/install_android.sh

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,33 @@ set -ex
1111
[ -n "${ANDROID_NDK_VERSION}" ]
1212

1313
install_prerequiresites() {
14-
apt-get update
14+
OS=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
15+
case "$OS" in
16+
amzn)
17+
# https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/amazon-linux-install.html
18+
yum install -y java-17-amazon-corretto \
19+
ca-certificates \
20+
ant
21+
;;
22+
*)
23+
apt-get update
1524

16-
# NB: Need OpenJDK 17 at the minimum
17-
apt-get install -y --no-install-recommends \
18-
openjdk-17-jdk \
19-
ca-certificates-java \
20-
ant
25+
# NB: Need OpenJDK 17 at the minimum
26+
apt-get install -y --no-install-recommends \
27+
openjdk-17-jdk \
28+
ca-certificates-java \
29+
ant
2130

22-
# Cleanup package manager
23-
apt-get autoclean && apt-get clean
24-
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
31+
# Cleanup package manager
32+
apt-get autoclean && apt-get clean
33+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
34+
;;
35+
esac
2536
}
2637

2738
install_ndk() {
2839
NDK_INSTALLATION_DIR=/opt/ndk
29-
mkdir -p "${NDK_INSTALLATION_DIR}"
40+
rm -rf "${NDK_INSTALLATION_DIR}" && mkdir -p "${NDK_INSTALLATION_DIR}"
3041

3142
pushd /tmp
3243
# The NDK installation is cached on ossci-android S3 bucket
@@ -54,7 +65,7 @@ install_cmdtools() {
5465

5566
install_sdk() {
5667
SDK_INSTALLATION_DIR=/opt/android/sdk
57-
mkdir -p "${SDK_INSTALLATION_DIR}"
68+
rm -rf "${SDK_INSTALLATION_DIR}" && mkdir -p "${SDK_INSTALLATION_DIR}"
5869

5970
# These are the tools needed to build Android apps
6071
yes | /opt/cmdline-tools/bin/sdkmanager --sdk_root="${SDK_INSTALLATION_DIR}" --install "platforms;android-34"

.ci/docker/common/install_base.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ install_ubuntu() {
2323
unzip \
2424
gdb \
2525
rsync \
26-
libssl-dev
26+
libssl-dev \
27+
zip
2728

2829
# Cleanup package manager
2930
apt-get autoclean && apt-get clean

.ci/docker/requirements-ci.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
mpmath==1.3.0
2-
numpy==1.25.2
2+
numpy==1.21.3; python_version == '3.10'
3+
numpy==1.23.2; python_version == '3.11'
4+
numpy; python_version >= '3.12'
35
PyYAML==6.0.1
46
ruamel.yaml==0.17.32
57
sympy==1.12
68
timm==0.6.13
79
tomli==2.0.1
810
torchsr==1.0.4
9-
transformers==4.36.0
11+
transformers==4.38.0
1012
zstd==1.5.5.1
13+
pandas==2.0.3; python_version == '3.10'
14+
pandas; python_version >= '3.11'
1115
pytest==7.2.0
1216
pytest-cov==4.1.0
1317
expecttest==0.1.6

.ci/docker/ubuntu/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,10 @@ COPY --chown=ci-user:ci-user ./arm /opt/arm
8282
# Set up ARM SDK if needed
8383
RUN if [ -n "${ARM_SDK}" ]; then git config --global user.email "[email protected]"; git config --global user.name "OSS CI"; bash /opt/arm/setup.sh --i-agree-to-the-contained-eula /opt/arm-sdk; chown -R ci-user:ci-user /opt/arm-sdk; fi
8484

85+
ARG QNN_SDK
86+
COPY --chown=ci-user:ci-user ./qualcomm /opt/qualcomm
87+
# Set up QNN SDK if needed
88+
RUN if [ -n "${QNN_SDK}" ]; then git config --global user.email "[email protected]"; git config --global user.name "OSS CI"; fi
89+
8590
USER ci-user
8691
CMD ["bash"]

.ci/scripts/build-qnn-sdk.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 -ex
9+
10+
build_qnn_backend() {
11+
echo "Start building qnn backend."
12+
export ANDROID_NDK_ROOT=/opt/ndk
13+
export QNN_SDK_ROOT=/tmp/qnn/2.23.0.240531
14+
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
15+
16+
bash backends/qualcomm/scripts/build.sh --skip_aarch64 --job_number 2 --release
17+
}
18+
19+
build_qnn_backend

.ci/scripts/build_llama_android.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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_KERNELS_OPTIMIZED=ON \
29+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
30+
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
31+
-DXNNPACK_ENABLE_ARM_BF16=OFF \
32+
-Bcmake-android-out .
33+
34+
cmake --build cmake-android-out -j4 --target install --config Release
35+
}
36+
37+
build_llama_runner() {
38+
echo "Building llama runner for Android..."
39+
ANDROID_ABI=arm64-v8a
40+
cmake -DBUCK2="${BUCK2}" \
41+
-DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK"/build/cmake/android.toolchain.cmake \
42+
-DANDROID_ABI="${ANDROID_ABI}" \
43+
-DANDROID_PLATFORM=android-23 \
44+
-DCMAKE_INSTALL_PREFIX=cmake-android-out \
45+
-DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=python \
46+
-DEXECUTORCH_BUILD_XNNPACK=ON \
47+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
48+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
49+
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
50+
-Bcmake-android-out/examples/models/llama2 examples/models/llama2
51+
52+
cmake --build cmake-android-out/examples/models/llama2 -j4 --config Release
53+
}
54+
install_flatc_from_source
55+
install_executorch_and_backend_lib
56+
build_llama_runner

.ci/scripts/gather_test_models.py

Lines changed: 23 additions & 3 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,9 +23,11 @@
2423
"w2l": "linux.12xlarge",
2524
"ic4": "linux.12xlarge",
2625
"resnet50": "linux.12xlarge",
26+
"llava": "linux.12xlarge",
2727
# This one causes timeout on smaller runner, the root cause is unclear (T161064121)
2828
"dl3": "linux.12xlarge",
2929
"emformer_join": "linux.12xlarge",
30+
"emformer_predict": "linux.12xlarge",
3031
}
3132
}
3233

@@ -35,9 +36,11 @@
3536
# Just some examples on how custom timeout can be set
3637
"linux": {
3738
"mobilebert": 90,
39+
"emformer_predict": 360,
3840
},
3941
"macos": {
4042
"mobilebert": 90,
43+
"emformer_predict": 360,
4144
},
4245
}
4346

@@ -56,7 +59,7 @@ def parse_args() -> Any:
5659
"-e",
5760
"--event",
5861
type=str,
59-
choices=["pull_request", "push"],
62+
choices=["pull_request", "push", "schedule"],
6063
required=True,
6164
help="GitHub CI Event. See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on",
6265
)
@@ -83,7 +86,21 @@ def model_should_run_on_event(model: str, event: str) -> bool:
8386
We put higher priority and fast models to pull request and rest to push.
8487
"""
8588
if event == "pull_request":
86-
return model in ["add", "ic3", "mv2", "mv3", "resnet18", "vit"]
89+
return model in ["mv3", "vit"]
90+
elif event == "push":
91+
# 'emformer_predict' is running super slow. Only run it periodically
92+
return model not in ["emformer_predict"]
93+
else:
94+
return True
95+
96+
97+
def model_should_run_on_target_os(model: str, target_os: str) -> bool:
98+
"""
99+
A helper function to decide whether a model should be tested on a target os (linux/macos).
100+
For example, a big model can be disabled in macos due to the limited macos resources.
101+
"""
102+
if target_os == "macos":
103+
return model not in ["llava"]
87104
return True
88105

89106

@@ -119,6 +136,9 @@ def export_models_for_ci() -> dict[str, dict]:
119136
if not model_should_run_on_event(name, event):
120137
continue
121138

139+
if not model_should_run_on_target_os(name, target_os):
140+
continue
141+
122142
if backend == "xnnpack":
123143
if name not in MODEL_NAME_TO_OPTIONS:
124144
continue

.ci/scripts/setup-macos.sh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,18 @@ install_buck() {
2828
fi
2929

3030
pushd .ci/docker
31-
32-
# TODO(huydo): This is a one-off copy of buck2 2024-02-15 to unblock Jon and
31+
# TODO(huydo): This is a one-off copy of buck2 2024-05-15 to unblock Jon and
3332
# re-enable ShipIt. It’s not ideal that upgrading buck2 will require a manual
3433
# update the cached binary on S3 bucket too. Let me figure out if there is a
3534
# way to correctly implement the previous setup of installing a new version of
3635
# buck2 only when it’s needed. AFAIK, the complicated part was that buck2
37-
# --version doesn't say anything w.r.t its release version, i.e. 2024-02-15.
36+
# --version doesn't say anything w.r.t its release version, i.e. 2024-05-15.
3837
# See D53878006 for more details.
39-
BUCK2=buck2-aarch64-apple-darwin.zst
38+
#
39+
# If you need to upgrade buck2 version on S3, please reach out to Dev Infra
40+
# team for help.
41+
BUCK2_VERSION=$(cat ci_commit_pins/buck2.txt)
42+
BUCK2=buck2-aarch64-apple-darwin-${BUCK2_VERSION}.zst
4043
curl -s "https://ossci-macos.s3.amazonaws.com/${BUCK2}" -o "${BUCK2}"
4144

4245
zstd -d "${BUCK2}" -o buck2
@@ -74,16 +77,18 @@ install_sccache() {
7477

7578
export PATH="${SCCACHE_PATH}:${PATH}"
7679

77-
# Create temp directory for sccache shims
78-
TMP_DIR=$(mktemp -d)
79-
trap 'rm -rfv ${TMP_DIR}' EXIT
80+
# Create temp directory for sccache shims if TMP_DIR doesn't exist
81+
if [ -z "${TMP_DIR:-}" ]; then
82+
TMP_DIR=$(mktemp -d)
83+
trap 'rm -rfv ${TMP_DIR}' EXIT
84+
export PATH="${TMP_DIR}:$PATH"
85+
fi
8086

8187
write_sccache_stub "${TMP_DIR}/c++"
8288
write_sccache_stub "${TMP_DIR}/cc"
8389
write_sccache_stub "${TMP_DIR}/clang++"
8490
write_sccache_stub "${TMP_DIR}/clang"
8591

86-
export PATH="${TMP_DIR}:$PATH"
8792
sccache --zero-stats || true
8893
}
8994

@@ -104,6 +109,12 @@ print_cmake_info() {
104109
codesign -f -s - "${CMAKE_EXEC}" || true
105110
}
106111

112+
setup_macos_env_variables() {
113+
CMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')
114+
export CMAKE_PREFIX_PATH
115+
}
116+
117+
setup_macos_env_variables
107118
# NB: we need buck2 in all cases because cmake build also depends on calling
108119
# buck2 atm
109120
install_buck

.ci/scripts/setup-qnn-deps.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 -ex
9+
10+
install_qnn() {
11+
echo "Start installing qnn."
12+
QNN_INSTALLATION_DIR=/tmp/qnn
13+
mkdir -p "${QNN_INSTALLATION_DIR}"
14+
15+
curl -Lo /tmp/v2.23.0.24.06.24.zip "https://softwarecenter.qualcomm.com/api/download/software/qualcomm_neural_processing_sdk/v2.23.0.24.06.24.zip"
16+
echo "Finishing downloading qnn sdk."
17+
unzip -qo /tmp/v2.23.0.24.06.24.zip -d /tmp
18+
echo "Finishing unzip qnn sdk."
19+
20+
21+
# Print the content for manual verification
22+
ls -lah "/tmp/qairt"
23+
mv "/tmp/qairt"/* "${QNN_INSTALLATION_DIR}"
24+
echo "Finishing installing qnn '${QNN_INSTALLATION_DIR}' ."
25+
26+
ls -lah "${QNN_INSTALLATION_DIR}"
27+
}
28+
29+
install_qnn

0 commit comments

Comments
 (0)