PyTorch 2 · Autograd and models
Compute gradients
Track operations and compute derivatives with backpropagation.
w = torch.tensor(2.0, requires_grad=True)
loss = (w * 3 - 1) ** 2
loss.backward()
print(w.grad)
Official PyTorch 2 documentation
PyTorch 2 · Autograd and models
Track operations and compute derivatives with backpropagation.
w = torch.tensor(2.0, requires_grad=True)
loss = (w * 3 - 1) ** 2
loss.backward()
print(w.grad)
Official PyTorch 2 documentation
Was this page helpful?