Same code works on “cpu”, but on “cuda”, it has following error:

TypeError                                 Traceback (most recent call last)
 in 
16         loss.backward()
17         with torch.no_grad():
—> 18             weights -= weights.grad * lr
19             bias -= bias.grad * lr
20             weights.grad.zero_()
TypeError: unsupported operand type(s) for *: ‘NoneType’ and ‘float’