code: def _reorder_state(
      self,
      state: Union[torch.Tensor, list, tuple],
      indices: torch.LongTensor,
      dim: int = 0,
  ):
      if isinstance(state, torch.Tensor):
          state = state.index_select(index=indices, dim=dim)
      elif isinstance(state, list):
          for i in range(len(state)):
              assert state[i] is not None
              state[i] = self._reorder_state(state[i], indices, dim)
      elif isinstance(state, tuple):
          tmp_list = []
          for i in range(len(state)):
              assert state[i] is not None
              tmp_list.append(
                  self._reorder_state(state[i], indices, dim)
              )
          state = tuple(tmp_list)
      else:
          raise TypeError(f"Cannot reorder data of type:{type(state)}")
  
      return state
  
imports: import torch
  from torch import nn
  from torch.nn import functional
  from transformers.models.bart.configuration_bart import BartConfig
  from .modeling_bart import BartModel
  from ..utils.util import avg_token_embeddings, seq_to_mask, get_model_device
  from functools import partial
  from typing import Union
label_desc: Use image node_id 2 for calling the PromptBartState obj's underlying member method code with example usage: obj._reorder_state(state, indices, dim) and returns: state