Is there a way to export graph.print_tabular()

gm = torch.fx.symbolic_trace(m)


I am trying to export the graph for model, is there anyway to convert graph.print_tabular() into dictionary format?

Something of this kind?

graph = {
            f"op_{idx}": {
                "opcode": n.op,
                "args": n.args,
                "kwargs": n.kwargs,
            } for idx, n in enumerate(gm.graph.nodes)

Yes, this will work, Thank you so much

You might try something like this as well which is simplier, but I don’t remember by heart what Node.dict contains exactly.

graph = {f"op_{idx}": n.__dict__ for idx, n in enumerate(gm.graph.nodes)}