docstr: Setup the optimizer and the learning rate scheduler.
  
  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 :obj:`optimizers`, or subclass and override this method in a subclass.
docstr_tok: ["Setup","the","optimizer","and","the","learning","rate","scheduler",".","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",":","obj",":","`","optimizers","`",",","or","subclass","and","override","this","method","in","a","subclass","."]
code: def create_optimizer_and_scheduler(self, num_training_steps: int):
      """
      Setup the optimizer and the learning rate scheduler.
  
      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 :obj:`optimizers`, or subclass and override this method in a subclass.
      """
      if self.optimizer is None:
          no_decay = ["bias", "LayerNorm.weight"]
          optimizer_grouped_parameters = [
              {
                  "params": [
                      p
                      for n, p in self.model.named_parameters()
                      if not any(nd in n for nd in no_decay)
                  ],
                  "weight_decay": self.args.weight_decay,
              },
              {
                  "params": [
                      p
                      for n, p in self.model.named_parameters()
                      if any(nd in n for nd in no_decay)
                  ],
                  "weight_decay": 0.0,
              },
          ]
          optimizer_cls = Adafactor if self.args.adafactor else AdamW
          if self.args.adafactor:
              optimizer_cls = Adafactor
              optimizer_kwargs = {
                  "scale_parameter": False,
                  "relative_step": False,
              }
          else:
              optimizer_cls = AdamW
              optimizer_kwargs = {
                  "betas": (self.args.adam_beta1, self.args.adam_beta2),
                  "eps": self.args.adam_epsilon,
              }
          optimizer_kwargs["lr"] = self.args.learning_rate
          self.optimizer = optimizer_cls(
              optimizer_grouped_parameters, **optimizer_kwargs
          )
  
      if self.lr_scheduler is None:
          self.lr_scheduler = self._get_lr_scheduler(num_training_steps)
      else:  # ignoring --lr_scheduler
          logger.warning(
              "scheduler is passed to `Seq2SeqTrainer`, `--lr_scheduler` arg is ignored."
          )
  
file_path: transformers/examples/legacy/seq2seq/seq2seq_trainer.py
imports: from typing import Any, Dict, List, Optional, Tuple, Union
  import torch
  from torch import nn
  from torch.utils.data import DistributedSampler, RandomSampler
  from transformers import PreTrainedModel, Trainer, logging
  from transformers.models.fsmt.configuration_fsmt import FSMTConfig
  from transformers.optimization import Adafactor, AdamW, get_constant_schedule, get_constant_schedule_with_warmup, get_cosine_schedule_with_warmup, get_cosine_with_hard_restarts_schedule_with_warmup, get_linear_schedule_with_warmup, get_polynomial_decay_schedule_with_warmup
  from transformers.trainer_pt_utils import get_tpu_sampler
  from transformers.training_args import ParallelMode
  from transformers.utils import is_torch_tpu_available
label_desc: Use image node_id 2 for calling the Seq2SeqTrainer obj's underlying member method code with example usage: obj.create_optimizer_and_scheduler(num_training_steps) without return types