2020
2121from executorch .examples .qualcomm .utils import (
2222 build_executorch_binary ,
23- get_backend_type ,
2423 get_imagenet_dataset ,
2524 make_output_dir ,
26- parse_skip_delegation_node ,
25+ QnnConfig ,
2726 setup_common_args_and_variables ,
2827 SimpleADB ,
2928)
@@ -57,10 +56,8 @@ def postprocess_output_and_save(output, image_height, image_width, output_image_
5756
5857
5958def main (args ):
60- if args .compile_only and args .pre_gen_pte :
61- raise RuntimeError ("Cannot set both compile_only and pre_gen_pte as true" )
62-
63- skip_node_id_set , skip_node_op_set = parse_skip_delegation_node (args )
59+ qnn_config = QnnConfig .load_config (args .config_file if args .config_file else args )
60+ # ensure the working directory exist.
6461 os .makedirs (args .artifact , exist_ok = True )
6562
6663 model = AutoModelForDepthEstimation .from_pretrained (
@@ -101,30 +98,18 @@ def main(args):
10198 goldens .append (predicted_depth .flatten ())
10299
103100 pte_filename = "depthanything_v2_small_qnn"
104- # Skip lowering/compilation if using pre-generated PTE
105- if not args .pre_gen_pte :
106- # Lower to QNN
107- backend = get_backend_type (args .backend )
108- quant_dtype = {
109- QnnExecuTorchBackendType .kGpuBackend : None ,
110- QnnExecuTorchBackendType .kHtpBackend : QuantDtype .use_8a8w ,
111- }[backend ]
112- build_executorch_binary (
113- model ,
114- inputs [0 ],
115- args .model ,
116- os .path .join (args .artifact , pte_filename ),
117- inputs ,
118- skip_node_id_set = skip_node_id_set ,
119- skip_node_op_set = skip_node_op_set ,
120- quant_dtype = quant_dtype ,
121- backend = backend ,
122- shared_buffer = args .shared_buffer ,
123- online_prepare = args .online_prepare ,
124- )
125-
126- if args .compile_only :
127- return
101+ quant_dtype = {
102+ QnnExecuTorchBackendType .kGpuBackend : None ,
103+ QnnExecuTorchBackendType .kHtpBackend : QuantDtype .use_8a8w ,
104+ QnnExecuTorchBackendType .kLpaiBackend : QuantDtype .use_8a8w ,
105+ }[qnn_config .backend ]
106+ build_executorch_binary (
107+ model = model ,
108+ qnn_config = qnn_config ,
109+ file_name = os .path .join (args .artifact , pte_filename ),
110+ dataset = inputs ,
111+ quant_dtype = quant_dtype ,
112+ )
128113
129114 workspace = f"/data/local/tmp/{ getpass .getuser ()} /executorch/{ pte_filename } "
130115 pte_path = (
@@ -134,17 +119,11 @@ def main(args):
134119 )
135120
136121 adb = SimpleADB (
137- qnn_sdk = os .getenv ("QNN_SDK_ROOT" ),
138- build_path = f"{ args .build_folder } " ,
122+ qnn_config = qnn_config ,
139123 pte_path = pte_path ,
140124 workspace = workspace ,
141- device_id = args .device ,
142- host_id = args .host ,
143- soc_model = args .model ,
144- shared_buffer = args .shared_buffer ,
145- target = args .target ,
146125 )
147- adb .push (inputs = inputs , backends = { backend } )
126+ adb .push (inputs = inputs )
148127 adb .execute ()
149128
150129 # collect output data
@@ -185,11 +164,10 @@ def main(args):
185164 image_width ,
186165 os .path .join (args .artifact , "prediction_depth.png" ),
187166 )
188-
189167 evaluations ["sqnr" ] = sum (evaluations ["sqnr" ]) / data_num
190168 if args .ip and args .port != - 1 :
191169 with Client ((args .ip , args .port )) as conn :
192- conn .send (json .dumps ({"sqnr" : evaluations ["sqnr" ]}))
170+ conn .send (json .dumps ({"sqnr" : evaluations ["sqnr" ]. item () }))
193171 else :
194172 print ("SQNR(dB)={sqnr}" .format (** evaluations ))
195173
@@ -225,7 +203,6 @@ def main(args):
225203 )
226204
227205 args = parser .parse_args ()
228- args .validate (args )
229206
230207 try :
231208 main (args )
0 commit comments