77import os
88from typing import Optional
99
10+ import serializer .tosa_serializer as ts
1011import torch
11-
12- import tosa_serializer as ts
1312from executorch .exir .print_program import inspect_node
1413
1514logger = logging .getLogger (__name__ )
@@ -51,20 +50,29 @@ def get_node_debug_info(
5150 return output
5251
5352
54- # Output TOSA flatbuffer for debugging
55- def debug_tosa_dump (tosa_graph : bytes , path : str , suffix : str = "" ):
53+ # Output TOSA flatbuffer and test harness file
54+ def debug_tosa_dump (tosa_graph : ts . TosaSerializer , path : str , suffix : str = "" ):
5655 filename = f"output{ suffix } .tosa"
5756
5857 logger .info (f"Emitting debug output to: { path = } , { suffix = } " )
5958
6059 os .makedirs (path , exist_ok = True )
6160
61+ fb = tosa_graph .serialize ()
62+ js = tosa_graph .writeJson (filename )
63+
6264 filepath_tosa_fb = os .path .join (path , filename )
6365 with open (filepath_tosa_fb , "wb" ) as f :
64- f .write (tosa_graph )
66+ f .write (fb )
6567 if not os .path .exists (filepath_tosa_fb ):
6668 raise IOError ("Failed to write TOSA flatbuffer" )
6769
70+ filepath_desc_json = os .path .join (path , f"desc{ suffix } .json" )
71+ with open (filepath_desc_json , "w" ) as f :
72+ f .write (js )
73+ if not os .path .exists (filepath_desc_json ):
74+ raise IOError ("Failed to write TOSA JSON" )
75+
6876
6977def debug_fail (
7078 node ,
@@ -73,7 +81,7 @@ def debug_fail(
7381 path : Optional [str ] = None ,
7482):
7583 logger .warning ("Internal error due to poorly handled node:" )
76- if tosa_graph is not None and path :
77- debug_tosa_dump (tosa_graph . serialize () , path )
84+ if tosa_graph is not None and path is not None :
85+ debug_tosa_dump (tosa_graph , path )
7886 logger .warning (f"Debug output captured in '{ path } '." )
7987 debug_node (node , graph_module )
0 commit comments