Skip to content

Commit b0a668a

Browse files
authored
Merge branch 'main' into add_mv3_testcase
2 parents 6a44e7a + 05277dd commit b0a668a

File tree

64 files changed

+2019
-1195
lines changed

Some content is hidden

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

64 files changed

+2019
-1195
lines changed

.ci/docker/ci_commit_pins/pytorch.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
08434df1f2f88c9770e59246caa2ff9c6f613270
1+
295f2ed4d103017f7e19a7b8263ece606cd629db

.ci/docker/common/install_android.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ install_sdk() {
7070
# These are the tools needed to build Android apps
7171
yes | /opt/cmdline-tools/bin/sdkmanager --sdk_root="${SDK_INSTALLATION_DIR}" --install "platforms;android-34"
7272
yes | /opt/cmdline-tools/bin/sdkmanager --sdk_root="${SDK_INSTALLATION_DIR}" --install "build-tools;33.0.1"
73+
yes | /opt/cmdline-tools/bin/sdkmanager --sdk_root="${SDK_INSTALLATION_DIR}" --install "build-tools;35.0.0"
7374
# And some more tools for future emulator tests
7475
yes | /opt/cmdline-tools/bin/sdkmanager --sdk_root="${SDK_INSTALLATION_DIR}" --install "platform-tools"
7576
yes | /opt/cmdline-tools/bin/sdkmanager --sdk_root="${SDK_INSTALLATION_DIR}" --install "tools"

.ci/docker/conda-env-ci.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake=3.22.1
1+
cmake=3.26.4
22
ninja=1.10.2
33
libuv
44
llvm-openmp
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
# Copyright (c) Qualcomm Innovation Center, Inc.
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+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
11+
12+
export EXECUTORCH_ROOT="$(dirname "${BASH_SOURCE[0]}")/../.."
13+
14+
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
15+
PYTHON_EXECUTABLE=python3
16+
fi
17+
18+
which "${PYTHON_EXECUTABLE}"
19+
20+
# Update tokenizers submodule
21+
pushd $EXECUTORCH_ROOT/extension/llm/tokenizers
22+
echo "Update tokenizers submodule"
23+
git submodule update --init
24+
popd
25+
26+
# Install ET with CMake
27+
cmake -DPYTHON_EXECUTABLE=python \
28+
-DCMAKE_INSTALL_PREFIX=cmake-out \
29+
-DEXECUTORCH_ENABLE_LOGGING=1 \
30+
-DCMAKE_BUILD_TYPE=Release \
31+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
32+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
33+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
34+
-DEXECUTORCH_BUILD_XNNPACK=OFF \
35+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
36+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
37+
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
38+
-Bcmake-out .
39+
cmake --build cmake-out -j16 --target install --config Release
40+
41+
# Install llama runner with torchao
42+
cmake -DPYTHON_EXECUTABLE=python \
43+
-DCMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())') \
44+
-DCMAKE_BUILD_TYPE=Release \
45+
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
46+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
47+
-DEXECUTORCH_BUILD_XNNPACK=OFF \
48+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
49+
-DEXECUTORCH_BUILD_TORCHAO=ON \
50+
-Bcmake-out/examples/models/llama \
51+
examples/models/llama
52+
cmake --build cmake-out/examples/models/llama -j16 --config Release
53+
54+
# Download stories llama110m artifacts
55+
download_stories_model_artifacts
56+
57+
echo "Creating tokenizer.bin"
58+
$PYTHON_EXECUTABLE -m extension.llm.tokenizer.tokenizer -t tokenizer.model -o tokenizer.bin
59+
60+
# Export model
61+
LLAMA_CHECKPOINT=stories110M.pt
62+
LLAMA_PARAMS=params.json
63+
MODEL_OUT=model.pte
64+
TOKENIZER=tokenizer.bin
65+
66+
# Set low-bit quantization parameters
67+
QLINEAR_BITWIDTH=3 # Can be 1-8
68+
QLINEAR_GROUP_SIZE=128 # Must be multiple of 16
69+
QEMBEDDING_BITWIDTH=4 # Can be 1-8
70+
QEMBEDDING_GROUP_SIZE=32 # Must be multiple of 16
71+
72+
${PYTHON_EXECUTABLE} -m examples.models.llama.export_llama \
73+
--checkpoint "${LLAMA_CHECKPOINT:?}" \
74+
--params "${LLAMA_PARAMS:?}" \
75+
-kv \
76+
--use_sdpa_with_kv_cache \
77+
--output_name=${MODEL_OUT} \
78+
-qmode "torchao:8da${QLINEAR_BITWIDTH}w" \
79+
--group_size ${QLINEAR_GROUP_SIZE} \
80+
-E "torchao:${QEMBEDDING_BITWIDTH},${QEMBEDDING_GROUP_SIZE}" \
81+
--disable_dynamic_shape \
82+
-d fp32
83+
84+
# Test run
85+
./cmake-out/examples/models/llama/llama_main --model_path=$MODEL_OUT --tokenizer_path=$TOKENIZER --prompt="Once upon a time,"

.github/workflows/android-perf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: android-perf
22

33
on:
44
schedule:
5-
- cron: 0 0 * * *
5+
- cron: 0 0,8,16 * * *
66
pull_request:
77
paths:
88
- .github/workflows/android-perf.yml

.github/workflows/trunk.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
2424
strategy:
2525
matrix:
26-
# Mac runners are expensive and limited, and non reliable.
27-
# Do some basic testing for macos jobs, and rely mostly on
26+
# Mac runners are expensive and limited, and non reliable.
27+
# Do some basic testing for macos jobs, and rely mostly on
2828
# test-models-linux-aarch64 job instead.
2929
model: [emformer_join, ic4, llama2, mobilebert, mv3, resnet50, vit, w2l]
3030
backend: [xnnpack-quantization-delegation]
@@ -288,6 +288,26 @@ jobs:
288288
# Test ANE llama
289289
${CONDA_RUN} sh .ci/scripts/test_ane_static_llama.sh
290290
291+
test-llama-torchao-lowbit:
292+
name: test-llama-torchao-lowbit
293+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
294+
with:
295+
runner: macos-m1-stable
296+
python-version: '3.11'
297+
submodules: 'true'
298+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
299+
script: |
300+
set -eux
301+
bash .ci/scripts/setup-conda.sh
302+
eval "$(conda shell.bash hook)"
303+
304+
# Install requirements
305+
${CONDA_RUN} python install_executorch.py
306+
${CONDA_RUN} sh examples/models/llama/install_requirements.sh
307+
308+
# Run test
309+
${CONDA_RUN} sh .ci/scripts/test_llama_torchao_lowbit.sh
310+
291311
test-llama-runner-linux:
292312
# Test Both linux x86 and linux aarch64
293313
name: test-llama-runner-linux

backends/arm/operators/op_avg_pool2d.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@ def _build_generic_avgpool2d(
4343
output_zp: int,
4444
accumulator_type: ts.DType,
4545
) -> None:
46-
input_tensor = inputs[0]
4746

47+
input_tensor = inputs[0]
4848
kernel_size_list = inputs[1].special
4949
stride_size_list = inputs[2].special
50+
5051
try:
5152
pad_size_list = inputs[3].special
53+
pad_size_list = [
54+
pad_size_list[0],
55+
pad_size_list[0],
56+
pad_size_list[1],
57+
pad_size_list[1],
58+
]
5259
except IndexError:
5360
pad_size_list = [0, 0, 0, 0]
5461

backends/arm/operators/op_max_pool2d.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ def define_node(
4242
stride = inputs[2].special
4343

4444
try:
45-
padding = [*inputs[3].special, *inputs[3].special]
45+
pad_size_list = inputs[3].special
46+
pad_size_list = [
47+
pad_size_list[0],
48+
pad_size_list[0],
49+
pad_size_list[1],
50+
pad_size_list[1],
51+
]
4652
except IndexError:
47-
padding = [0, 0, 0, 0]
53+
pad_size_list = [0, 0, 0, 0]
4854

4955
accumulator_type = output.dtype
5056

@@ -63,7 +69,7 @@ def define_node(
6369
attr.PoolAttribute(
6470
kernel=kernel_size,
6571
stride=stride,
66-
pad=padding,
72+
pad=pad_size_list,
6773
input_zp=input_zp,
6874
output_zp=output_zp,
6975
accum_dtype=accumulator_type,

0 commit comments

Comments
 (0)