Skip to content

Commit 1c46184

Browse files
committed
Qualcomm AI Engine Direct - CI for Non-LLM GA model Part1
1 parent d7699d6 commit 1c46184

File tree

5 files changed

+66
-10
lines changed

5 files changed

+66
-10
lines changed

.ci/scripts/test_model.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,37 @@ test_model_with_qnn() {
192192
EXPORT_SCRIPT=edsr
193193
# Additional deps for edsr
194194
pip install piq
195+
elif [[ "${MODEL_NAME}" == "deit" ]]; then
196+
EXPORT_SCRIPT=deit
197+
elif [[ "${MODEL_NAME}" == "pvt" ]]; then
198+
EXPORT_SCRIPT=pvt
199+
elif [[ "${MODEL_NAME}" == "swin" ]]; then
200+
EXPORT_SCRIPT=swin_transformer
195201
else
196202
echo "Unsupported model $MODEL_NAME"
197203
exit 1
198204
fi
199205

206+
SCRIPT_FOLDER=""
207+
case "${MODEL_NAME}" in
208+
"dl3"|"mv3"|"mv2"|"ic4"|"ic3"|"vit"|"mb"|"w2l")
209+
SCRIPT_FOLDER=scripts
210+
;;
211+
"deit"|"pvt"|"swin")
212+
SCRIPT_FOLDER=oss_scripts
213+
;;
214+
*)
215+
echo "Unsupported model $MODEL_NAME"
216+
exit 1
217+
;;
218+
esac
219+
220+
200221
# Use SM8450 for S22, SM8550 for S23, and SM8560 for S24
201222
# TODO(guangyang): Make QNN chipset matches the target device
202223
QNN_CHIPSET=SM8450
203224

204-
"${PYTHON_EXECUTABLE}" -m examples.qualcomm.scripts.${EXPORT_SCRIPT} -b ${CMAKE_OUTPUT_DIR} -m ${QNN_CHIPSET} --ci --compile_only $EXTRA_FLAGS
225+
"${PYTHON_EXECUTABLE}" -m examples.qualcomm.${SCRIPT_FOLDER}.${EXPORT_SCRIPT} -b ${CMAKE_OUTPUT_DIR} -m ${QNN_CHIPSET} --ci --compile_only $EXTRA_FLAGS
205226
EXPORTED_MODEL=$(find "./${EXPORT_SCRIPT}" -type f -name "${MODEL_NAME}*.pte" -print -quit)
206227
}
207228

.github/workflows/trunk.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,32 @@ jobs:
479479
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
480480
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
481481
PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh ${{ matrix.model }} "cmake" "qnn"
482+
483+
test-qnn-optimum-model:
484+
name: test-qnn-optimum-model
485+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
486+
permissions:
487+
id-token: write
488+
contents: read
489+
strategy:
490+
matrix:
491+
dtype: [fp32]
492+
model: [deit, pvt, swin]
493+
fail-fast: false
494+
with:
495+
runner: linux.2xlarge
496+
docker-image: executorch-ubuntu-22.04-qnn-sdk
497+
submodules: 'recursive'
498+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
499+
timeout: 900
500+
script: |
501+
# The generic Linux job chooses to use base env, not the one setup by the image
502+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
503+
conda activate "${CONDA_ENV}"
504+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool cmake
505+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
506+
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
507+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh ${{ matrix.model }} "cmake" "qnn"
482508
483509
test-apple-model:
484510
name: test-apple-model

backends/qualcomm/builders/op_slice_copy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def define_node(
5555
if start < 0:
5656
start = start % input_tensor.shape[dim]
5757

58-
if len(node.args) > 3:
58+
if len(node.args) > 3 and node.args[3] is not None:
5959
end = min(cast(int, node.args[3]), input_tensor.shape[dim])
6060
if end < 0:
6161
end = end % input_tensor.shape[dim]

examples/qualcomm/oss_scripts/deit.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
import getpass
88
import json
9+
import logging
910
import os
1011
from multiprocessing.connection import Client
1112

1213
import numpy as np
14+
import torch
1315
from executorch.backends.qualcomm._passes.qnn_pass_manager import (
1416
get_capture_program_passes,
1517
)
@@ -46,12 +48,19 @@ def main(args):
4648
data_num = 100
4749
height = config.image_size
4850
width = config.image_size
49-
inputs, targets, input_list = get_imagenet_dataset(
50-
dataset_path=f"{args.dataset}",
51-
data_size=data_num,
52-
image_shape=(height, width),
53-
crop_size=(height, width),
54-
)
51+
52+
if args.ci:
53+
inputs = [(torch.rand(1, 3, height, width),)]
54+
logging.warning(
55+
"This option is for CI to verify the export flow. It uses random input and will result in poor accuracy."
56+
)
57+
else:
58+
inputs, targets, input_list = get_imagenet_dataset(
59+
dataset_path=f"{args.dataset}",
60+
data_size=data_num,
61+
image_shape=(height, width),
62+
crop_size=(height, width),
63+
)
5564

5665
# Get the Deit model.
5766
model = get_instance()
@@ -134,7 +143,7 @@ def main(args):
134143
"for https://www.kaggle.com/datasets/ifigotin/imagenetmini-1000)"
135144
),
136145
type=str,
137-
required=True,
146+
required=False,
138147
)
139148

140149
args = parser.parse_args()

examples/qualcomm/oss_scripts/swin_transformer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def main(args):
8989

9090
data_num = 100
9191
if args.ci:
92-
inputs = [torch.rand(1, 3, 224, 224)]
92+
inputs = [(torch.rand(1, 3, 224, 224),)]
9393
logging.warning(
9494
"This option is for CI to verify the export flow. It uses random input and will result in poor accuracy."
9595
)

0 commit comments

Comments
 (0)