megengine.optimizer.clip_grad_norm#

clip_grad_norm(tensors, max_norm, ord=2.0)[源代码]#

通过限制范数最大值裁剪梯度。该范数将在所有梯度上一起计算,就好像梯度被拼接成一个向量。梯度修改将原地进行。

参数:
  • tensors (Union[Tensor, Iterable[Tensor]]) – an iterable of Tensors or a single Tensor.

  • max_norm (float) – 梯度的最大范数。

  • ord (float) – type of the used p-norm. Can be 'inf' for infinity norm.

返回:

total norm of the parameters (viewed as a single vector).