Skip to content

Commit c5b05a9

Browse files
Qualcomm AI Engine Direct - Enable Example/OSS models on GPU backend (pytorch#16425)
### Summary Update model scripts for GPU backend. ## Succeed - albert - bert - conv_former - convnext_small - cvt - deit - distilbert - dit - edsr - fbnet - focalnet - gMLP - inception_v3 - inception_v4 - maxvit_t - mobilevit_v1 - mobilenet_v2 - regnet - retinanet - torchvision_vit ## Validation failed - dino_v2 - efficientnet - efficientSAM - esrgan - eurobert - mobilevit_v2 - squeezenet - ssd300_vgg16 - swin_v2_t - t5 - whisper ## Finalization failed - fastvit ## Has accuracy issue - pvt - roberta - swin_transformer - vit_b_16 - mobilenet_v3 ### Test plan ``` python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_albert --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --sentence_dataset /local/mnt/workspace/chenweng/executorch/wikisent2.txt python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_bert --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --sentence_dataset /local/mnt/workspace/chenweng/executorch/wikisent2.txt python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_conv_former --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_convnext_small --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_cvt --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_deit --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_dino_v2 --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_distilbert --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --sentence_dataset /local/mnt/workspace/chenweng/executorch/wikisent2.txt python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_dit --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_efficientnet --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_efficientSAM --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val --pretrained_weight /local/mnt/workspace/chenweng/executorch/EfficientSAM/weights/efficient_sam_vitt.pt --oss_repo /local/mnt/workspace/chenweng/executorch/EfficientSAM -v python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_esrgan --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --oss_repo /local/mnt/workspace/chenweng/executorch/Real-ESRGAN -v python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_eurobert --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --sentence_dataset /local/mnt/workspace/chenweng/executorch/wikisent2.txt python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_fastvit --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val --pretrained_weight /local/mnt/workspace/chenweng/executorch/fastvit_s12_reparam.pth.tar --oss_repo /local/mnt/workspace/chenweng/executorch/ml-fastvit -v python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_fbnet --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_focalnet --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_gMLP --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_maxvit_t --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_mobilevit_v1 --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_mobilevit_v2 --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_pvt --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_regnet --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_retinanet --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/val2017 python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_roberta --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --sentence_dataset /local/mnt/workspace/chenweng/executorch/wikisent2.txt python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_squeezenet --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_ssd300_vgg16 --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --pretrained_weight /local/mnt/workspace/chenweng/executorch/checkpoint_ssd300.pth.tar --oss_repo /local/mnt/workspace/chenweng/executorch/a-PyTorch-Tutorial-to-Object-Detection python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_swin_transformer --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_swin_v2_t --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_t5 --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --qa_dataset /local/mnt/workspace/chenweng/executorch/SQuAD-v1.1.csv python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_vit_b_16 --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleOssScript.test_whisper --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleScript.test_edsr --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --default_dataset python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleScript.test_inception_v3 --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleScript.test_inception_v4 --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleScript.test_mobilenet_v2 --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleScript.test_mobilenet_v3 --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val python ${EXECUTORCH_ROOT}/backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleScript.test_vit --model SM8650 --build_folder /local/mnt/workspace/chenweng/executorch/executorch/build-android --host <host> --device <device_id> --executorch_root ${EXECUTORCH_ROOT} --artifact_dir ./artifact_dir --backend gpu --online_prepare --image_dataset /local/mnt/workspace/chenweng/executorch/imagenet-mini/val ``` cc @cccclai @cbilgin
1 parent 8b78cc1 commit c5b05a9

40 files changed

Lines changed: 816 additions & 871 deletions

‎backends/qualcomm/tests/test_qnn_delegate.py‎

Lines changed: 140 additions & 729 deletions
Large diffs are not rendered by default.

‎backends/qualcomm/tests/utils.py‎

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
)
2121
from executorch.backends.qualcomm.qnn_preprocess import QnnBackend
2222
from executorch.backends.qualcomm.quantizer.quantizer import ModuleQConfig, QuantDtype
23-
from executorch.backends.qualcomm.serialization.qc_schema import (
24-
QcomChipset,
25-
QnnExecuTorchBackendType,
26-
)
23+
from executorch.backends.qualcomm.serialization.qc_schema import QcomChipset
2724
from executorch.backends.qualcomm.utils.constants import (
2825
QCOM_DTYPE,
2926
QCOM_PASS_ACTIVATE_KEY,
@@ -39,6 +36,7 @@
3936
from executorch.devtools.inspector._inspector_utils import TimeScale
4037
from executorch.examples.qualcomm.utils import (
4138
generate_inputs,
39+
get_backend_type,
4240
make_output_dir,
4341
make_quantizer,
4442
SimpleADB,
@@ -222,9 +220,6 @@ def _save_model_and_expected_output(
222220

223221
return ref_outputs, pte_fname
224222

225-
def get_backend_type(self):
226-
return getattr(QnnExecuTorchBackendType, f"k{self.backend.title()}Backend")
227-
228223
def required_envs(self, conditions=None) -> bool:
229224
conditions = [] if conditions is None else conditions
230225
return all(
@@ -235,6 +230,42 @@ def required_envs(self, conditions=None) -> bool:
235230
]
236231
)
237232

233+
def add_default_cmds(self, cmds):
234+
cmds.extend(
235+
[
236+
"--model",
237+
self.model,
238+
"--target",
239+
self.target,
240+
"--ip",
241+
self.ip,
242+
"--port",
243+
str(self.port),
244+
"--seed",
245+
str(1126),
246+
"--backend",
247+
self.backend,
248+
]
249+
)
250+
if self.compile_only:
251+
cmds.extend(["--compile_only"])
252+
elif self.device:
253+
cmds.extend(["--device", self.device])
254+
255+
if self.host:
256+
cmds.extend(["--host", self.host])
257+
elif self.enable_x86_64:
258+
cmds.extend(["--enable_x86_64"])
259+
260+
if self.online_prepare:
261+
cmds.extend(["--online_prepare"])
262+
263+
if self.shared_buffer:
264+
cmds.extend(["--shared_buffer"])
265+
266+
if self.pre_gen_pte:
267+
cmds.extend(["--pre_gen_pte", self.pre_gen_pte])
268+
238269
def verify_output( # noqa: C901
239270
self,
240271
module: torch.nn.Module,
@@ -442,7 +473,7 @@ def validate_intermediate_tensor():
442473
dump_intermediate_outputs=(
443474
True if expected_intermediate_events != -1 else False
444475
),
445-
backend=self.get_backend_type(),
476+
backend=get_backend_type(self.backend),
446477
expected_input_shape=(
447478
(tensor.shape for tensor in processed_inputs)
448479
if check_io_shape

‎examples/qualcomm/oss_scripts/albert.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
get_capture_program_passes,
1818
)
1919
from executorch.backends.qualcomm.quantizer.quantizer import QuantDtype
20+
from executorch.backends.qualcomm.serialization.qc_schema import (
21+
QnnExecuTorchBackendType,
22+
)
2023

2124
from executorch.examples.qualcomm.utils import (
2225
build_executorch_binary,
26+
get_backend_type,
2327
get_masked_language_model_dataset,
2428
make_output_dir,
2529
parse_skip_delegation_node,
@@ -61,12 +65,17 @@ def main(args):
6165
config = AlbertConfig.from_pretrained(model_name)
6266
config.hidden_act = "gelu"
6367
module = AutoModelForMaskedLM.from_pretrained(model_name, config=config).eval()
64-
pte_filename = "albert_qnn_q16"
68+
pte_filename = "albert_qnn"
6569

6670
# Skip lowering/compilation if using pre-generated PTE
6771
if not args.pre_gen_pte:
6872
# lower to QNN
6973
passes_job = get_capture_program_passes()
74+
backend = get_backend_type(args.backend)
75+
quant_dtype = {
76+
QnnExecuTorchBackendType.kGpuBackend: None,
77+
QnnExecuTorchBackendType.kHtpBackend: QuantDtype.use_16a16w,
78+
}[backend]
7079
build_executorch_binary(
7180
module,
7281
inputs[0],
@@ -75,9 +84,11 @@ def main(args):
7584
dataset=inputs,
7685
skip_node_id_set=skip_node_id_set,
7786
skip_node_op_set=skip_node_op_set,
78-
quant_dtype=QuantDtype.use_16a16w,
87+
quant_dtype=quant_dtype,
88+
backend=backend,
7989
passes_job=passes_job,
8090
shared_buffer=args.shared_buffer,
91+
online_prepare=args.online_prepare,
8192
)
8293

8394
if args.compile_only:
@@ -100,6 +111,7 @@ def main(args):
100111
soc_model=args.model,
101112
shared_buffer=args.shared_buffer,
102113
target=args.target,
114+
backend=backend,
103115
)
104116
output_data_folder = f"{args.artifact}/outputs"
105117
make_output_dir(output_data_folder)

‎examples/qualcomm/oss_scripts/bert.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
get_capture_program_passes,
1818
)
1919
from executorch.backends.qualcomm.quantizer.quantizer import QuantDtype
20+
from executorch.backends.qualcomm.serialization.qc_schema import (
21+
QnnExecuTorchBackendType,
22+
)
2023

2124
from executorch.examples.qualcomm.utils import (
2225
build_executorch_binary,
26+
get_backend_type,
2327
get_masked_language_model_dataset,
2428
make_output_dir,
2529
parse_skip_delegation_node,
@@ -58,12 +62,17 @@ def main(args):
5862
module = AutoModelForMaskedLM.from_pretrained(
5963
"google-bert/bert-base-uncased"
6064
).eval()
61-
pte_filename = "bert_qnn_q16"
65+
pte_filename = "bert_qnn"
6266

6367
# Skip lowering/compilation if using pre-generated PTE
6468
if not args.pre_gen_pte:
6569
# lower to QNN
6670
passes_job = get_capture_program_passes()
71+
backend = get_backend_type(args.backend)
72+
quant_dtype = {
73+
QnnExecuTorchBackendType.kGpuBackend: None,
74+
QnnExecuTorchBackendType.kHtpBackend: QuantDtype.use_16a8w,
75+
}[backend]
6776
build_executorch_binary(
6877
module,
6978
inputs[0],
@@ -72,9 +81,11 @@ def main(args):
7281
dataset=inputs,
7382
skip_node_id_set=skip_node_id_set,
7483
skip_node_op_set=skip_node_op_set,
75-
quant_dtype=QuantDtype.use_16a8w,
84+
quant_dtype=quant_dtype,
85+
backend=backend,
7686
passes_job=passes_job,
7787
shared_buffer=args.shared_buffer,
88+
online_prepare=args.online_prepare,
7889
)
7990

8091
if args.compile_only:
@@ -97,6 +108,7 @@ def main(args):
97108
soc_model=args.model,
98109
shared_buffer=args.shared_buffer,
99110
target=args.target,
111+
backend=backend,
100112
)
101113
output_data_folder = f"{args.artifact}/outputs"
102114
make_output_dir(output_data_folder)

‎examples/qualcomm/oss_scripts/conv_former.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
import timm
1616
import torch
1717
from executorch.backends.qualcomm.quantizer.quantizer import QuantDtype
18+
from executorch.backends.qualcomm.serialization.qc_schema import (
19+
QnnExecuTorchBackendType,
20+
)
1821
from executorch.examples.qualcomm.utils import (
1922
build_executorch_binary,
23+
get_backend_type,
2024
get_imagenet_dataset,
2125
make_output_dir,
2226
parse_skip_delegation_node,
@@ -52,15 +56,23 @@ def main(args):
5256
model = model.eval()
5357

5458
# lower to QNN
59+
backend = get_backend_type(args.backend)
60+
quant_dtype = {
61+
QnnExecuTorchBackendType.kGpuBackend: None,
62+
QnnExecuTorchBackendType.kHtpBackend: QuantDtype.use_8a8w,
63+
}[backend]
5564
build_executorch_binary(
5665
model,
5766
inputs[0],
5867
args.model,
5968
f"{args.artifact}/{pte_filename}",
6069
inputs,
61-
quant_dtype=QuantDtype.use_8a8w,
70+
quant_dtype=quant_dtype,
71+
backend=backend,
6272
skip_node_id_set=skip_node_id_set,
6373
skip_node_op_set=skip_node_op_set,
74+
shared_buffer=args.shared_buffer,
75+
online_prepare=args.online_prepare,
6476
)
6577

6678
if args.compile_only:
@@ -76,6 +88,7 @@ def main(args):
7688
soc_model=args.model,
7789
shared_buffer=args.shared_buffer,
7890
target=args.target,
91+
backend=backend,
7992
)
8093
adb.push(inputs=inputs)
8194
adb.execute()

‎examples/qualcomm/oss_scripts/convnext_small.py‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414

1515
import torch
1616
import torchvision
17-
1817
from executorch.backends.qualcomm.quantizer.quantizer import QuantDtype
18+
from executorch.backends.qualcomm.serialization.qc_schema import (
19+
QnnExecuTorchBackendType,
20+
)
1921
from executorch.examples.qualcomm.utils import (
2022
build_executorch_binary,
23+
get_backend_type,
2124
get_imagenet_dataset,
2225
make_output_dir,
2326
make_quantizer,
@@ -45,19 +48,26 @@ def main(args):
4548
crop_size=224,
4649
)
4750

48-
pte_filename = "convnext_small_qnn_q8"
51+
pte_filename = "convnext_small_qnn"
4952
instance = torchvision.models.convnext_small(weights="IMAGENET1K_V1").eval()
53+
backend = get_backend_type(args.backend)
54+
qnn_quantizer = {
55+
QnnExecuTorchBackendType.kGpuBackend: None,
56+
QnnExecuTorchBackendType.kHtpBackend: make_quantizer(
57+
quant_dtype=QuantDtype.use_8a8w,
58+
per_channel_linear=True,
59+
),
60+
}[backend]
5061
build_executorch_binary(
5162
instance,
5263
inputs[0],
5364
args.model,
5465
f"{args.artifact}/{pte_filename}",
5566
inputs,
56-
custom_quantizer=make_quantizer(
57-
quant_dtype=QuantDtype.use_8a8w,
58-
per_channel_linear=True,
59-
),
67+
custom_quantizer=qnn_quantizer,
68+
backend=backend,
6069
shared_buffer=args.shared_buffer,
70+
online_prepare=args.online_prepare,
6171
)
6272

6373
if args.compile_only:
@@ -73,6 +83,7 @@ def main(args):
7383
soc_model=args.model,
7484
shared_buffer=args.shared_buffer,
7585
target=args.target,
86+
backend=backend,
7687
)
7788
adb.push(inputs=inputs)
7889
adb.execute()

‎examples/qualcomm/oss_scripts/cvt.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515

1616
import torch
1717
from executorch.backends.qualcomm.quantizer.quantizer import QuantDtype
18+
from executorch.backends.qualcomm.serialization.qc_schema import (
19+
QnnExecuTorchBackendType,
20+
)
1821
from executorch.examples.qualcomm.utils import (
1922
build_executorch_binary,
23+
get_backend_type,
2024
get_imagenet_dataset,
2125
make_output_dir,
2226
parse_skip_delegation_node,
@@ -115,7 +119,12 @@ def main(args):
115119
)
116120
# Fix prepare failed due to einsum
117121
module = _replace_attention(module)
118-
pte_filename = "cvt_qnn_q8"
122+
pte_filename = "cvt_qnn"
123+
backend = get_backend_type(args.backend)
124+
quant_dtype = {
125+
QnnExecuTorchBackendType.kGpuBackend: None,
126+
QnnExecuTorchBackendType.kHtpBackend: QuantDtype.use_8a8w,
127+
}[backend]
119128
build_executorch_binary(
120129
module.eval(),
121130
inputs[0],
@@ -124,8 +133,10 @@ def main(args):
124133
inputs,
125134
skip_node_id_set=skip_node_id_set,
126135
skip_node_op_set=skip_node_op_set,
127-
quant_dtype=QuantDtype.use_8a8w,
136+
quant_dtype=quant_dtype,
137+
backend=backend,
128138
shared_buffer=args.shared_buffer,
139+
online_prepare=args.online_prepare,
129140
)
130141

131142
if args.compile_only:
@@ -141,6 +152,7 @@ def main(args):
141152
soc_model=args.model,
142153
shared_buffer=args.shared_buffer,
143154
target=args.target,
155+
backend=backend,
144156
)
145157
adb.push(inputs=inputs)
146158
adb.execute()

‎examples/qualcomm/oss_scripts/deit.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
get_capture_program_passes,
1818
)
1919
from executorch.backends.qualcomm.quantizer.quantizer import QuantDtype
20+
from executorch.backends.qualcomm.serialization.qc_schema import (
21+
QnnExecuTorchBackendType,
22+
)
2023
from executorch.examples.qualcomm.utils import (
2124
build_executorch_binary,
25+
get_backend_type,
2226
get_imagenet_dataset,
2327
make_output_dir,
2428
parse_skip_delegation_node,
@@ -65,10 +69,15 @@ def main(args):
6569

6670
# Get the Deit model.
6771
model = get_instance()
68-
pte_filename = "deit_qnn_q8"
72+
pte_filename = "deit_qnn"
6973

7074
# lower to QNN
7175
passes_job = get_capture_program_passes()
76+
backend = get_backend_type(args.backend)
77+
quant_dtype = {
78+
QnnExecuTorchBackendType.kGpuBackend: None,
79+
QnnExecuTorchBackendType.kHtpBackend: QuantDtype.use_8a8w,
80+
}[backend]
7281
build_executorch_binary(
7382
model,
7483
inputs[0],
@@ -77,9 +86,11 @@ def main(args):
7786
dataset=inputs,
7887
skip_node_id_set=skip_node_id_set,
7988
skip_node_op_set=skip_node_op_set,
80-
quant_dtype=QuantDtype.use_8a8w,
89+
quant_dtype=quant_dtype,
90+
backend=backend,
8191
passes_job=passes_job,
8292
shared_buffer=args.shared_buffer,
93+
online_prepare=args.online_prepare,
8394
)
8495

8596
if args.compile_only:
@@ -98,6 +109,7 @@ def main(args):
98109
soc_model=args.model,
99110
shared_buffer=args.shared_buffer,
100111
target=args.target,
112+
backend=backend,
101113
)
102114
adb.push(inputs=inputs)
103115
adb.execute()

0 commit comments

Comments
 (0)