Rate this Page

torch.nn.utils.get_total_norm#

torch.nn.utils.get_total_norm(tensors,norm_type=2.0,error_if_nonfinite=False,foreach=None)[source]#

Compute the norm of an iterable of tensors.

The norm is computed over the norms of the individual tensors, as if the norms ofthe individual tensors were concatenated into a single vector.

Parameters
  • tensors (Iterable[Tensor] orTensor) – an iterable of Tensors or asingle Tensor that will be normalized

  • norm_type (float) – type of the used p-norm. Can be'inf' forinfinity norm.

  • error_if_nonfinite (bool) – if True, an error is thrown if the totalnorm oftensors isnan,inf, or-inf.Default:False

  • foreach (bool) – use the faster foreach-based implementation.IfNone, use the foreach implementation for CUDA and CPU native tensors and silentlyfall back to the slow implementation for other device types.Default:None

Returns

Total norm of the tensors (viewed as a single vector).

Return type

Tensor