77import os
88from typing import Optional
99
10- import serializer .tosa_serializer as ts
1110import torch
11+
12+ import tosa_serializer as ts
1213from executorch .exir .print_program import inspect_node
1314
1415logger = logging .getLogger (__name__ )
@@ -50,29 +51,20 @@ def get_node_debug_info(
5051 return output
5152
5253
53- # Output TOSA flatbuffer and test harness file
54- def debug_tosa_dump (tosa_graph : ts . TosaSerializer , path : str , suffix : str = "" ):
54+ # Output TOSA flatbuffer for debugging
55+ def debug_tosa_dump (tosa_graph : bytes , path : str , suffix : str = "" ):
5556 filename = f"output{ suffix } .tosa"
5657
5758 logger .info (f"Emitting debug output to: { path = } , { suffix = } " )
5859
5960 os .makedirs (path , exist_ok = True )
6061
61- fb = tosa_graph .serialize ()
62- js = tosa_graph .writeJson (filename )
63-
6462 filepath_tosa_fb = os .path .join (path , filename )
6563 with open (filepath_tosa_fb , "wb" ) as f :
66- f .write (fb )
64+ f .write (tosa_graph )
6765 if not os .path .exists (filepath_tosa_fb ):
6866 raise IOError ("Failed to write TOSA flatbuffer" )
6967
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-
7668
7769def debug_fail (
7870 node ,
@@ -81,7 +73,7 @@ def debug_fail(
8173 path : Optional [str ] = None ,
8274):
8375 logger .warning ("Internal error due to poorly handled node:" )
84- if tosa_graph is not None and path is not None :
85- debug_tosa_dump (tosa_graph , path )
76+ if tosa_graph is not None and path :
77+ debug_tosa_dump (tosa_graph . serialize () , path )
8678 logger .warning (f"Debug output captured in '{ path } '." )
8779 debug_node (node , graph_module )
0 commit comments