It is possible to iterate torch._C.graph?

Hi folks,

I’m following this Official PyTorch ONNX tutorial and I would like to iterate through the torch._C.graph that generated so I can obtain the “layer indexes” from the trace (i.e. for the AlexNet tutorial, it is %17, %18 and so on).

Is that possible? The reason why I want the indexes because I want to do a one-to-one layer comparison between PyTorch and Core ML layers generated by my model. Thanks!

2 Likes

I think I figured it out. For those who interested in getting the “layer indexes”, or to be specific, the “output indexes”, check out this file https://github.com/pytorch/pytorch/blob/98e312cf96f6a5e23933cd8794097063ee3cbc8c/torch/utils/tensorboard/_pytorch_graph.py

1 Like