Two notes for now: (these probably won’t fix your problem, but it’s probably worth a shot…)

You should probably move the initialization of the optimizer outside of your training loop. This is because optimizers can store state.
If loss.backward() results in None losses, I can think of two things,


model.parameters() aren’t leaf nodes in the computation graph (Variables that don’t come from operations on variables)
The loss doesn’t need model.parameters().