torch.nn.utils.get_total_norm
function get_total_norm(tensors: Iterable<Tensor>, options?: GetTotalNormOptions): Tensorfunction get_total_norm(tensors: Iterable<Tensor>, norm_type: number | 'inf', options?: GetTotalNormOptions): TensorCompute the norm of an iterable of tensors.
The norm is computed over all tensors together, as if they were concatenated into a single vector.
Parameters
tensorsIterable<Tensor>- Iterable of tensors
optionsGetTotalNormOptionsoptional- Optional settings for norm calculation: -
norm_type: Type of the used p-norm. Can be 'inf' for infinity norm (default: 2.0).
Returns
Tensor– Total norm of the tensors (as a scalar Tensor)Examples
const total = torch.nn.utils.get_total_norm(model.parameters(), { norm_type: 2.0 });
console.log(await total.item()); // L2 norm of all parameters