class_docstr: A cache that grows dynamically as more tokens are generated. This is the default for generative models.
  
  It stores the Key and Value states as a list of tensors, one for each layer. The expected shape for each tensor is
  `[batch_size, num_heads, seq_len, head_dim]`.
class_docstr_tok: ["A","cache","that","grows","dynamically","as","more","tokens","are","generated",".","This","is","the","default","for","generative","models",".","It","stores","the","Key","and","Value","states","as","a","list","of","tensors",",","one","for","each","layer",".","The","expected","shape","for","each","tensor","is","`","[","batch_size",",","num_heads",",","seq_len",",","head_dim","]","`","."]
docstr: Reorders the cache for beam search, given the selected beam indices.
docstr_tok: ["Reorders","the","cache","for","beam","search",",","given","the","selected","beam","indices","."]
code: def reorder_cache(self, beam_idx: torch.LongTensor):
      """Reorders the cache for beam search, given the selected beam indices."""
      for layer_idx in range(len(self.key_cache)):
          device = self.key_cache[layer_idx].device
          self.key_cache[layer_idx] = self.key_cache[
              layer_idx
          ].index_select(0, beam_idx.to(device))
          device = self.value_cache[layer_idx].device
          self.value_cache[layer_idx] = self.value_cache[
              layer_idx
          ].index_select(0, beam_idx.to(device))
  
imports: from typing import Any, Dict, List, Optional, Tuple
  import torch
label_desc: Use image node_id 8 for calling the DynamicCache obj's underlying member method code with example usage: obj.reorder_cache(beam_idx) without return types