(parameters, clip_val)
r"""Clips gradient norm of an iterable of parameters.
    The norm is computed over all gradients together, as if they were
    concatenated into a single vector. Gradients are modified in-place.
    Arguments:
        parameters (Iterable[Variable]): an iterable of Variables that will have
            gradients normalized
        max_norm (float or int): max norm of the gradients
        norm_type (float or int): type of the used p-norm. Can be ``'inf'`` for
            infinity norm.
    Returns:
        Total norm of the parameters (viewed as a single vector).
r"""Clips gradient norm of an iterable of parameters.
    The norm is computed over all gradients together, as if they were
    concatenated into a single vector. Gradients are modified in-place.
    Arguments:
        parameters (Iterable[Variable]): an iterable of Variables that will have
            gradients normalized
        max_norm (float or int): max norm of the gradients
        norm_type (float or int): type of the used p-norm. Can be ``'inf'`` for
            infinity norm.
    Returns:
        Total norm of the parameters (viewed as a single vector).
r Clips gradient norm of an iterable of parameters . The norm is computed over all gradients together as if they were concatenated into a single vector . Gradients are modified in - place . Arguments : parameters ( Iterable [ Variable ] ) : an iterable of Variables that will have gradients normalized max_norm ( float or int ) : max norm of the gradients norm_type ( float or int ) : type of the used p - norm . Can be inf for infinity norm . Returns : Total norm of the parameters ( viewed as a single vector ) .
def clip_grad(parameters, clip_val):
    r"""Clips gradient norm of an iterable of parameters.
    The norm is computed over all gradients together, as if they were
    concatenated into a single vector. Gradients are modified in-place.
    Arguments:
        parameters (Iterable[Variable]): an iterable of Variables that will have
            gradients normalized
        max_norm (float or int): max norm of the gradients
        norm_type (float or int): type of the used p-norm. Can be ``'inf'`` for
            infinity norm.
    Returns:
        Total norm of the parameters (viewed as a single vector).
    """
    parameters = list(filter(lambda p: p.grad is not None, parameters))
    for p in parameters:
        p.grad.data.clamp_(-clip_val, clip_val)
def clip_grad ( parameters , clip_val ) : parameters = list ( filter ( lambda p : p . grad is not None , parameters ) ) for p in parameters : p . grad . data . clamp_ ( - clip_val , clip_val )