Skip to content

Add work-in-progress for visualizing gradients tutorial (issue #3186) #3389

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

j-silv
Copy link

@j-silv j-silv commented Jun 9, 2025

Fixes #3186

Description

Add initial draft for visualizing gradients tutorial. Link is here

This write-up starts by discussing the difference between leaf and non-leaf tensors, and the associated requires_grad and retains_grad class attributes.

It then will go through a real-world example of visualizing gradients by using the retains_grad in a more complicated neural network like ResNet (this part is a work-in-progress).

I put the tutorial in the advanced_source directory but perhaps it would be better sorted as an intermediate tutorial or a recipe. Open to suggestions.

What's written so far is how I imagined structuring the tutorial. If you have any comments about the overall flow / material let me know. Feel free to comment on the wordage and tone as well, just know that I plan on revising tutorial as this is just the first go at it.

Checklist

  • The issue that is being fixed is referred in the description (see above "Fixes #ISSUE_NUMBER")
  • Only one issue is addressed in this pull request
  • Labels from the issue that this PR is fixing are added to this pull request
  • No unnecessary issues are included into this pull request.

Copy link

pytorch-bot bot commented Jun 9, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3389

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 031ba22 with merge base 06f9c4b (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@github-actions github-actions bot added advanced docathon-h1-2025 A label for the docathon in H1 2025 hard hard label for docathon tutorial-proposal labels Jun 9, 2025
@sekyondaMeta
Copy link
Contributor

sekyondaMeta commented Jun 10, 2025

Generally seems to be headed in the right direction in terms of tone and organization from my perspective.
Can you add perquisite knowledge for this.

@sekyondaMeta sekyondaMeta requested review from svekars and albanD June 10, 2025 14:04
@svekars svekars requested a review from soulitzer June 10, 2025 17:19
Copy link
Contributor

@soulitzer soulitzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the working on this tutorial. Overall I'd say though that this section (prior to the actual visualizing gradients part) can be much shorter.

By the end of this tutorial, you will be able to:

Differentiate between leaf and non-leaf tensors

have a diagram from https://github.com/szagoruyko/pytorchviz, point to the leafs

Know when to use\ retain_grad vs. ``require_grad`

"use requires_grad for leaf, use retain_grad for non-leaf"

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

Successfully merging this pull request may close these issues.

Writing a gradient tutorial, focused on leaf vs non leaf tensors.
4 participants