Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lisibility of saved tensor #69

Open
Varal7 opened this issue Jul 27, 2021 · 1 comment
Open

Lisibility of saved tensor #69

Varal7 opened this issue Jul 27, 2021 · 1 comment

Comments

@Varal7
Copy link
Contributor

Varal7 commented Jul 27, 2021

The commit pytorch/pytorch@1efa863 changes the way variables are saved during the forward (in certain cases).

This can create comical graphs when visualized with torchviz because the saved variable shares the same id as the input.

For instance:

a = torch.randn(5, requires_grad=True)
y = a * a
make_dot(y, show_saved=True)

Before:

After pytorch/pytorch@1efa863:

In this second image the blue node and the two orange nodes are merged into one.

I'm opening this issue to discuss how we would to fix this.

One option is to revert back to the old behavior by giving unique names to each node (so something like dot.node(SAVED_PREFIX + attr + str(id(val)), get_var_name(val, attr), fillcolor='orange')).
The drawback is that the user loses the information that those three nodes are indeed backed by the same tensor.

Another option would be to draw a dotted edge between the saved variable and its base, for instance:

cc @soulitzer @albanD

@albanD
Copy link
Contributor

albanD commented Aug 24, 2021

From offline discussion, I think the dotted line version is nice.
Note that this actually exposes some "internal" autograd stuff as these Tensors being the exact same python object or not is only true for non-outputs.
Maybe we could change the way we do this detection and use tensor.data_ptr() to detect if SavedVariables ever match another Tensor already here. And use dotted lines between them (to specify they are views of each other).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants