code: def _get_optim(model, opts):
      """Get the optimizer based on dictionary with options. Options are passed to the optimizer constructor.
  
      :param model: model to optimize
      :param opts: config dictionary that will be passed to optimizer together with the params
      (e.g. lr, weight_decay, correct_bias ...). no_decay' can be given - parameters containing any of those strings
      will have weight_decay set to 0.
      :return: created optimizer
      """
  
      optimizer_name = opts.pop("name", None)
  
      # Logging
      logger.info(f"Loading optimizer `{optimizer_name}`: '{opts}'")
      MlLogger.log_params(opts)
      MlLogger.log_params({"optimizer_name": optimizer_name})
  
      weight_decay = opts.pop("weight_decay", None)
      no_decay = opts.pop("no_decay", None)
  
      if no_decay:
          optimizable_parameters = [
              {
                  "params": [
                      p
                      for n, p in model.named_parameters()
                      if not any(nd in n for nd in no_decay)
                      and p.requires_grad
                  ],
                  **opts,
              },
              {
                  "params": [
                      p
                      for n, p in model.named_parameters()
                      if any(nd in n for nd in no_decay)
                      and p.requires_grad
                  ],
                  "weight_decay": 0.0,
                  **opts,
              },
          ]
      else:
          optimizable_parameters = [
              {
                  "params": [
                      p for p in model.parameters() if p.requires_grad
                  ],
                  **opts,
              }
          ]
  
      # default weight decay is not the same for all optimizers, so we can't use default value
      # only explicitly add weight decay if it's given
      if weight_decay is not None:
          optimizable_parameters[0]["weight_decay"] = weight_decay
  
      # Import optimizer by checking in order: torch, transformers, apex and local imports
      try:
          optim_constructor = getattr(
              import_module("torch.optim"), optimizer_name
          )
      except AttributeError:
          try:
              optim_constructor = getattr(
                  import_module("transformers.optimization"),
                  optimizer_name,
              )
          except AttributeError:
              try:
                  optim_constructor = getattr(
                      import_module("apex.optimizers"), optimizer_name
                  )
              except (AttributeError, ImportError):
                  try:
                      # Workaround to allow loading AdamW from transformers
                      # pytorch > 1.2 has now also a AdamW (but without the option to set bias_correction = False,
                      # which is done in the original BERT implementation)
                      optim_constructor = getattr(
                          sys.modules[__name__], optimizer_name
                      )
                  except (AttributeError, ImportError):
                      raise AttributeError(
                          f"Optimizer '{optimizer_name}' not found in 'torch', 'transformers', 'apex' or 'local imports"
                      )
  
      return optim_constructor(optimizable_parameters)
  
file_path: FARM/farm/modeling/optimization.py
imports: from importlib import import_module
  import logging
  import sys
  import inspect
  import torch
  from torch.nn.parallel import DistributedDataParallel
  from torch.nn import DataParallel
  from transformers.optimization import AdamW
  from farm.utils import MLFlowLogger
label_desc: Use image node_id 2 for calling a global function with example usage: _get_optim(model, opts) and returns: optim_constructor