code: def _create_gradient_clipper(cfg):
      """
      Creates gradient clipping closure to clip by value or by norm,
      according to the provided config.
      """
      cfg = cfg.clone()
  
      def clip_grad_norm(p: _GradientClipperInput):
          torch.nn.utils.clip_grad_norm_(
              p, cfg.CLIP_VALUE, cfg.NORM_TYPE
          )
  
      def clip_grad_value(p: _GradientClipperInput):
          torch.nn.utils.clip_grad_value_(p, cfg.CLIP_VALUE)
  
      _GRADIENT_CLIP_TYPE_TO_CLIPPER = {
          GradientClipType.VALUE: clip_grad_value,
          GradientClipType.NORM: clip_grad_norm,
      }
      return _GRADIENT_CLIP_TYPE_TO_CLIPPER[
          GradientClipType(cfg.CLIP_TYPE)
      ]
  
file_path: gluon-cv/gluoncv/torch/utils/optimizer.py
imports: import math
  from enum import Enum
  import torch
  from torch.optim.optimizer import Optimizer
label_desc: Use image node_id 1 for calling a global function with example usage: _create_gradient_clipper(cfg) and returns: _GRADIENT_CLIP_TYPE_TO_CLIPPER