Skip to content

Commit 8293fa6

Browse files
authored
Merge branch 'main' into tosa_llm_ext
2 parents bf26a16 + dbf3c37 commit 8293fa6

File tree

1,492 files changed

+64942
-18799
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,492 files changed

+64942
-18799
lines changed

.buckconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
[buildfile]
55
name = TARGETS
6+
name_v2 = TARGETS,BUCK
67

78
[repositories]
89
root = .

.ci/docker/build.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ MINICONDA_VERSION=23.10.0-1
2323
BUCK2_VERSION=$(cat ci_commit_pins/buck2.txt)
2424

2525
case "${IMAGE_NAME}" in
26-
executorch-ubuntu-22.04-gcc9)
26+
executorch-ubuntu-22.04-gcc11)
27+
LINTRUNNER=""
28+
GCC_VERSION=11
29+
;;
30+
executorch-ubuntu-22.04-gcc9-nopytorch)
2731
LINTRUNNER=""
2832
GCC_VERSION=9
33+
SKIP_PYTORCH=yes
2934
;;
3035
executorch-ubuntu-22.04-clang12)
3136
LINTRUNNER=""
@@ -95,6 +100,7 @@ docker build \
95100
--build-arg "QNN_SDK=${QNN_SDK:-}" \
96101
--build-arg "MEDIATEK_SDK=${MEDIATEK_SDK:-}" \
97102
--build-arg "ANDROID_NDK_VERSION=${ANDROID_NDK_VERSION:-}" \
103+
--build-arg "SKIP_PYTORCH=${SKIP_PYTORCH:-}" \
98104
-f "${OS}"/Dockerfile \
99105
"$@" \
100106
.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d03e90c2cd9048e6d9a75285c0355f033cd016fc
1+
732b11313b2006b4d8649500eaf5567ec6ac1e49
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b31bad1b8f1331bf43d47f46602cf6141db56844
1+
7a79b41e29a790ebb4b530eb98a89381e2d7de29

.ci/docker/common/install_pytorch.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1212

1313
install_domains() {
1414
echo "Install torchvision and torchaudio"
15-
pip_install --no-use-pep517 --user "git+https://github.com/pytorch/audio.git@${TORCHAUDIO_VERSION}"
16-
pip_install --no-use-pep517 --user "git+https://github.com/pytorch/vision.git@${TORCHVISION_VERSION}"
15+
pip_install --no-build-isolation --user "git+https://github.com/pytorch/audio.git@${TORCHAUDIO_VERSION}"
16+
pip_install --no-build-isolation --user "git+https://github.com/pytorch/vision.git@${TORCHVISION_VERSION}"
1717
}
1818

1919
install_pytorch_and_domains() {

.ci/docker/requirements-ci.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mpmath==1.3.0
22
numpy>=2.0.0; python_version >= '3.10'
33
PyYAML==6.0.1
44
ruamel.yaml==0.18.15
5-
sympy==1.12
5+
sympy>=1.13.3
66
timm==0.6.13
77
tomli==2.0.1
88
torchsr==1.0.4

.ci/docker/ubuntu/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ ENV SCCACHE_S3_KEY_PREFIX executorch
6464
ENV SCCACHE_REGION us-east-1
6565

6666
ARG TORCH_VERSION
67+
ARG SKIP_PYTORCH
6768
COPY ./common/install_pytorch.sh install_pytorch.sh
6869
COPY ./common/utils.sh utils.sh
69-
RUN bash ./install_pytorch.sh && rm install_pytorch.sh utils.sh
70+
RUN if [ -z "${SKIP_PYTORCH}" ]; then bash ./install_pytorch.sh; fi && rm install_pytorch.sh utils.sh
7071

7172
ARG LINTRUNNER
7273
# Install lintrunner if needed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ set_up_aot() {
4242
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
4343
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
4444
-DPYTHON_EXECUTABLE=python3
45-
cmake --build $PWD --target "PyQnnManagerAdaptor" "PyQnnWrapperAdaptor" -j$(nproc)
45+
cmake --build $PWD --target "PyQnnManagerAdaptor" -j$(nproc)
4646
# install Python APIs to correct import path
4747
# The filename might vary depending on your Python and host version.
4848
cp -f backends/qualcomm/PyQnnManagerAdaptor.cpython-310-x86_64-linux-gnu.so $EXECUTORCH_ROOT/backends/qualcomm/python
49-
cp -f backends/qualcomm/PyQnnWrapperAdaptor.cpython-310-x86_64-linux-gnu.so $EXECUTORCH_ROOT/backends/qualcomm/python
5049
popd
5150

5251
# Workaround for fbs files in exir/_serialize

.ci/scripts/setup-samsung-linux-deps.sh

Lines changed: 185 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,209 @@
88

99
set -ex
1010

11+
API_KEY=$SAMSUNG_AI_LITECORE_KEY
12+
if [[ -z "${API_KEY}" ]]; then
13+
echo "ERROR: It didn't set up SAMSUNG_AI_LITECORE_KEY." >&2
14+
exit 1
15+
fi
16+
17+
OS_NAME="Ubuntu 22.04"
18+
LITECORE_BASE="https://soc-developer.semiconductor.samsung.com/api/v1/resource/ai-litecore/download"
19+
DEVICEFARM_BASE="https://soc-developer.semiconductor.samsung.com/api/v1/resource/remotelab/download"
20+
21+
parse_url() {
22+
local json="$1"
23+
if command -v jq >/dev/null 2>&1; then
24+
jq -r '.data // empty' <<<"$json"
25+
else
26+
sed -n 's/.*"data":[[:space:]]*"\([^"]*\)".*/\1/p' <<<"$json"
27+
fi
28+
}
1129

12-
download_ai_lite_core() {
13-
API_BASE="https://soc-developer.semiconductor.samsung.com/api/v1/resource/ai-litecore/download"
14-
API_KEY=$SAMSUNG_AI_LITECORE_KEY
15-
16-
VERSION="0.7"
17-
OS_NAME="Ubuntu 22.04"
18-
OUT_FILE="/tmp/exynos-ai-litecore-v${VERSION}.tar.gz"
19-
TARGET_PATH="/tmp/exynos_ai_lite_core"
20-
21-
mkdir -p ${TARGET_PATH}
22-
# Presigned issue URL
23-
JSON_RESP=$(curl -sS -G \
24-
--location --fail --retry 3 \
30+
download_and_extract() {
31+
local base_url="$1"
32+
local version="$2"
33+
local out_dir="$3"
34+
local out_file="$4"
35+
36+
local resp
37+
resp=$(curl -fsSL -G \
2538
-H "apikey: ${API_KEY}" \
26-
--data-urlencode "version=${VERSION}" \
39+
--data-urlencode "version=${version}" \
2740
--data-urlencode "os=${OS_NAME}" \
28-
"${API_BASE}")
41+
"${base_url}")
42+
43+
local download_url
44+
download_url=$(parse_url "$resp")
45+
if [[ -z "${download_url}" ]]; then
46+
echo "ERROR: It failed to download from ${base_url} ."
47+
echo "Response: $resp" >&2
48+
exit 1
49+
fi
50+
51+
curl -fsSL -L --retry 3 -o "${out_file}" "${download_url}"
52+
echo "Download completed: ${out_file}"
2953

30-
DOWNLOAD_URL=$(echo "$JSON_RESP" | sed -n 's/.*"data":[[:space:]]*"\([^"]*\)".*/\1/p')
54+
mkdir -p "${out_dir}"
55+
case "${out_file##*.}" in
56+
tar|tgz|gz)
57+
echo "Extracting TAR.GZ..."
58+
tar -C "${out_dir}" --strip-components=1 -xzvf "${out_file}"
59+
;;
3160

32-
if [[ -z "$DOWNLOAD_URL" ]]; then
33-
echo "Failed to extract download URL"
34-
echo "$JSON_RESP"
61+
zip)
62+
echo "Extracting ZIP..."
63+
unzip -q -d "${out_dir}" "${out_file}"
64+
;;
65+
66+
*)
3567
exit 1
68+
;;
69+
esac
70+
echo "Extracted to: ${out_dir}"
71+
}
72+
73+
download_ai_lite_core() {
74+
local litecore_version="${1:-1.0}"
75+
local litecore_out="/tmp/exynos-ai-litecore-v${litecore_version}.tar.gz"
76+
local litecore_dir="/tmp/exynos_ai_lite_core"
77+
78+
download_and_extract \
79+
"${LITECORE_BASE}" \
80+
"${litecore_version}" \
81+
"${litecore_dir}" \
82+
"${litecore_out}"
83+
84+
export EXYNOS_AI_LITECORE_ROOT="${litecore_dir}"
85+
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}:${EXYNOS_AI_LITECORE_ROOT}/lib/x86_64-linux"
86+
}
87+
88+
install_devicefarm_cli() {
89+
local cli_version="${1:-beta-1.0.8}"
90+
local cli_out="/tmp/devicefarm-cli-v${cli_version}.zip"
91+
local cli_dir="/tmp/devicefarm_cli"
92+
93+
download_and_extract \
94+
"${DEVICEFARM_BASE}" \
95+
"${cli_version}" \
96+
"${cli_dir}" \
97+
"${cli_out}"
98+
99+
export PATH="${PATH%:}:${cli_dir}"
100+
chmod +x "${cli_dir}/devicefarm-cli"
101+
}
102+
103+
reserve_if_needed() {
104+
# Set default value
105+
export DEVICE_RESERVED=0
106+
107+
if ! command -v devicefarm-cli >/dev/null 2>&1; then
108+
echo "[WARN] devicefarm-cli is not installed." >&2
109+
return 1
36110
fi
37111

38-
# Download LiteCore
39-
curl -sS -L --fail --retry 3 \
40-
--output "$OUT_FILE" \
41-
"$DOWNLOAD_URL"
112+
local raw_info info_lines
113+
raw_info="$(devicefarm-cli -I)"
114+
115+
info_lines="$(printf '%s\n' "$raw_info" | grep -v '^\\[INFO\\]')"
42116

43-
echo "Download done: $OUT_FILE"
117+
local found_count
44118

119+
found_count=$(printf '%s\n' "$info_lines" \
120+
| grep -Eo 'Found available reservations *: *[0-9]+' \
121+
| grep -Eo '[0-9]+')
122+
[[ -z "$found_count" ]] && found_count=0
45123

46-
tar -C "${TARGET_PATH}" --strip-components=1 -xzvf "${OUT_FILE}"
124+
echo "[INFO] Current Reserved Count: $found_count"
125+
126+
local THRESHOLD_SECONDS=12600
127+
local any_below_threshold=0
128+
129+
if (( found_count > 0 )); then
130+
local table_body
131+
table_body=$(printf '%s\n' "$info_lines" | sed -n '2,$p')
132+
133+
while IFS= read -r line; do
134+
if [[ "$line" =~ ^[0-9]+[[:space:]]+([0-9]{1,2}:[0-9]{2}:[0-9]{2}) ]]; then
135+
local time_str="${BASH_REMATCH[1]}"
136+
IFS=: read -r hh mm ss <<<"$time_str"
137+
(( seconds = 10#$hh * 3600 + 10#$mm * 60 + 10#$ss ))
138+
if (( seconds <= THRESHOLD_SECONDS )); then
139+
any_below_threshold=1
140+
break
141+
fi
142+
fi
143+
done <<<"$table_body"
144+
else
145+
any_below_threshold=1
146+
fi
47147

48-
export EXYNOS_AI_LITECORE_ROOT=${TARGET_PATH}
49-
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:${EXYNOS_AI_LITECORE_ROOT}/lib/x86_64-linux
148+
if (( any_below_threshold )); then
149+
echo "[INFO] Reserving now."
150+
if ! devicefarm-cli -R; then
151+
echo "::warning::Failed to reserve a device. No devices are currently available." >&2
152+
echo "[WARN] Device reservation failed - continuing without device." >&2
153+
return 0
154+
fi
155+
else
156+
echo "[INFO] Don't need to be reserved."
157+
fi
158+
159+
local info_after reservation_id max_seconds=0 max_id
160+
161+
info_after="$(devicefarm-cli -I)"
162+
163+
local body_after
164+
body_after=$(printf '%s\n' "$info_after" | grep -v '^\\[INFO\\]' | sed -n '2,$p')
165+
166+
while IFS= read -r line; do
167+
if [[ "$line" =~ ^[0-9]+[[:space:]]+([0-9]{1,2}:[0-9]{2}:[0-9]{2})[[:space:]].*([0-9a-f-]{36})$ ]]; then
168+
local time_str="${BASH_REMATCH[1]}"
169+
local id="${BASH_REMATCH[2]}"
170+
IFS=: read -r hh mm ss <<<"$time_str"
171+
(( seconds = 10#$hh * 3600 + 10#$mm * 60 + 10#$ss ))
172+
if (( seconds > max_seconds )); then
173+
max_seconds=$seconds
174+
max_id=$id
175+
fi
176+
fi
177+
done <<<"$body_after"
178+
179+
reservation_id=$max_id
180+
181+
if [[ -n "$reservation_id" ]]; then
182+
devicefarm-cli -C "$reservation_id"
183+
devicefarm-cli -E "ls /"
184+
export DEVICE_RESERVED=1
185+
echo "[INFO] Device successfully reserved and connected."
186+
else
187+
echo "::warning::No available devices found." >&2
188+
echo "[WARN] There is no available devices."
189+
fi
50190
}
51191

52192
install_enn_backend() {
53-
NDK_INSTALLATION_DIR=/opt/ndk
54-
rm -rf "${NDK_INSTALLATION_DIR}" && sudo mkdir -p "${NDK_INSTALLATION_DIR}"
55-
ANDROID_NDK_VERSION=r28c
193+
local ndk_dir="/opt/ndk"
194+
local ndk_version="r28c"
195+
196+
if [[ ! -d "${ndk_dir}" ]]; then
197+
sudo mkdir -p "${ndk_dir}"
198+
sudo chown "$(whoami)":"$(whoami)" "${ndk_dir}"
199+
fi
200+
201+
export ANDROID_NDK_ROOT="${ndk_dir}"
202+
echo "NDK will be installed/used at: ${ANDROID_NDK_ROOT}"
56203

57-
# build Exynos backend
58-
export ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT:-/opt/ndk}
59204
bash backends/samsung/build.sh --build all
60-
# set env variable
61-
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)"
62-
export PYTHONPATH=${PYTHONPATH:-}:${EXECUTORCH_ROOT}/..
205+
206+
export EXECUTORCH_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
207+
export PYTHONPATH="${PYTHONPATH:-}:${EXECUTORCH_ROOT}/.."
63208
}
64209

65-
AI_LITE_CORE_VERSION=0.7.0
210+
litecore_ver="1.0"
211+
devicefarm_ver="beta-1.0.8"
66212

67-
download_ai_lite_core ${AI_LITE_CORE_VERSION}
213+
download_ai_lite_core ${litecore_ver}
214+
install_devicefarm_cli "${devicefarm_ver}"
68215
install_enn_backend
216+
reserve_if_needed

.ci/scripts/test_ane_static_llama.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ pushd $EXECUTORCH_ROOT/examples/apple/coreml/llama
2828
# Download stories llama110m artifacts
2929
download_stories_model_artifacts
3030

31+
# Test static ANE llama model
32+
python export_static_llm_coreml.py --checkpoint stories110M.pt --params params.json --output model.pte
33+
34+
# The ANE cannot run in github CI
35+
# python run_static_llm.py --model model.pte --params params.json --tokenizer tokenizer.model --prompt "Once upon a time," --lookahead
36+
37+
# Test export of deprecated model
3138
python export.py -n model.pte -p params.json -c stories110M.pt --seq_length 32 --max_seq_length 64 --dtype fp16 --coreml-quantize c4w --embedding-quantize 4,32
3239

3340
popd

0 commit comments

Comments
 (0)