2121from  executorch .backends .nxp .neutron_partitioner  import  NeutronPartitioner 
2222from  executorch .backends .nxp .nxp_backend  import  generate_neutron_compile_spec 
2323from  executorch .backends .nxp .quantizer .neutron_quantizer  import  NeutronQuantizer 
24+ from  executorch .devtools .visualization .visualization_utils  import  (
25+     visualize_with_clusters ,
26+ )
2427from  executorch .examples .models  import  MODEL_NAME_TO_MODEL 
2528from  executorch .examples .models .model_factory  import  EagerModelFactory 
2629from  executorch .exir  import  (
@@ -210,6 +213,12 @@ def _get_batch_size(data):
210213        nargs = "*" ,
211214        help = "List of operators not to delegate. E.g., --operators_not_to_delegate aten::convolution aten::mm" ,
212215    )
216+     parser .add_argument (
217+         "--visualize" ,
218+         choices = ["show" , "store" ],
219+         help = "Visualize the lowered program. `show` launches a browser tab with the visualization. `store` stores the " 
220+         "visualization in a json file for later inspection. See `docs/source/visualize-with-clusters.md` for details." ,
221+     )
213222
214223    args  =  parser .parse_args ()
215224
@@ -237,7 +246,7 @@ def _get_batch_size(data):
237246        module  =  post_training_quantize (module , calibration_inputs )
238247
239248    if  args .so_library  is  not None :
240-         logging .debug (f"Loading libraries: { args .so_library }  and  { args . portable_lib }  )
249+         logging .debug (f"Loading libraries: { args .so_library }  )
241250        torch .ops .load_library (args .so_library )
242251
243252    if  args .test :
@@ -284,7 +293,7 @@ def _get_batch_size(data):
284293            raise  RuntimeError (
285294                e .args [0 ]
286295                +  ".\n This likely due to an external so library not being loaded. Supply a path to it with the " 
287-                 "--portable_lib  flag." 
296+                 "--so_library  flag." 
288297            ).with_traceback (e .__traceback__ ) from  None 
289298        else :
290299            raise  e 
@@ -301,3 +310,13 @@ def executorch_program_to_str(ep, verbose=False):
301310        "_nxp_delegate"  if  args .delegate  is  True  else  "" 
302311    )
303312    save_pte_program (exec_prog , model_name )
313+ 
314+     # 7. Optionally visualize the model. 
315+     if  args .visualize  ==  "show" :
316+         visualize_with_clusters (exec_prog .exported_program ())
317+     elif  args .visualize  ==  "store" :
318+         file_name  =  f"{ args .model_name }  
319+         logging .info (
320+             f"Saved the graph visualization in `{ file_name }  
321+         )
322+         visualize_with_clusters (exec_prog .exported_program (), file_name )
0 commit comments