code: def build_default_optimizer(
      model: torch.nn.Module, optimizer_kwargs: hf_parse.OptimizerKwargs
  ) -> Union[hf_opt.Adafactor, hf_opt.AdamW]:
      """
      This follows the function in transformer's Trainer to construct the optimizer.
  
      Args:
          model: model whose parameters will be updated by the optimizer
          weight_decay: weight_decay factor to apply to weights
          optimizer_kwargs: see OptimizerKwargs in _config_parser.py for expected fields
      Returns:
          optimizer configured accordingly
      """
      optimizer_grouped_parameters = group_parameters_for_optimizer(
          model, optimizer_kwargs.weight_decay
      )
      if optimizer_kwargs.adafactor:
          return hf_opt.Adafactor(
              optimizer_grouped_parameters,
              lr=optimizer_kwargs.learning_rate,
              scale_parameter=optimizer_kwargs.scale_parameter,
              relative_step=optimizer_kwargs.relative_step,
          )
      return hf_opt.AdamW(
          optimizer_grouped_parameters,
          lr=optimizer_kwargs.learning_rate,
          betas=(
              optimizer_kwargs.adam_beta1,
              optimizer_kwargs.adam_beta2,
          ),
          eps=optimizer_kwargs.adam_epsilon,
      )
  
file_path: determined/model_hub/model_hub/huggingface/_trial.py
imports: import dataclasses
  import logging
  from typing import Any, Dict, List, Optional, Tuple, Union, cast
  import datasets
  import torch
  import transformers
  import transformers.optimization
  import determined.pytorch
  from model_hub import utils
  from model_hub.huggingface import _config_parser
label_desc: Use image node_id 3 for calling a global function with example usage: build_default_optimizer(model, optimizer_kwargs) and returns: hf_opt, hf_opt