o
    #j                     @   s"   d dl Z g Ze j dd ZdS )    Nc                 C   s\   t  stdt| t jr| g} t|}t| D ]\}}|jdur+|jj| |d qdS )aV  
    Clips gradient of an iterable of parameters at specified value.
    The gradient will be modified in place.
    This API can only run in dynamic graph mode, not static graph mode.

    Args:
        parameters (Iterable[paddle.Tensor]|paddle.Tensor): Tensors or a single Tensor
            that will be normalized gradients
        clip_value (float|int): maximum allowed value of the gradients.
            The gradients are clipped in the range
            :math:`\left[\text{-clip\_value}, \text{clip\_value}\right]`

    Example:
        .. code-block:: python

            >>> import paddle
            >>> x = paddle.uniform([10, 10], min=-10.0, max=10.0, dtype='float32')
            >>> clip_value = float(5.0)
            >>> linear = paddle.nn.Linear(in_features=10, out_features=10)
            >>> out = linear(x)
            >>> loss = paddle.mean(out)
            >>> loss.backward()
            >>> paddle.nn.utils.clip_grad_value_(linear.parameters(), clip_value)
            >>> sdg = paddle.optimizer.SGD(learning_rate=0.1, parameters=linear.parameters())
            >>> sdg.step()
    z&this API can only run in dynamic mode.N)minmax)	paddleZin_dynamic_modeRuntimeError
isinstanceZTensorfloat	enumerateZgradZclip_)
parametersZ
clip_value_p r   a/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/nn/utils/clip_grad_value_.pyclip_grad_value_   s   
r   )r   __all__ZautogradZno_gradr   r   r   r   r   <module>   s   