(self, fp16_net, fp32_weights)
Copy gradients from fp16 model to fp32 weight copy.
Copy gradients from fp16 model to fp32 weight copy.
Copy gradients from fp16 model to fp32 weight copy .
def copy_grads_to_fp32(self, fp16_net, fp32_weights):
        """Copy gradients from fp16 model to fp32 weight copy."""
        for fp32_param, fp16_param in zip(fp32_weights, fp16_net.parameters()):
            if fp16_param.grad is not None:
                if fp32_param.grad is None:
                    fp32_param.grad = fp32_param.data.new(fp32_param.size())
                fp32_param.grad.copy_(fp16_param.grad)
def copy_grads_to_fp32 ( self , fp16_net , fp32_weights ) : for fp32_param , fp16_param in zip ( fp32_weights , fp16_net . parameters ( ) ) : if fp16_param . grad is not None : if fp32_param . grad is None : fp32_param . grad = fp32_param . data . new ( fp32_param . size ( ) ) fp32_param . grad . copy_ ( fp16_param . grad )