19 lines
274 B
Python
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 |