Skip to content

Commit 6df7934

Browse files
committed
Qualcomm AI Engine Direct - CI for Non-LLM GA model Part1
1 parent 695c7d5 commit 6df7934

File tree

8 files changed

+70
-23
lines changed

8 files changed

+70
-23
lines changed

.ci/scripts/test_model.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,24 @@ test_model_with_qnn() {
188188
EXPORT_SCRIPT=edsr
189189
# Additional deps for edsr
190190
pip install piq
191+
elif [[ "${MODEL_NAME}" == "cvt" ]]; then
192+
EXPORT_SCRIPT=cvt
193+
elif [[ "${MODEL_NAME}" == "deit" ]]; then
194+
EXPORT_SCRIPT=deit
195+
elif [[ "${MODEL_NAME}" == "dit" ]]; then
196+
EXPORT_SCRIPT=dit
197+
elif [[ "${MODEL_NAME}" == "efficientnet" ]]; then
198+
EXPORT_SCRIPT=efficientnet
199+
elif [[ "${MODEL_NAME}" == "focalnet" ]]; then
200+
EXPORT_SCRIPT=focalnet
201+
elif [[ "${MODEL_NAME}" == "mobilevit_v1" ]]; then
202+
EXPORT_SCRIPT=mobilevit_v1
203+
elif [[ "${MODEL_NAME}" == "mobilevit_v2" ]]; then
204+
EXPORT_SCRIPT=mobilevit_v2
205+
elif [[ "${MODEL_NAME}" == "pvt" ]]; then
206+
EXPORT_SCRIPT=pvt
207+
elif [[ "${MODEL_NAME}" == "swin" ]]; then
208+
EXPORT_SCRIPT=swin_transformer
191209
elif [[ "${MODEL_NAME}" == "albert" ]]; then
192210
EXPORT_SCRIPT=albert
193211
elif [[ "${MODEL_NAME}" == "bert" ]]; then
@@ -196,6 +214,8 @@ test_model_with_qnn() {
196214
EXPORT_SCRIPT=distilbert
197215
elif [[ "${MODEL_NAME}" == "eurobert" ]]; then
198216
EXPORT_SCRIPT=eurobert
217+
elif [[ "${MODEL_NAME}" == "roberta" ]]; then
218+
EXPORT_SCRIPT=roberta
199219
else
200220
echo "Unsupported model $MODEL_NAME"
201221
exit 1
@@ -210,7 +230,10 @@ test_model_with_qnn() {
210230
"dl3"|"mv3"|"mv2"|"ic4"|"ic3"|"vit"|"mb"|"w2l")
211231
SCRIPT_FOLDER=scripts
212232
;;
213-
"albert"|"bert"|"distilbert")
233+
"cvt"|"deit"|"dit"|"efficientnet"|"focalnet"|"mobilevit_v1"|"mobilevit_v2"|"pvt"|"swin")
234+
SCRIPT_FOLDER=oss_scripts
235+
;;
236+
"albert"|"bert"|"distilbert"|"roberta")
214237
pip install evaluate
215238
SCRIPT_FOLDER=oss_scripts
216239
# Bert models running in 16bit will encounter op validation fail on some operations,

.github/workflows/trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ jobs:
489489
strategy:
490490
matrix:
491491
dtype: [fp32]
492-
model: [albert, bert, distilbert] # eurobert requires transfomer >= 4.48.0, skip for now
492+
model: [cvt, deit, dit, efficientnet, focalnet, mobilevit_v1, mobilevit_v2, pvt, swin, albert, bert, distilbert, roberta] # eurobert requires transfomer >= 4.48.0, skip for now
493493
fail-fast: false
494494
with:
495495
runner: linux.2xlarge

backends/qualcomm/builders/op_slice_copy.py

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

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

backends/qualcomm/tests/test_qnn_delegate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4646,13 +4646,13 @@ def test_pvt(self):
46464646
self.assertGreaterEqual(msg["top_1"], 65)
46474647
self.assertGreaterEqual(msg["top_5"], 85)
46484648

4649-
def test_mobilevit1(self):
4649+
def test_mobilevit_v1(self):
46504650
if not self.required_envs([self.image_dataset]):
46514651
self.skipTest("missing required envs")
46524652

46534653
cmds = [
46544654
"python",
4655-
f"{self.executorch_root}/examples/qualcomm/oss_scripts/mobilevit1.py"
4655+
f"{self.executorch_root}/examples/qualcomm/oss_scripts/mobilevit_v1.py"
46564656
"--dataset",
46574657
self.image_dataset,
46584658
"--artifact",

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/mobilevit1.py renamed to examples/qualcomm/oss_scripts/mobilevit_v1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def main(args):
8484
.to("cpu")
8585
)
8686

87-
pte_filename = "mobilevit1_qnn_q16"
87+
pte_filename = "mobilevit_v1_qnn_q16"
8888
build_executorch_binary(
8989
module.eval(),
9090
inputs[0],

examples/qualcomm/oss_scripts/roberta.py

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

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

@@ -38,16 +39,29 @@ def main(args):
3839
skip_node_id_set, skip_node_op_set = parse_skip_delegation_node(args)
3940

4041
os.makedirs(args.artifact, exist_ok=True)
41-
data_size = 100
4242

4343
tokenizer = AutoTokenizer.from_pretrained("xlm-roberta-base")
44-
inputs, targets, input_list = get_masked_language_model_dataset(
45-
args.dataset, tokenizer, data_size
46-
)
44+
data_size = 100
45+
if args.ci:
46+
random_ids = torch.randint(low=0, high=100, size=(1, 100), dtype=torch.int32)
47+
attention_mask = torch.ones((1, 100), dtype=torch.float32)
48+
inputs = [
49+
(
50+
random_ids,
51+
attention_mask,
52+
)
53+
]
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_masked_language_model_dataset(
59+
args.dataset, tokenizer, data_size
60+
)
4761

4862
# Get the Roberta model.
4963
model = get_instance(args)
50-
pte_filename = "roberta_qnn"
64+
pte_filename = "roberta_qnn_q16"
5165

5266
# lower to QNN
5367
passes_job = get_capture_program_passes()
@@ -137,7 +151,7 @@ def main(args):
137151
"-a",
138152
"--artifact",
139153
help="path for storing generated artifacts and output by this example. Default ./Roberta_qnn",
140-
default="./Roberta_qnn",
154+
default="./roberta",
141155
type=str,
142156
)
143157
parser.add_argument(
@@ -149,7 +163,7 @@ def main(args):
149163
"for https://www.kaggle.com/datasets/mikeortman/wikipedia-sentences"
150164
),
151165
type=str,
152-
required=True,
166+
required=False,
153167
)
154168

155169
args = parser.parse_args()

examples/qualcomm/oss_scripts/swin_transformer.py

Lines changed: 4 additions & 3 deletions
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
)
@@ -181,8 +181,9 @@ def main(args):
181181
parser.add_argument(
182182
"-a",
183183
"--artifact",
184-
help="path for storing generated artifacts by this example. " "Default ./swin",
185-
default="./swin",
184+
help="path for storing generated artifacts by this example. "
185+
"Default ./swin_transformer",
186+
default="./swin_transformer",
186187
type=str,
187188
)
188189

0 commit comments

Comments
 (0)