def METHOD_NAME(self, grad, max_norm):
    """
    in-place gradient clipping.
    :param grad: list of gradients
    :param max_norm: maximum norm allowable
    :return:
    """
    total_norm = 0
    counter = 0
    for g in grad:
        param_norm = g.data.norm(2)
        total_norm += param_norm.item() ** 2
        counter += 1
    total_norm = total_norm ** (1. / 2)
    clip_coef = max_norm / (total_norm + 1e-6)
    if clip_coef < 1:
        for g in grad:
            g.data.mul_(clip_coef)
    return total_norm/counter