(args)
| 101 | |
| 102 | |
| 103 | def main(args): |
| 104 | qnn_config = QnnConfig.load_config(args.config_file if args.config_file else args) |
| 105 | |
| 106 | # ensure the working directory exist. |
| 107 | os.makedirs(args.artifact, exist_ok=True) |
| 108 | |
| 109 | instance = EdsrModel() |
| 110 | if args.ci: |
| 111 | inputs = instance.get_example_inputs() |
| 112 | logging.warning( |
| 113 | "This option is for CI to verify the export flow. It uses random input and will result in poor accuracy." |
| 114 | ) |
| 115 | else: |
| 116 | dataset = get_dataset( |
| 117 | args.hr_ref_dir, args.lr_dir, args.default_dataset, args.artifact |
| 118 | ) |
| 119 | |
| 120 | inputs, targets = dataset.lr, dataset.hr |
| 121 | |
| 122 | pte_filename = "edsr_qnn" |
| 123 | quant_dtype = { |
| 124 | QnnExecuTorchBackendType.kGpuBackend: None, |
| 125 | QnnExecuTorchBackendType.kHtpBackend: QuantDtype.use_8a8w, |
| 126 | }[qnn_config.backend] |
| 127 | build_executorch_binary( |
| 128 | model=instance.get_eager_model().eval(), |
| 129 | qnn_config=qnn_config, |
| 130 | file_name=f"{args.artifact}/{pte_filename}", |
| 131 | dataset=[(input,) for input in inputs], |
| 132 | quant_dtype=quant_dtype, |
| 133 | ) |
| 134 | |
| 135 | adb = SimpleADB( |
| 136 | qnn_config=qnn_config, |
| 137 | pte_path=f"{args.artifact}/{pte_filename}.pte", |
| 138 | workspace=f"/data/local/tmp/executorch/{pte_filename}", |
| 139 | ) |
| 140 | adb.push(inputs=inputs) |
| 141 | adb.execute() |
| 142 | |
| 143 | # collect output data |
| 144 | output_data_folder = f"{args.artifact}/outputs" |
| 145 | output_pic_folder = f"{args.artifact}/output_pics" |
| 146 | make_output_dir(output_data_folder) |
| 147 | make_output_dir(output_pic_folder) |
| 148 | |
| 149 | output_raws = [] |
| 150 | |
| 151 | def post_process(): |
| 152 | cnt = 0 |
| 153 | output_shape = tuple(targets[0].size()) |
| 154 | for f in sorted( |
| 155 | os.listdir(output_data_folder), key=lambda f: int(f.split("_")[1]) |
| 156 | ): |
| 157 | filename = os.path.join(output_data_folder, f) |
| 158 | if re.match(r"^output_[0-9]+_[1-9].raw$", f): |
| 159 | os.remove(filename) |
| 160 | else: |
no test coverage detected