code: def _clip_grad(clr, grad, group_grad_clip):
      if group_grad_clip > 0:
          norm = grad.norm(2).item()
          if norm > group_grad_clip:
              clr *= group_grad_clip / (norm + 1e-10)
      return clr
  
file_path: fairseq/examples/adaptive_span/adagrad_with_grad_clip.py
imports: from torch.optim import Adagrad
  from fairseq.optim import LegacyFairseqOptimizer, register_optimizer
label_desc: Use image node_id 1 for calling a global function with example usage: _clip_grad(clr, grad, group_grad_clip) and returns: clr