Solution Review: Finding Gradient
Learn how we can calculate gradients after setting up a computation graph.
Solution
Press + to interact
import torch# set up simple graph relating x, y and za = torch.tensor(3.0, requires_grad=True)b = torch.tensor(2.0, requires_grad=True)x = 3*a + 3*by = 6*a*a + 5*b*b*bz = 3*x + 3*y# work out gradientsz.backward()# what is gradient at a = 3.0print(a.grad)# what is gradient at b = 2.0print(b.grad)
Explanation
-
Line 11 calculates the gradient ...
Get hands-on with 1400+ tech skills courses.