code: def _reorder_cache(self, past, beam_idx):
      # if decoder past is not included in output
      # speedy decoding is disabled and no need to reorder
      if past is None:
          logger.warning(
              "You might want to consider setting `use_cache=True` to speed up decoding"
          )
          return past
  
      reordered_decoder_past = ()
      for layer_past_states in past:
          # get the correct batch idx from layer past batch dim
          # batch dim of `past` is at 2nd position
          reordered_layer_past_states = ()
          for layer_past_state in layer_past_states:
              # need to set correct `past` for each of the four key / value states
              reordered_layer_past_states = (
                  reordered_layer_past_states
                  + (
                      layer_past_state.index_select(
                          0, beam_idx.to(layer_past_state.device)
                      ),
                  )
              )
  
          assert (
              reordered_layer_past_states[0].shape
              == layer_past_states[0].shape
          )
          assert len(reordered_layer_past_states) == len(
              layer_past_states
          )
  
          reordered_decoder_past = reordered_decoder_past + (
              reordered_layer_past_states,
          )
      return reordered_decoder_past
  
imports: import logging
  import torch
  from transformers.models.t5.modeling_t5 import T5_INPUTS_DOCSTRING, T5_START_DOCSTRING, T5Model, T5PreTrainedModel
  from transformers.utils import add_start_docstrings, add_start_docstrings_to_model_forward
  from ...composition import adjust_tensors_for_parallel
  from ...heads import ClassificationHead, ModelWithFlexibleHeadsAdaptersMixin, MultiLabelClassificationHead, QuestionAnsweringHead, Seq2SeqLMHead
  from ...model_mixin import EmbeddingAdaptersWrapperMixin
  from ...wrappers import init
label_desc: Use image node_id 7 for calling the T5AdapterModel obj's underlying member method code with example usage: obj._reorder_cache(past, beam_idx) and returns: reordered_decoder_past, past