class_docstr: A base runner for training without training tricks.
  Applying training tricks such as ensemble of template or verbalizer,
  or self-training can use other runner class.
  This class is specially implemented for classification.
  For generation task, though it can be integrated in this class
  via `task` option, we keep it as another class for simplicity.
  
  Args:
      model (:obj:`nn.Module`): One ``nn.Module`` object.
      train_dataloader (:obj:`PromptDataloader`, optional): The dataloader to bachify and process the training data.
      valid_dataloader (:obj:`PromptDataloader`, optionla): The dataloader to bachify and process the val data.
      test_dataloader (:obj:`PromptDataloader`, optional): The dataloader to bachify and process the test data.
      config (:obj:`CfgNode`): A configuration object.
      loss_function (:obj:`Callable`, optional): The loss function in the training process.
docstr: config the optimizer and scheduler for
  
  1. model
  
  2. template
  
  3. verbalizer(optional)
docstr_tok: ["config","the","optimizer","and","scheduler","for","1.","model","2.","template","3.","verbalizer","(","optional",")"]
code: def configure_optimizers(self):
      r"""config the optimizer and scheduler for
  
      1. model
  
      2. template
  
      3. verbalizer(optional)
      """
  
      optimizers = []
      schedulers = []
  
      if not self.config.plm.optimize.freeze_para:
          no_decay = self.config.plm.optimize.no_decay
          weight_decay = self.config.plm.optimize.weight_decay
          optimizer_grouped_parameters = [
              {
                  "params": [
                      p
                      for n, p in self.inner_model.plm.named_parameters()
                      if not any(nd in n for nd in no_decay)
                  ],
                  "weight_decay": weight_decay,
              },
              {
                  "params": [
                      p
                      for n, p in self.inner_model.plm.named_parameters()
                      if any(nd in n for nd in no_decay)
                  ],
                  "weight_decay": 0.0,
              },
          ]
  
          plm_optimizer = AdamW(
              optimizer_grouped_parameters,
              lr=self.config.plm.optimize.lr,
              betas=self.config.plm.optimize.betas,
              eps=self.config.plm.optimize.eps,
          )
          optimizers.append(plm_optimizer)
          if self.config.plm.optimize.scheduler is not None:
              plm_scheduler = get_linear_schedule_with_warmup(
                  plm_optimizer,
                  num_warmup_steps=self.config.plm.optimize.scheduler.num_warmup_steps,
                  num_training_steps=self.num_training_steps,
              )
              schedulers.append(plm_scheduler)
  
      class Dummy:
          pass
  
      template_config = self.config[self.config.template]
      if (
          hasattr(template_config, "optimize")
          and template_config.optimize is not None
      ):  # TODO should add optimize config in each yaml
          if not hasattr(self.inner_model.template, "optimize"):
              # using default gradient descent optimizer.
              optimizer_grouped_parameters = [
                  {
                      "params": [
                          p
                          for name, p in self.inner_model.template.named_parameters()
                          if "raw_embedding" not in name
                      ]
                  }
              ]
              if template_config.optimize.name.lower() == "adamw":
                  template_optimizer = AdamW(
                      optimizer_grouped_parameters,
                      lr=template_config.optimize.lr,
                      eps=template_config.optimize.adam_epsilon,
                  )
                  optimizers.append(template_optimizer)
                  if (
                      hasattr(template_config.optimize, "scheduler")
                      and template_config.optimize.scheduler is not None
                  ):
                      template_scheduler = get_linear_schedule_with_warmup(
                          template_optimizer,
                          num_warmup_steps=template_config.optimize.scheduler.num_warmup_steps,
                          num_training_steps=self.num_training_steps,
                      )
                      schedulers.append(template_scheduler)
              elif template_config.optimize.name.lower() == "adafactor":
                  template_optimizer = Adafactor(
                      optimizer_grouped_parameters,
                      lr=template_config.optimize.lr,
                      weight_decay=1e-5,
                      relative_step=False,
                      scale_parameter=False,
                      warmup_init=False,
                  )
                  # template_scheduler = AdafactorSchedule(template_optimizer)
                  optimizers.append(template_optimizer)
                  # schedulers.append(template_scheduler)
              else:
                  raise NotImplementedError(
                      "Template Optimizer not Implemented!"
                  )
          else:
              template_optimizer = Dummy()
              # resemble a pytorch optimizer for unified training.
              setattr(
                  template_optimizer,
                  "step",
                  self.inner_model.template.optimize,
              )
              setattr(template_optimizer, "zero_grad", lambda: None)
              optimizers.append(template_optimizer)
  
      if (
          hasattr(self.inner_model, "verbalizer")
          and self.inner_model.verbalizer
      ):
          verbalizer_config = self.config[self.config.verbalizer]
          if (
              hasattr(verbalizer_config, "optimize")
              and verbalizer_config.optimize is not None
          ):
              if not hasattr(self.inner_model.verbalizer, "optimize"):
                  # using default gradient descent optimizer.
                  verbalizer_optimizer = AdamW(
                      self.inner_model.verbalizer.parameters(),
                      lr=verbalizer_config.optimize.lr,
                  )
                  optimizers.append(verbalizer_optimizer)
                  if (
                      hasattr(verbalizer_config.optimize, "scheduler")
                      and verbalizer_config.optimize.scheduler
                      is not None
                  ):
                      verbalizer_scheduler = get_linear_schedule_with_warmup(
                          verbalizer_optimizer,
                          num_warmup_steps=verbalizer_config.optimize.scheduler.num_warmup_steps,
                          num_training_steps=self.num_training_steps,
                      )
                      schedulers.append(verbalizer_scheduler)
              else:
                  verbalizer_optimizer = Dummy()
                  # resemble a pytorch optimizer for unified training.
                  setattr(
                      verbalizer_optimizer,
                      "step",
                      self.inner_model.verbalizer.optimize,
                  )
                  setattr(
                      verbalizer_optimizer, "zero_grad", lambda: None
                  )
                  optimizers.append(verbalizer_optimizer)
  
      self.optimizers = optimizers
      self.schedulers = schedulers
  
imports: import os, shutil
  import sys
  import torch
  from torch import nn
  from torch.nn.parallel.data_parallel import DataParallel
  from openprompt.utils.cuda import model_to_device
  from tensorboardX import SummaryWriter
  from tqdm import tqdm
  import dill
  import warnings
  from typing import Callable, Union, Dict
  from openprompt.pipeline_base import PromptForClassification, PromptForGeneration
  from openprompt import PromptDataLoader
  from openprompt.prompts import *
  from openprompt.utils.logging import logger
  from openprompt.utils.metrics import classification_metrics, generation_metric
  from transformers import AdamW, get_linear_schedule_with_warmup
  from transformers.optimization import Adafactor, AdafactorSchedule
label_desc: Use image node_id 8 for calling the BaseRunner obj's underlying member method code with example usage: obj.configure_optimizers() without return types