class_docstr: Override GPT2LMHeadModel to allow for prefix conditioning.
docstr: This function is used to re-order the :obj:`past_key_values` cache if
  :meth:`~transformers.PreTrainedModel.beam_search` or :meth:`~transformers.PreTrainedModel.beam_sample` is
  called. This is required to match :obj:`past_key_values` with the correct beam_idx at every generation step.
code: def _reorder_cache(past, beam_idx):
      """
      This function is used to re-order the :obj:`past_key_values` cache if
      :meth:`~transformers.PreTrainedModel.beam_search` or :meth:`~transformers.PreTrainedModel.beam_sample` is
      called. This is required to match :obj:`past_key_values` with the correct beam_idx at every generation step.
      """
      return tuple(
          tuple(
              past_state.index_select(0, beam_idx.to(past_state.device))
              for past_state in layer_past
          )
          for layer_past in past
      )
  
file_path: TTS/TTS/tts/layers/xtts/gpt_inference.py
imports: import math
  import torch
  from torch import nn
  from transformers import GPT2PreTrainedModel
  from transformers.modeling_outputs import CausalLMOutputWithCrossAttentions
label_desc: Use image node_id 5 for calling the GPT2InferenceModel obj's underlying member method code with example usage: obj._reorder_cache(past, beam_idx) and returns: tuple