When I do that I no longer get the error, however when I…
print(model.weight.grad)

… it still prints None, so it doesn’t seem to be the solution.
I think the way I’m adding or computing the g1 and g2 value might still not be correct.