class_docstr: RNN decoder with multihead attention. Attention is calculated using encoder
  output and output of decoder's first RNN layerself. Attention is applied
  after first RNN layer and concatenated to input of subsequent layers.
class_docstr_tok: ["RNN","decoder","with","multihead","attention",".","Attention","is","calculated","using","encoder","output","and","output","of","decoder","'s","first","RNN","layerself",".","Attention","is","applied","after","first","RNN","layer","and","concatenated","to","input","of","subsequent","layers","."]
docstr: Reorder buffered internal state (for incremental generation).
docstr_tok: ["Reorder","buffered","internal","state","(","for","incremental","generation",")","."]
code: def reorder_incremental_state(
      self, incremental_state: Dict[str, torch.Tensor], new_order
  ):
      """Reorder buffered internal state (for incremental generation)."""
      assert incremental_state is not None
      hiddens = self.get_incremental_state(
          incremental_state, "cached_hiddens"
      )
      assert hiddens is not None
      cells = self.get_incremental_state(
          incremental_state, "cached_cells"
      )
      assert cells is not None
      feeds = self.get_incremental_state(
          incremental_state, "cached_feeds"
      )
      assert feeds is not None
  
      self.set_incremental_state(
          incremental_state,
          "cached_hiddens",
          hiddens.index_select(1, new_order),
      )
      self.set_incremental_state(
          incremental_state,
          "cached_cells",
          cells.index_select(1, new_order),
      )
      self.set_incremental_state(
          incremental_state,
          "cached_feeds",
          feeds.index_select(0, new_order),
      )
  
imports: from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  from fairseq import utils
  from pytext.config import ConfigBase
  from pytext.models.seq_models.base import PyTextSeq2SeqModule
  from pytext.utils.usage import log_class_usage
  from torch import nn
  from .attention import DotAttention
  from .base import PlaceholderIdentity, PyTextIncrementalDecoderComponent
label_desc: Use image node_id 4 for calling the RNNDecoderBase obj's underlying member method code with example usage: obj.reorder_incremental_state(incremental_state, new_order) without return types