code: def validate_pytorch_optim(optim):
      import types
  
      if isinstance(optim, str):
          if optim in PYTORCH_OPTIM_NAMES:
              return getattr(torch.optim, optim)
          invalidInputError(
              False,
              f"Must provide a valid torch optimizer name among {PYTORCH_OPTIM_NAMES}",
          )
  
      if isinstance(optim, types.FunctionType):
          return optim
  
      invalidInputError(
          False,
          "Must provide a valid pytorch optimizer name "
          "or a pytorch optimizer creator function.",
      )
  
imports: import torch
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 2 for calling a global function with example usage: validate_pytorch_optim(optim) and returns: optim, getattr