def grad_clip_value(parameters: _tensor_or_tensors, clip_value: float) -> None:
    """
    **Overview**:
        Implementation of grad_clip_value <link https://pytorch.org/docs/stable/_modules/torch/nn/utils/clip_grad.html#clip_grad_value_ link>
        This function is used after the loss backpropagation, clip all the gradient of network parameters
        with a fixed range [-clip_value, clip_value].
        BTW, This function is a in-place operation, modify the gradient without any return value.
    """
    # Save the non-empty gradient of trainable parameters into a list.
    if isinstance(parameters, torch.Tensor):
        parameters = [parameters]
    grads = [p.grad for p in parameters if p.grad is not None]
    # Convert the original clip_value to float.
    clip_value = float(clip_value)
    # Clip the gradient to [-clip_value, clip_value] in-place.
    for grad in grads:
        grad.data.clamp_(min=-clip_value, max=clip_value)

    **Overview**:
        Implementation of grad_clip_value <link https://pytorch.org/docs/stable/_modules/torch/nn/utils/clip_grad.html#clip_grad_value_ link>
        This function is used after the loss backpropagation, clip all the gradient of network parameters
        with a fixed range [-clip_value, clip_value].
        BTW, This function is a in-place operation, modify the gradient without any return value.
    
chapter7_tricks/grad_clip_value.py