code: def _generate_optimizer_class_with_gradient_clipping(
      optimizer_type, gradient_clipper
  ):
      """
      Dynamically creates a new type that inherits the type of a given instance
      and overrides the `step` method to add gradient clipping
      """
  
      def optimizer_wgc_step(self, closure=None):
          for group in self.param_groups:
              for p in group["params"]:
                  gradient_clipper(p)
          super(type(self), self).step(closure)
  
      OptimizerWithGradientClip = type(
          optimizer_type.__name__ + "WithGradientClip",
          (optimizer_type,),
          {"step": optimizer_wgc_step},
      )
      return OptimizerWithGradientClip
  
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 2 for calling a global function with example usage: _generate_optimizer_class_with_gradient_clipping(optimizer_type, gradient_clipper) and returns: OptimizerWithGradientClip