code: def clip_grad_value_(parameters, clip_value, norm_type=2):
      if isinstance(parameters, torch.Tensor):
          parameters = [parameters]
      parameters = list(
          filter(lambda p: p.grad is not None, parameters)
      )
      norm_type = float(norm_type)
      if clip_value is not None:
          clip_value = float(clip_value)
  
      total_norm = 0
      for p in parameters:
          param_norm = p.grad.data.norm(norm_type)
          total_norm += param_norm.item() ** norm_type
          if clip_value is not None:
              p.grad.data.clamp_(min=-clip_value, max=clip_value)
      total_norm = total_norm ** (1.0 / norm_type)
      return total_norm
  
imports: import math
  import numpy
  import torch
  from torch import nn
  from torch.nn import functional
label_desc: Use image node_id 19 for calling a global function with example usage: clip_grad_value_(parameters, clip_value, norm_type) and returns: total_norm