-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add the Latest Features For Basics Autograd Tutorial #3395
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
ParagEkbote
wants to merge
11
commits into
pytorch:main
Choose a base branch
from
ParagEkbote:Add-Latest-Features-For-Autograd-Tutorial
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d37a7fb
update.
ParagEkbote ad5eb25
update the autograd tutorial.
ParagEkbote 1532c0d
update the tutorial.
ParagEkbote 4feed23
Merge branch 'main' into Add-Latest-Features-For-Autograd-Tutorial
ParagEkbote f9351d4
Merge branch 'main' into Add-Latest-Features-For-Autograd-Tutorial
ParagEkbote 7609948
Merge branch 'main' into Add-Latest-Features-For-Autograd-Tutorial
ParagEkbote 141aa18
Merge branch 'main' into Add-Latest-Features-For-Autograd-Tutorial
ParagEkbote 4fca41c
Merge branch 'main' into Add-Latest-Features-For-Autograd-Tutorial
ParagEkbote c11b361
update the tutorial.
ParagEkbote 86cf702
update.
ParagEkbote 00b4978
Merge branch 'main' into Add-Latest-Features-For-Autograd-Tutorial
ParagEkbote File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
y = torch.zeros(3) # expected output | ||
w = torch.randn(5, 3, requires_grad=True) | ||
b = torch.randn(3, requires_grad=True) | ||
z = torch.matmul(x, w)+b | ||
z = torch.matmul(x, w) + b | ||
loss = torch.nn.functional.binary_cross_entropy_with_logits(z, y) | ||
|
||
|
||
|
@@ -133,7 +133,8 @@ | |
# - To mark some parameters in your neural network as **frozen parameters**. | ||
# - To **speed up computations** when you are only doing forward pass, because computations on tensors that do | ||
# not track gradients would be more efficient. | ||
|
||
# For additional reference, you can view the autograd mechanics | ||
# documentation:https://docs.pytorch.org/docs/stable/notes/autograd.html#locally-disabling-gradient-computation | ||
|
||
###################################################################### | ||
|
||
|
@@ -160,6 +161,39 @@ | |
# - accumulates them in the respective tensor’s ``.grad`` attribute | ||
# - using the chain rule, propagates all the way to the leaf tensors. | ||
# | ||
# We can also visualize the computational graph by the following 2 methods: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for this section, we can just keep it short for now, and link to the relevant resource:
(for the links use the proper hyperlink syntax) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
# | ||
# 1. TORCH_LOGS="+autograd" | ||
# By setting the TORCH_LOGS="+autograd" environment variable, we can enable runtime autograd logs for debugging. | ||
# | ||
# We can perform the logging in the following manner: | ||
# TORCH_LOGS="+autograd" python test.py | ||
# | ||
# 2. Torchviz | ||
# Torchviz is a package to render the computational graph visually. | ||
# | ||
# We can generate an image for the computational graph in the example given below: | ||
# | ||
# import torch | ||
# from torch import nn | ||
# from torchviz import make_dot | ||
# | ||
# model = nn.Sequential( | ||
# nn.Linear(8, 16), | ||
# nn.ReLU(), | ||
# nn.Linear(16, 1) | ||
# ) | ||
|
||
# x = torch.randn(1, 8, requires_grad=True) | ||
# y = model(x).mean() | ||
|
||
# log the internal operations using torchviz | ||
# import os | ||
# os.environ['TORCH_LOGS'] = "+autograd" | ||
|
||
# dot = make_dot(y, params=dict(model.named_parameters()), show_attrs=True, show_saved=True) | ||
# dot.render('simple_graph', format='png') | ||
# | ||
# .. note:: | ||
# **DAGs are dynamic in PyTorch** | ||
# An important thing to note is that the graph is recreated from scratch; after each | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.