docstr: Performs adapter fusion with the given adapters for the given input.
docstr_tok: ["Performs","adapter","fusion","with","the","given","adapters","for","the","given","input","."]
code: def compose_fuse(
      self, adapter_setup: Fuse, state: BottleneckState, lvl: int = 0
  ):
      """
      Performs adapter fusion with the given adapters for the given input.
      """
      context = ForwardContext.get_context()
  
      # config of _last_ fused adapter is significant
      fusion_config = self.adapters_config.get_fusion(
          adapter_setup.name
      )
      last_adapter = self.adapters[adapter_setup.last()]
      hidden_states, query, residual = last_adapter.pre_forward(
          state.hidden_states,
          state.input_tensor,
          state.layer_norm,
          fusion_config=fusion_config,
      )
      state = state._replace(
          hidden_states=hidden_states, adapter_residual=residual
      )
  
      children_states = []
      for child in adapter_setup:
          if isinstance(child, AdapterCompositionBlock):
              self.check_composition_valid(adapter_setup, child, lvl)
              composition_func = self.composition_to_func_map[
                  type(child)
              ]
              child_state = composition_func(child, state, lvl=lvl + 1)
              children_states.append(child_state)
          elif child in self.adapter_modules:
              child_state = self.compose_single(
                  child, state, lvl=lvl + 1
              )
              children_states.append(child_state)
          else:
              pass
  
      if len(children_states) > 0:
          up_list = torch.stack(
              [state.bottleneck_up for state in children_states]
          )
          up_list = up_list.permute(1, 2, 0, 3)
  
          fusion_output = self.adapter_fusion_layer[adapter_setup.name](
              query,
              up_list,
              up_list,
              state.adapter_residual,
              output_attentions=context.output_adapter_fusion_attentions,
          )
          if context.output_adapter_fusion_attentions:
              hidden_states = fusion_output[0]
              self._store_fusion_attentions(
                  adapter_setup.name, fusion_output[-1]
              )
          else:
              hidden_states = fusion_output
  
      return state._replace(hidden_states=hidden_states)
  
imports: from typing import Dict, List, Mapping, NamedTuple, Optional, Union
  import torch
  from torch import nn
  from ..composition import AdapterCompositionBlock, Average, BatchSplit, Fuse, Parallel, Split, Stack, adjust_tensors_for_parallel
  from ..configuration import BnConfig
  from ..context import ForwardContext
  from .adapter_layer_base import ComposableAdapterLayerBase
  from .modeling import Adapter, BertFusion, ParallelAdapter
label_desc: Use image node_id 17 for calling the BottleneckLayer obj's underlying member method code with example usage: obj.compose_fuse(adapter_setup, state, lvl) and returns: state