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