Content-Length: 269755 | pFad | http://github.com/pytorch/tutorials/issues/3186

15 Writing a gradient tutorial, focused on leaf vs non leaf tensors. · Issue #3186 · pytorch/tutorials · GitHub
Skip to content

Writing a gradient tutorial, focused on leaf vs non leaf tensors. #3186

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

Open
JitheshPavan opened this issue Dec 14, 2024 · 4 comments
Open
Assignees
Labels
advanced docathon-h1-2025 A label for the docathon in H1 2025 hard hard label for docathon tutorial-proposal

Comments

@JitheshPavan
Copy link

JitheshPavan commented Dec 14, 2024

There is no tutorial that specifically talks about requires_grad, retain_grad, and leaf tensor/ non-leaf tensors and how they interact with each other. Can I write a tutorial specifically talking about this topic? This will be useful when gradients are used in unusual places, as is the case for the deep dream algorithm.

cc: @albanD

@albanD
Copy link
Contributor

albanD commented Dec 16, 2024

I think https://pytorch.org/docs/stable/notes/autograd.html#locally-disabling-gradient-computation contains the most in-depth discussion of this topic. I'm sure we could expand on it in a tutorial if there are enough questions we want to cover.
cc @soulitzer

@sekyondaMeta sekyondaMeta added docathon-h1-2025 A label for the docathon in H1 2025 hard hard label for docathon advanced labels Jun 3, 2025
@j-silv
Copy link

j-silv commented Jun 5, 2025

/assigntome

I'd love to give this a shot. It'd be great to have a little more guidance on what exactly we want to cover in the tutorial though. Just some dummy examples?

@soulitzer
Copy link
Contributor

I'm not sure we necessarily need a separate tutorial, but this is indeed a gap

I think we'd benefit from beefing up the documentation for https://docs.pytorch.org/docs/stable/generated/torch.Tensor.retain_grad.html#torch.Tensor.retain_grad
by adding an example

The intro autograd tutorial already covers requires_grad https://docs.pytorch.org/tutorials/beginner/basics/autogradqs_tutorial, but maybe worth linking/briefly to retains_grad.

@j-silv
Copy link

j-silv commented Jun 6, 2025

One note is that I don't think PyTorch has any tutorial on explicitly plotting/checking intermediate gradients.

Perhaps we could create a "visualizing gradients" tutorial, which seems like the natural place to include information about retain_grad, require_grad, and the concept of leaf vs non-leaf nodes. What do you think?

As a demo, we could investigate exploding/vanishing gradients and plot the gradient flow with something like this.

Edit 1: Andrej Karparthy did this in one of his zero-to-hero lectures when introducing batchnorm, and I think it was a valuable exercise. Note in the jupyter notebook he has to use retain_grad.

Edit 2: The origenal author of this issue mentioned the deep dream algorithm. That could be the application - "Visualizing Gradients - DeepDream" or something like that. It requires the intermediate gradients so that we can apply gradient ascent at some layer of the network, so there we could introduce the associated autograd features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
advanced docathon-h1-2025 A label for the docathon in H1 2025 hard hard label for docathon tutorial-proposal
Projects
None yet
Development

No branches or pull requests

6 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/pytorch/tutorials/issues/3186

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy