MCPcopy Create free account
hub / github.com/pytorch/executorch / main

Function main

examples/qualcomm/oss_scripts/conv_former.py:33–101  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

31
32
33def main(args):
34 qnn_config = QnnConfig.load_config(args.config_file if args.config_file else args)
35
36 # ensure the working directory exist.
37 os.makedirs(args.artifact, exist_ok=True)
38
39 data_num = 100
40 if args.ci:
41 inputs = [(torch.rand(1, 3, 224, 224),)]
42 logging.warning(
43 "This option is for CI to verify the export flow. It uses random input and will result in poor accuracy."
44 )
45 else:
46 inputs, targets = get_imagenet_dataset(
47 dataset_path=f"{args.dataset}",
48 data_size=data_num,
49 image_shape=(256, 256),
50 crop_size=224,
51 )
52
53 pte_filename = "conv_former"
54 model = timm.create_model("convformer_s18.sail_in1k", pretrained=True)
55
56 model = model.eval()
57
58 # lower to QNN
59 quant_dtype = {
60 QnnExecuTorchBackendType.kGpuBackend: None,
61 QnnExecuTorchBackendType.kHtpBackend: QuantDtype.use_8a8w,
62 }[qnn_config.backend]
63 build_executorch_binary(
64 model=model,
65 qnn_config=qnn_config,
66 file_name=f"{args.artifact}/{pte_filename}",
67 dataset=inputs,
68 quant_dtype=quant_dtype,
69 )
70
71 adb = SimpleADB(
72 qnn_config=qnn_config,
73 pte_path=f"{args.artifact}/{pte_filename}.pte",
74 workspace=f"/data/local/tmp/executorch/{pte_filename}",
75 )
76 adb.push(inputs=inputs)
77 adb.execute()
78
79 # collect output data
80 output_data_folder = f"{args.artifact}/outputs"
81 make_output_dir(output_data_folder)
82
83 adb.pull(host_output_path=args.artifact)
84
85 # top-k analysis
86 predictions = []
87 for i in range(data_num):
88 predictions.append(
89 np.fromfile(
90 os.path.join(output_data_folder, f"output_{i}_0.raw"), dtype=np.float32

Callers 1

conv_former.pyFile · 0.70

Calls 11

pushMethod · 0.95
executeMethod · 0.95
pullMethod · 0.95
get_imagenet_datasetFunction · 0.90
build_executorch_binaryFunction · 0.90
SimpleADBClass · 0.90
make_output_dirFunction · 0.90
topk_accuracyFunction · 0.90
load_configMethod · 0.80
create_modelMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected