Pytorch IR with Line Numbers


I was wondering how to generate the PyTorch IR for a Torch Script module with line numbers, like the one shown in the example code:

Currently, foo.graph does not get you the IR with line numbers, so I was wondering if it was possible to get the IR with the line numbers included.

Thank you!

Are you on the latest version of PyTorch (v1.3.0)? You can check with print(torch.__version__). This feature was recently added so if you’re on an older version (e.g. v1.0) it might not show up.

For a simple example like:

def x(e):
    return e + 10


You should get something like

graph(%e.1 : Tensor):
  %3 : int = prim::Constant[value=1]()
  %2 : int = prim::Constant[value=10]() # ../
  %4 : Tensor = aten::add(%e.1, %2, %3) # ../
  return (%4)