param.grad can now be None when it used to be zero. We made this change to better support sparse gradients.


When you share a model, the gradients are not shared. That means you don’t need to do param.grad.data = param.grad.data.clone() – it won’t do anything, and as you saw breaks when .grad is None.


So if you just remove the cloning your code should work fine.