code: def _reorder_cache(
      past: Tuple[Tuple[tf.Tensor]], beam_idx: tf.Tensor
  ) -> Tuple[Tuple[tf.Tensor]]:
      return tuple(
          tuple(
              tf.gather(past_state, beam_idx, axis=0)
              for past_state in layer_past
          )
          for layer_past in past
      )
  
imports: import warnings
  from typing import Optional, Tuple, Union
  import numpy
  import tensorflow
  from ...modeling_tf_outputs import TFBaseModelOutputWithPast, TFCausalLMOutputWithPast, TFSequenceClassifierOutput
  from ...modeling_tf_utils import TFCausalLanguageModelingLoss, TFModelInputType, TFPreTrainedModel, TFSequenceClassificationLoss, TFSharedEmbeddings, get_initializer, keras_serializable, unpack_inputs
  from ...tf_utils import shape_list, stable_softmax
  from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
  from .configuration_ctrl import CTRLConfig
label_desc: Use image node_id 7 for calling the TFCTRLLMHeadModel obj's underlying member method code with example usage: obj._reorder_cache(past, beam_idx) and returns: tuple