
      i                     X    d Z ddlmZ ddlZddlmZ d
dedeeeef   dede	eef   fd	Z
y)z Utilities to describe gradients.    )UnionN)Modulemodule	norm_typegroup_separatorreturnc           	         t        |      }|dk  rt        d|       | j                         D ci c]?  \  }}|j                  .d| d| | |j                  j                  j                  |      A }}}|rDt        j                  t        |j                                     j                  |      }||d| d<   |S c c}}w )a  Compute each parameter's gradient's norm and their overall norm.

    The overall norm is computed over all gradients together, as if they
    were concatenated into a single vector.

    Args:
        module: :class:`torch.nn.Module` to inspect.
        norm_type: The type of the used p-norm, cast to float if necessary.
            Can be ``'inf'`` for infinity norm.
        group_separator: The separator string used by the logger to group
            the gradients norms in their own subfolder instead of the logs one.

    Return:
        norms: The dictionary of p-norms of each parameter's gradient and
            a special entry for the total p-norm of the gradients viewed
            as a single vector.

    r   zD`norm_type` must be a positive number or 'inf' (infinity norm). Got grad__norm_norm_total)
float
ValueErrornamed_parametersgraddatanormtorchtensorlistvalues)r   r   r   namepnorms
total_norms          v/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/lightning/pytorch/utilities/grads.py	grad_normr      s    & i IA~_`i_jkll ..00GD!66 	{%079I9I)9TT0 
 
 \\$u||~"67<<YG
0:i[,-Ls   AC)/)__doc__typingr   r   torch.nnr   r   intstrdictr        r   <module>r&      sM    '   f uc3)? RU `dehjoeo`p r%   