def METHOD_NAME(tensors, device, max_norm=1.0, norm_type=2.):
    total_norm = torch.norm(torch.stack(
        [torch.norm(p.detach(), norm_type).to(device) for p in tensors]), norm_type)
    clip_coef = max_norm / (total_norm + 1e-6)
    clip_coef_clamped = torch.clamp(clip_coef, max=1.0)
    for p in tensors:
        p.mul_(clip_coef_clamped.to(p.device))
    return total_norm