Order of nodes in scripted graph

Suppose I have the following graph and example code.

import torch

class Net(torch.nn.Module):
    def __init__(self):
        super(Net, self).__init__()

    def forward(self, x):
        z = x.squeeze(0)
        return x

if __name__ == "__main__":
    script = torch.jit.script(Net().eval())
    print("-" * 10)
    for node in script.graph.nodes():

Is the loop guaranteed to iterate over the nodes in an order that preserves the semantics of the in-place operations in the graph?
In this simple example its just enough that the add is looped over before the mul, but the general case is more important to me.
I do get the correct order when running this script, but Iā€™m interested if this is guaranteed.

Reodering is done with checking dependencies, including side effects:

Best regards


1 Like

Thanks! Greatly appreciated (: