docstr: Setup the optimizer.
  
  We provide a reasonable default that works well. If you want to use something else, you can pass a tuple in the
  Trainer's init through `optimizers`, or subclass and override this method in a subclass.
docstr_tok: ["Setup","the","optimizer",".","We","provide","a","reasonable","default","that","works","well",".","If","you","want","to","use","something","else",",","you","can","pass","a","tuple","in","the","Trainer","'s","init","through","`","optimizers","`",",","or","subclass","and","override","this","method","in","a","subclass","."]
code: def create_optimizer(self):
      """
      Setup the optimizer.
  
      We provide a reasonable default that works well. If you want to use something else, you can pass a tuple in the
      Trainer's init through `optimizers`, or subclass and override this method in a subclass.
      """
      opt_model = (
          self.model_wrapped
          if is_sagemaker_mp_enabled()
          else self.model
      )
  
      if self.optimizer is None:
          decay_parameters = self.get_decay_parameter_names(opt_model)
          if hasattr(self.model, "config") and hasattr(
              self.model.config, "adapters"
          ):
              match_str = r"adapter_fusion_layer\..*\.value"
              decay_parameters = [
                  name
                  for name in decay_parameters
                  if not re.match(match_str, name)
              ]
          optimizer_grouped_parameters = [
              {
                  "params": [
                      p
                      for n, p in opt_model.named_parameters()
                      if (n in decay_parameters and p.requires_grad)
                  ],
                  "weight_decay": self.args.weight_decay,
              },
              {
                  "params": [
                      p
                      for n, p in opt_model.named_parameters()
                      if (n not in decay_parameters and p.requires_grad)
                  ],
                  "weight_decay": 0.0,
              },
          ]
  
          (
              optimizer_cls,
              optimizer_kwargs,
          ) = Trainer.get_optimizer_cls_and_kwargs(self.args)
          self.optimizer = optimizer_cls(
              optimizer_grouped_parameters, **optimizer_kwargs
          )
  
      if is_sagemaker_mp_enabled():
          self.optimizer = smp.DistributedOptimizer(self.optimizer)
  
      return self.optimizer
  
imports: import os
  import re
  from typing import Callable, Dict, List, Optional, Tuple, Union
  import torch
  from torch import nn
  from torch.utils.data.dataset import Dataset
  from transformers import PreTrainedModel, Seq2SeqTrainer, Trainer, __version__
  from transformers.configuration_utils import PretrainedConfig
  from transformers.data.data_collator import DataCollator
  from transformers.modeling_utils import unwrap_model
  from transformers.tokenization_utils_base import PreTrainedTokenizerBase
  from transformers.trainer_callback import TrainerCallback, TrainerControl, TrainerState
  from transformers.trainer_utils import EvalPrediction
  from transformers.training_args import TrainingArguments
  from transformers.utils import CONFIG_NAME, WEIGHTS_NAME, is_sagemaker_mp_enabled, logging
  from .composition import AdapterCompositionBlock, Fuse
label_desc: Use image node_id 2 for calling the AdapterTrainer obj's underlying member method code with example usage: obj.create_optimizer() and returns: self