def calc_sample_norms(named_params: Iterator[Tuple[(str, torch.Tensor)]], flat: bool=True) -> List[torch.Tensor]:
    '\n    Calculates the norm of the given tensors for each sample.\n\n    This function calculates the overall norm of the given tensors for each sample,\n    assuming the each batch\'s dim is zero.\n\n    Args:\n        named_params: An iterator of tuples <name, param> with name being a\n            string and param being a tensor of shape ``[B, ...]`` where ``B``\n            is the size of the batch and is the 0th dimension.\n        flat: A flag, when set to `True` returns a flat norm over all\n            layers norms\n\n    Example:\n        >>> t1 = torch.rand((2, 5))\n        >>> t2 = torch.rand((2, 5))\n        >>> calc_sample_norms([("1", t1), ("2", t2)])\n            [tensor([1.5117, 1.0618])]\n\n    Returns:\n        A list of tensor norms where length of the list is the number of layers\n    '
    norms = [param.view(len(param), (- 1)).norm(2, dim=(- 1)) for (name, param) in named_params]
    if flat:
        norms = [torch.stack(norms, dim=0).norm(2, dim=0)]
    return norms
Calculates the norm of the given tensors for each sample.

This function calculates the overall norm of the given tensors for each sample,
assuming the each batch's dim is zero.

Args:
    named_params: An iterator of tuples <name, param> with name being a
        string and param being a tensor of shape ``[B, ...]`` where ``B``
        is the size of the batch and is the 0th dimension.
    flat: A flag, when set to `True` returns a flat norm over all
        layers norms

Example:
    >>> t1 = torch.rand((2, 5))
    >>> t2 = torch.rand((2, 5))
    >>> calc_sample_norms([("1", t1), ("2", t2)])
        [tensor([1.5117, 1.0618])]

Returns:
    A list of tensor norms where length of the list is the number of layers
def calc_sample_norms(named_params: Iterator[Tuple[(str, torch.Tensor)]], flat: bool=True) -> List[torch.Tensor]:
    '\n    Calculates the norm of the given tensors for each sample.\n\n    This function calculates the overall norm of the given tensors for each sample,\n    assuming the each batch\'s dim is zero.\n\n    Args:\n        named_params: An iterator of tuples <name, param> with name being a\n            string and param being a tensor of shape ``[B, ...]`` where ``B``\n            is the size of the batch and is the 0th dimension.\n        flat: A flag, when set to `True` returns a flat norm over all\n            layers norms\n\n    Example:\n        >>> t1 = torch.rand((2, 5))\n        >>> t2 = torch.rand((2, 5))\n        >>> calc_sample_norms([("1", t1), ("2", t2)])\n            [tensor([1.5117, 1.0618])]\n\n    Returns:\n        A list of tensor norms where length of the list is the number of layers\n    '
    norms = [param.view(len(param), (- 1)).norm(2, dim=(- 1)) for (name, param) in named_params]
    if flat:
        norms = [torch.stack(norms, dim=0).norm(2, dim=0)]
    return norms