code: def __init__(self, model_name_or_path, config, args):
      super().__init__()
      self.t5 = T5ForConditionalGeneration.from_pretrained(
          model_name_or_path, config=config
      )
      self.config = self.t5.config
      self.args = args
  
      # model config related
      self.match_n_layer = self.config.num_decoder_layers
      self.match_n_head = self.config.num_heads
      self.n_embd = self.config.d_model
      self.match_n_embd = self.config.d_kv
  
      # prefix related
      self.prompt_len = args.prompt_len
      self.prompt_dim = args.prompt_dim
      self.prompt_inputs = torch.arange(
          self.prompt_len
      ).long()  # [0, 1, ..., prompt_len-1]
  
      self.wte = nn.Embedding(self.prompt_len, self.n_embd)
      self.control_trans = nn.Sequential(
          nn.Linear(self.n_embd, self.prompt_dim),
          nn.Tanh(),
          nn.Linear(
              self.prompt_dim,
              self.match_n_layer
              * 2
              * self.match_n_head
              * self.match_n_embd,
          ),
      )
  
      self.wte_enc = nn.Embedding(self.prompt_len, self.n_embd)
      self.control_trans_enc = nn.Sequential(
          nn.Linear(self.n_embd, self.prompt_dim),
          nn.Tanh(),
          nn.Linear(
              self.prompt_dim,
              self.match_n_layer
              * 2
              * self.match_n_head
              * self.match_n_embd,
          ),
      )
  
      self.wte_dec = nn.Embedding(self.prompt_len, self.n_embd)
      self.control_trans_dec = nn.Sequential(
          nn.Linear(self.n_embd, self.prompt_dim),
          nn.Tanh(),
          nn.Linear(
              self.prompt_dim,
              self.match_n_layer
              * 2
              * self.match_n_head
              * self.match_n_embd,
          ),
      )
  
      self.dropout = nn.Dropout(0.1)
  
      if (
          args.source_prefix_path is not None
          and "concat" in args.prefix_fusion_way
      ):
          self.source_prompt_inputs = torch.arange(
              self.prompt_len
          ).long()  # [0, 1, ..., prompt_len-1]
          self.source_wte = nn.Embedding(self.prompt_len, self.n_embd)
          self.source_control_trans = nn.Sequential(
              nn.Linear(self.n_embd, self.prompt_dim),
              nn.Tanh(),
              nn.Linear(
                  self.prompt_dim,
                  self.match_n_layer
                  * 2
                  * self.match_n_head
                  * self.match_n_embd,
              ),
          )
  
          self.source_wte_enc = nn.Embedding(
              self.prompt_len, self.n_embd
          )
          self.source_control_trans_enc = nn.Sequential(
              nn.Linear(self.n_embd, self.prompt_dim),
              nn.Tanh(),
              nn.Linear(
                  self.prompt_dim,
                  self.match_n_layer
                  * 2
                  * self.match_n_head
                  * self.match_n_embd,
              ),
          )
  
          self.source_wte_dec = nn.Embedding(
              self.prompt_len, self.n_embd
          )
          self.source_control_trans_dec = nn.Sequential(
              nn.Linear(self.n_embd, self.prompt_dim),
              nn.Tanh(),
              nn.Linear(
                  self.prompt_dim,
                  self.match_n_layer
                  * 2
                  * self.match_n_head
                  * self.match_n_embd,
              ),
          )
  
      if args.multi_source_path:
          # module
          self.prefix_project_layer = nn.Sequential(
              nn.Linear(self.n_embd, 500),
              nn.Tanh(),
              nn.Linear(500, self.n_embd),
          )
  
      if "lstm" in args.prefix_fusion_way:
          self.lstm = nn.LSTM(
              input_size=self.match_n_head * self.match_n_embd,
              hidden_size=self.match_n_head * self.match_n_embd,
              num_layers=2,
              batch_first=True,
              bidirectional=True,
          )
  
      if args.freeze_plm:
          for name, param in self.t5.named_parameters():
              if (
                  "encoder" in name
                  or "decoder" in name
                  and "adapter" not in name
              ):
                  param.requires_grad = False
  
      if args.freeze_prefix:
          for name, param in self.named_parameters():
              if "wte" in name or "control_trans" in name:
                  param.requires_grad = False
  
file_path: DeepKE/src/deepke/name_entity_re/cross/seq2seq/models.py
imports: import os
  from copy import deepcopy
  import torch
  from torch import nn
  from .modeling_t5 import T5ForConditionalGeneration
label_desc: Use image node_id 1 to create a new T5Prompt object from inherited base classes: nn with example: obj = T5Prompt(model_name_or_path, config, args)