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","."]
code: def compose_single(
      self, adapter_setup: str, state: PrefixTuningState, lvl: int = 0
  ) -> PrefixTuningState:
      prefix_id = self.prefixes[adapter_setup]
      batch_size = state.key_states.size(0)
  
      # Retrieve pre-computed prefix states from context
      context = ForwardContext.get_context()
      # batch_size x n_heads x prefix_length x n_embd_per_head
      prefix_keys, prefix_values = context.prefix_states[adapter_setup][
          self.location_key
      ][prefix_id]
  
      # Select index range for batch split
      # Ignore slices that go beyond the prefix states bsz
      # (this is the case for slices produced by Parallel blocks which operate on replicated kv states)
      if (
          state.idx_slice is not None
          and state.idx_slice.start < prefix_keys.size(0)
      ):
          prefix_keys = prefix_keys[state.idx_slice]
          prefix_values = prefix_values[state.idx_slice]
  
      if adapter_setup in self.prefix_gates:
          gate = self.prefix_gates[adapter_setup]
          gate_output = torch.mean(
              torch.sigmoid(gate(state.residual_input)), dim=1
          )
          self._store_gating_score(adapter_setup, gate_output)
          gate_output_key = gate_output[:, 0].view(-1, 1, 1, 1)
          gate_output_value = gate_output[:, -1].view(-1, 1, 1, 1)
          prefix_keys = prefix_keys * gate_output_key
          prefix_values = prefix_values * gate_output_value
  
      # Replicate for Parallel block
      prefix_keys, prefix_values = adjust_tensors_for_parallel(
          state.key_states, prefix_keys, prefix_values
      )
  
      key_states = torch.cat([prefix_keys, state.key_states], dim=2)
      value_states = torch.cat(
          [prefix_values, state.value_states], dim=2
      )
      if state.attention_mask is not None:
          if (
              state.attention_mask.dim() == 2
          ):  # e.g. for DistilBERT, attention_mask has shape (batch_size, seq_len)
              prefix_mask = torch.ones(
                  batch_size, prefix_keys.size(2)
              ).to(state.attention_mask.device)
          else:
              prefix_mask = torch.ones(
                  batch_size,
                  1,
                  state.attention_mask.size(2),
                  prefix_keys.size(2),
              ).to(state.attention_mask.device)
          if state.invert_mask:
              prefix_mask = 1.0 - prefix_mask
          (prefix_mask,) = adjust_tensors_for_parallel(
              state.attention_mask, prefix_mask
          )
          attention_mask = torch.cat(
              [prefix_mask, state.attention_mask], dim=-1
          )
      else:
          attention_mask = None
  
      return state._replace(
          key_states=key_states,
          value_states=value_states,
          attention_mask=attention_mask,
      )
  
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 15 for calling the PrefixTuningLayer obj's underlying member method code with example usage: obj.compose_single(adapter_setup, state, lvl) and returns: state