What's the difference between scriptmodule.graph() vs. scriptmodule.graph_for()

I noticed that scriptmodule have graph() and graph_for() methods, but I am confused about those two methods. Does anyone can tell me the difference? really thanks!

graph_for should try to optimize or fuse the graph for the provided inputs, while graph should print the IR directly.


Great! now I see, and I have another question, will torch.jit.script() try to optimize or fuse the graph when exporting a pytorch native model to a scriptmodule?

It will automatically optimize/fuse for you when you run it with some inputs, graph_for is showing you a preview of what will be executed for a certain set of inputs.

1 Like