code: def _construct_optimizer_from_config(
      module: Any, config: Union[str, Dict], model=None
  ):
      """
      construct from the config, the config can be class name as a `str`, or a dict containing the construct parameters.
      """
      instance = None
      if isinstance(config, str):
          construct_name = getattr(module, config)
          if model is not None:
              trainable_params = [
                  p for p in model.parameters() if p.requires_grad
              ]
              instance = construct_name(trainable_params)
      elif isinstance(config, Dict):
          optimizer_construct_name = config[NAME]
          construct_name = getattr(module, optimizer_construct_name)
          kwargs = {}
          for arg_name in config:
              if arg_name != NAME:
                  kwargs[arg_name] = config[arg_name]
          if model is not None:
              trainable_params = [
                  p for p in model.parameters() if p.requires_grad
              ]
              instance = construct_name(trainable_params, **kwargs)
      return instance
  
imports: import random
  from typing import NamedTuple, Any, Generator, Callable, Dict, Union
  from collections.abc import Mapping
  from enum import Enum
  import numpy
  import torch
  import os
  from pathlib import Path
  import torch.distributed
  from torch import nn
label_desc: Use image node_id 15 for calling a global function with example usage: _construct_optimizer_from_config(module, config, model) and returns: instance