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

Update tensors and autograd #1185

Merged
merged 17 commits into from
Dec 30, 2020
Prev Previous commit
Next Next commit
Fix typo
  • Loading branch information
subramen committed Oct 20, 2020
commit 6d91b988d5d8c1d076f0cd500f9aff50f1e275e9
2 changes: 1 addition & 1 deletion beginner_source/blitz/autograd_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
model = torchvision.models.resnet18(pretrained=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need a bit more text explanation here - either in text or in code comments.

very roughly something like:
"Let's start by looking at the a single training step. Here we load an existing pretrained resnet18 model, create random input data tensor of shape 3x64x64, and some random output labels."

...

Then we might want to pause again and say "here we push the data forward through the model, calculate the loss, and then call .backward() to collect the gradients for each parameter in the model. <more detail here on what backward does (i.e. where are the gradients stored?>

....

Then we say: "Finally we load in an optimizer, in this case SGD, with a learning rate and momentum of ..., and call .step() to use our gradients and step backwards"

That's a basic model, below we dive a bit deeper into what is going on when we call .backward()

Copy link
Member

Choose a reason for hiding this comment

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

I agree with Randall here

data = torch.rand(1, 3, 64, 64)
labels = torch.rand(1, 1000)
prediction = model(x) # forward pass
prediction = model(data) # forward pass
loss = prediction - labels
loss.backward() # backward pass

Expand Down