Custom loss functions - PyTorch Forums
discuss.pytorch.org › t › custom-loss-functionsNov 12, 2018 · loss = torch.mean((output - target)**2) return loss model = nn.Linear(2, 2) x = torch.randn(1, 2) target = torch.randn(1, 2) output = model(x) loss = my_loss(output, target) loss.backward() print(model.weight.grad) 48 Likes From where does the backward() method come in custom loss functions Custom tweedie loss throwing an error in pytorch