Regarding functionalization, is there a guarantee that a functional graph will be always generated?
If there’s complicated aliasing (e.g., through multiple views), we’ll just ship some preconditions to Dynamo as trace guards?
Hey @nunoplopes - that’s right. We will always guarantee a functional graph when you ask for core ATen IR.
More specifically:
-
any “internal” mutations in the program will be functionalized away. This includes, say, if you have two tensors that are aliased and you mutate one, we’ll make sure the right thing happens.
-
“input mutation” support is a bit special, e.g. if you have a model who’s forward pass mutates buffers. We will still fully functionalize the graph, but the updated buffers will show up as extra out puts in the forward graph, and export has some metadata telling you specifically which buffers were mutated and what outputs they map to.
-
you can imagine some crazier situations, where e.g your model takes in two inputs that are aliased to each other, and your model mutates them. This is actually supported in torch.compile, but banned when trying to export an aten graph (because it requires complicated calling convention changes, and is generally not common).