class_docstr: Representation of a Prefix Tuning layer within one Transformer layer. This class implements `AdapterLayerBase` for
  compatibility with adapters. It uses `PrefixTuningPool` in the background and `set_pool()` must be called after
  initialization.
  
  Args:
      location_key (str): The id describing the location of this layer in the model.
                          Currently, can be "encoder_prefix", "cross_prefix" or None.
      config (:class:`~transformers.PretrainedConfig`): The model config.
class_docstr_tok: ["Representation","of","a","Prefix","Tuning","layer","within","one","Transformer","layer",".","This","class","implements","`","AdapterLayerBase","`","for","compatibility","with","adapters",".","It","uses","`","PrefixTuningPool","`","in","the","background","and","`","set_pool","(",")","`","must","be","called","after","initialization",".","Args",":","location_key","(","str",")",":","The","id","describing","the","location","of","this","layer","in","the","model",".","Currently",",","can","be","``","encoder_prefix","''",",","``","cross_prefix","''","or","None",".","config","(",":","class",":","`","~transformers.PretrainedConfig","`",")",":","The","model","config","."]
docstr: Pads all key & value states to the longest prefix length in the current batch.
  This is required e.g. for stacked prefix tunings.
docstr_tok: ["Pads","all","key","&","value","states","to","the","longest","prefix","length","in","the","current","batch",".","This","is","required","e.g",".","for","stacked","prefix","tunings","."]
code: def pad_and_concat(
      self, states: List[PrefixTuningState]
  ) -> PrefixTuningState:
      """Pads all key & value states to the longest prefix length in the current batch.
      This is required e.g. for stacked prefix tunings.
      """
      max_prefix_length = max(
          [state.key_states.shape[-2] for state in states]
      )
      (
          all_key_states,
          all_value_states,
          all_residual_input,
          all_attention_mask,
      ) = ([], [], [], [])
      for state in states:
          (
              key_states,
              value_states,
              residual_input,
              attention_mask,
          ) = state[:4]
          # pad sizes
          pad_length = max_prefix_length - key_states.shape[-2]
          pad_size = (0, 0, pad_length, 0)
          key_states = F.pad(
              key_states,
              pad_size,
              "constant",
              self.model_config.pad_token_id,
          )
          value_states = F.pad(
              value_states,
              pad_size,
              "constant",
              self.model_config.pad_token_id,
          )
  
          # pad attention mask
          if pad_length > 0:
              # Masking the padded tokens only works correctly if attention_mask is set
              # We assume this to be the case at this point
              assert (
                  attention_mask is not None
              ), "Attention mask must be set for prefix tuning"
              attention_mask = F.pad(
                  attention_mask,
                  (max_prefix_length - attention_mask.shape[-1], 0),
                  "constant",
                  1.0 if state.invert_mask else 0.0,
              )
  
          all_key_states.append(key_states)
          all_value_states.append(value_states)
          all_residual_input.append(residual_input)
          all_attention_mask.append(attention_mask)
  
      all_key_states = torch.cat(all_key_states, dim=0)
      all_value_states = torch.cat(all_value_states, dim=0)
      all_residual_input = torch.cat(all_residual_input, dim=0)
      all_attention_mask = (
          torch.cat(all_attention_mask, dim=0)
          if attention_mask is not None
          else None
      )
  
      return PrefixTuningState(
          key_states=all_key_states,
          value_states=all_value_states,
          residual_input=all_residual_input,
          attention_mask=all_attention_mask,
          invert_mask=states[0].invert_mask,
          idx_slice=states[0].idx_slice,
      )
  
imports: from typing import Dict, List, NamedTuple, Optional, Union
  import torch
  import torch.nn.functional
  from torch import nn
  from transformers import PretrainedConfig
  from transformers.modeling_utils import ModuleUtilsMixin
  from ..composition import AdapterCompositionBlock, BatchSplit, Parallel, Stack, adjust_tensors_for_parallel
  from ..configuration import ModelAdaptersConfig, PrefixTuningConfig
  from ..context import AdapterSetup, ForwardContext
  from .adapter_layer_base import ComposableAdapterLayerBase
  from .modeling import Activation_Function_Class
label_desc: Use image node_id 12 for calling the PrefixTuningLayer obj's underlying member method code with example usage: obj.pad_and_concat(states) and returns: PrefixTuningState