Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. class Net(torch.nn.Module):
  2. def __init__(self):
  3. super(Net, self).__init__()
  4. self.l1 = torch.nn.Linear(1, 1)
  5. self.optimizer = torch.optim.Adadelta(self.parameters())
  6. self.loss_function = torch.nn.MSELoss()
  7.  
  8. def forward(self):
  9. return self.l1(torch.tensor([1], dtype=torch.float))
  10.  
  11. def backward(self, loss):
  12. self.optimizer.zero_grad()
  13. loss.backward()
  14. if not self.l1.weight.grad is None:
  15. #(*) changing the grad to 0
  16. self.l1.weight.grad[0] = torch.tensor([0], dtype=torch.float)
  17. self.optimizer.step()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement