code: def forward(
      self,
      input_ids=None,
      attention_mask=None,
      labels=None,
      decoder_input_ids=None,
      return_dict=True,
  ):
      bsz = input_ids.shape[0]
      past_prompt = self.get_prompt(bsz=bsz)
  
      if self.args.multi_source_path:
          # 1. compute cosine similarity between target prefix and source prefixes
          trans_source_prefixes = self.prefix_project_layer(
              self.trans_source_prefixes.detach().to(input_ids.device)
          )  # project
  
          trans_target_prefix = self.convert_prefix(
              self.get_prompt(bsz=1)
          )
          trans_target_prefix = (
              self.prefix_project_layer(trans_target_prefix)
              .detach()
              .unsqueeze(0)
          )
  
          prefix_sim = torch.cosine_similarity(
              trans_target_prefix.to(input_ids.device),
              trans_source_prefixes.to(input_ids.device),
          )  # n
          prefix_sim = prefix_sim / prefix_sim.sum()
  
          # 2. compute cosine similarity between target label word and source label words
          target_label_word = []
          for label_id in self.label_word_id:
              if len(label_id) > 1:
                  target_label_word.append(
                      torch.stack(
                          [
                              self.t5.shared.weight.data[id]
                              for id in label_id
                          ],
                          dim=0,
                      ).mean(0)
                  )
              else:
                  target_label_word.append(
                      self.t5.shared.weight.data[label_id[0]]
                  )
          target_label_word = (
              torch.stack(target_label_word, dim=0)
              .mean(0)
              .to(input_ids.device)
          )
          label_word_sim = torch.cosine_similarity(
              target_label_word.unsqueeze(0),
              self.source_label_words.to(input_ids.device),
          )
          label_word_sim = label_word_sim / label_word_sim.sum()
  
          total_sim = (prefix_sim + label_word_sim) / 2
  
          # aggregate
          for i, prefix in enumerate(past_prompt):  # 24
              for (
                  key
              ) in (
                  prefix.keys()
              ):  # 'decoder_prompt', 'cross_attention_prompt', 'encoder_prompt'
                  for sub_key in prefix[
                      key
                  ].keys():  # prev_key', 'prev_value', 'prev_key_padding_mask'
                      if len(prefix[key][sub_key].size()) == 4:
                          agg_prefix = torch.zeros(
                              (
                                  1,
                                  self.match_n_head,
                                  self.prompt_len,
                                  self.match_n_embd,
                              ),
                              device=input_ids.device,
                          )
                          for j in range(len(self.source_prefixes)):
                              agg_prefix += (
                                  self.source_prefixes[j][i][key][
                                      sub_key
                                  ].to(input_ids.device)
                                  * total_sim[j]
                              )
                          past_prompt[i][key][sub_key] = (
                              past_prompt[i][key][sub_key] + agg_prefix
                          ) / 2
  
      if "concat" in self.args.prefix_fusion_way:
          source_past_prompt = self.get_source_prompt(bsz=bsz)
          for i, prefix in enumerate(past_prompt):  # 24
              for (
                  key
              ) in (
                  prefix.keys()
              ):  # 'decoder_prompt', 'cross_attention_prompt', 'encoder_prompt'
                  for sub_key in prefix[
                      key
                  ].keys():  # prev_key', 'prev_value', 'prev_key_padding_mask'
                      if len(prefix[key][sub_key].size()) == 4:
                          past_prompt[i][key][sub_key] = torch.cat(
                              (
                                  past_prompt[i][key][sub_key],
                                  source_past_prompt[i][key][sub_key],
                              ),
                              dim=2,
                          )
                      elif len(prefix[key][sub_key].size()) == 2:
                          past_prompt[i][key][sub_key] = torch.cat(
                              (
                                  past_prompt[i][key][sub_key],
                                  source_past_prompt[i][key][sub_key],
                              ),
                              dim=1,
                          )
  
      if "lstm" in self.args.prefix_fusion_way:
          for i, prefix in enumerate(past_prompt):  # 24
              for (
                  key
              ) in (
                  prefix.keys()
              ):  # 'decoder_prompt', 'cross_attention_prompt', 'encoder_prompt'
                  for sub_key in prefix[
                      key
                  ].keys():  # prev_key', 'prev_value', 'prev_key_padding_mask'
                      if len(prefix[key][sub_key].size()) == 4:
                          _, _, prefix_len, _ = prefix[key][
                              sub_key
                          ].size()
                          lstm_output = self.lstm(
                              past_prompt[i][key][sub_key].reshape(
                                  bsz,
                                  prefix_len,
                                  self.match_n_head * self.match_n_embd,
                              )
                          )[0]
                          if lstm_output.size(-1) == 2 * (
                              self.match_n_head * self.match_n_embd
                          ):  # bidirectional
                              past_prompt[i][key][
                                  sub_key
                              ] = lstm_output.reshape(
                                  bsz,
                                  self.match_n_head,
                                  prefix_len,
                                  2,
                                  self.match_n_embd,
                              ).mean(
                                  dim=-2
                              )
                          else:
                              past_prompt[i][key][
                                  sub_key
                              ] = lstm_output.reshape(
                                  bsz,
                                  self.match_n_head,
                                  prefix_len,
                                  self.match_n_embd,
                              )
  
      return self.t5(
          input_ids=input_ids,
          attention_mask=attention_mask,
          labels=labels,
          decoder_input_ids=decoder_input_ids,
          return_dict=return_dict,
          past_prompt=past_prompt,
      )
  
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 6 for calling the T5Prompt obj's underlying member method code with example usage: obj.forward(input_ids, attention_mask, labels, decoder_input_ids, return_dict) and returns: self