Files
pytorch_learn/04_backpropagation.py
Joseph Hopfmüller 34b6999e39 finished chapter 5
2022-10-17 00:27:39 +02:00

19 lines
274 B
Python

import torch
x = torch.tensor(1.0)
y = torch.tensor(2.0)
w = torch.tensor(1.0, requires_grad=True)
#forward path and compute loss
y_hat = w*x
loss = (y_hat-y)**2
print(loss)
#backward path
loss.backward()
print(w.grad)
### update weights
### next forward and backwards