Skip to content

Instantly share code, notes, and snippets.

@b0noI
Created October 31, 2021 00:34
Show Gist options
  • Save b0noI/36b84dadba6ba5838329b09b85cb423b to your computer and use it in GitHub Desktop.
Save b0noI/36b84dadba6ba5838329b09b85cb423b to your computer and use it in GitHub Desktop.
epoch = 100
for _ in range(epoch):
for i in range(len(X)):
x, y = torch.tensor(X[i]), torch.tensor(Y[i])
y_predict = model(x)
loss_tensor = loss(y_predict, y)
loss_tensor.backward()
loss_value = loss_tensor.data[0]
with torch.no_grad():
w -= w.grad * 1e-3
b -= b.grad * 1e-3
w.grad.zero_()
b.grad.zero_()
print(loss_value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment