code: def __init__(self, config, tokenizer):
      super().__init__(config, tokenizer)
      model_path = config["model_path"]
      load_type = config["load_type"]
  
      # loading config
      config_path = config["config_path"] or model_path or None
      config_kwargs = config["config_kwargs"] or {}
      if config_path is None:
          # No pretrained config. loading config from yaml
          model_type = config["model_type"]
          _name_or_path = config["_name_or_path"]
          params_list = list(
              inspect.signature(
                  AutoConfig.for_model(model_type).__init__
              ).parameters.keys()
          )
          config_dict = {
              key: val
              for key, val in config.final_config_dict.items()
              if key in params_list
          }
          config_dict["model_type"] = model_type
          config_dict["_name_or_path"] = _name_or_path
          self.configuration = AutoConfig.for_model(**config_dict)
      else:
          # loading config from config_path
          if self.model_name == "unilm":
              config_kwargs["label_smoothing"] = self.label_smoothing
              self.label_smoothing = 0
          self.configuration = AutoConfig.from_pretrained(
              config_path, **config_kwargs
          )
      if config["efficient_methods"]:
          hard_efficient_methods = [
              m
              for m in [
                  "prefix-tuning",
                  "p-tuning-v2",
                  "adapter",
                  "lora",
              ]
              if m in config["efficient_methods"]
          ]
          if hard_efficient_methods and self.model_name not in [
              "bart",
              "gpt2",
              "t5",
          ]:
              raise NotImplementedError(
                  f"{self.model_name} does not currently support {hard_efficient_methods} method."
              )
          self.configuration.efficient_methods = config[
              "efficient_methods"
          ]
          efficient_kwargs = {}
          for method in config["efficient_methods"]:
              efficient_kwargs.update(efficient_kwargs_dict[method])
          if config["efficient_kwargs"]:
              efficient_kwargs.update(config["efficient_kwargs"])
          self.configuration.update(efficient_kwargs)
  
      self._init_params()
  
      # loading model
      model_class = None
      if self.model_name in ["bert2bert", "xlm-roberta", "xlm"]:
          model_class = EncoderDecoderModel
      if self.model_name == "cpt":
          from transformers.models.cpt import (
              CPTForConditionalGeneration,
          )
  
          model_class = CPTForConditionalGeneration
      elif self.is_casual_model:
          model_class = AutoModelForCausalLM
          self.configuration.is_decoder = True
      else:
          model_class = AutoModelForSeq2SeqLM
  
      if load_type == "from_pretrained":
          if self.model_name in ["bert2bert", "xlm-roberta", "xlm"]:
              self.model = (
                  EncoderDecoderModel.from_encoder_decoder_pretrained(
                      model_path, model_path, config=self.configuration
                  )
              )
          else:
              self.model = model_class.from_pretrained(
                  model_path, config=self.configuration
              )
      else:
          if hasattr(model_class, "from_config"):
              self.model = model_class.from_config(self.configuration)
          else:
              self.model = model_class(self.configuration)
  
      if load_type == "from_scratch":
          warnings.warn(f"Initialize {self.model_name} from scratch")
  
      if self.model_name == "unilm":
          (
              mask_word_id,
              eos_word_ids,
              sos_word_id,
          ) = tokenizer.convert_tokens_to_ids(
              ["[MASK]", "[SEP]", "[S2S_SOS]"]
          )
          self.model.additional_init(
              mask_word_id, eos_word_ids, sos_word_id
          )
  
      if self.model_name in ["bert2bert", "xlm-roberta", "xlm"]:
          self.model.config.decoder_start_token_id = (
              self.tokenizer.cls_token_id
          )
          self.model.config.pad_token_id = self.tokenizer.pad_token_id
  
      if self.model_name not in [
          "bert2bert",
          "unilm",
          "xlm-roberta",
          "xlm",
      ]:
          self.model.resize_token_embeddings(len(self.tokenizer))
  
      if self.is_prompt_tuning:
          self.prompt_length = self.model.config.prompt_length
          self.prompt_embedding = nn.Embedding(
              self.prompt_length, self.model.config.hidden_size
          )
  
      if config["lightweight_tuning"]:
          self.model.set_lightweight_tuning()
  
      if (
          config["efficient_methods"]
          and not config["efficient_unfreeze_model"]
      ):
          if hard_efficient_methods:
              self.model.set_efficient_tuning()
          elif "bitfit" in config["efficient_methods"]:
              for para in self.model.parameters():
                  if len(para.shape) > 1:
                      para.requires_grad_(False)
          elif "prompt-tuning" in config["efficient_methods"]:
              self.model.requires_grad_(False)
      self.generate_setting(config)
  
file_path: TextBox/textbox/model/pretrained_models.py
imports: import os
  import copy
  import torch
  import torch.nn
  import warnings
  import inspect
  from .abstract_model import AbstractModel
  from transformers import AutoConfig, AutoModelForCausalLM, AutoModelForSeq2SeqLM, EncoderDecoderModel
  from transformers.models.encoder_decoder.configuration_encoder_decoder import EncoderDecoderConfig
  from ..utils.argument_list import efficient_kwargs_dict
label_desc: Use image node_id 1 to create a new Pretrained_Models object from inherited base classes: AbstractModel with example: obj = Pretrained_Models(config, tokenizer)