コード例 #1
0
 def clip_gradients(self, grad_clip_val: Union[int, float], optimizer: Optimizer, norm_type: float):
     max_norm = grad_clip_val
     norm_type = float(2.0)
     optimizer = cast(OSS, optimizer)
     optimizer.clip_grad_norm(max_norm, norm_type=norm_type)
コード例 #2
0
 def clip_grad_by_norm(self,
                       optimizer: Optimizer,
                       clip_val: Union[int, float],
                       norm_type: float = 2.0) -> None:
     optimizer = cast(OSS, optimizer)
     optimizer.clip_grad_norm(clip_val, norm_type=norm_type)