class_docstr: Refer Attention is All You Need for more details.
  
  This is a simplified implementation of multihead attention
  optimized for exporting using torchscript. Usage of nn.Linear() instead of
  F.Linear() helps to quantize the linear layers.
  
  Query represents the output from last decoder step. Key and Values are obtained from
  encoder. Attention weights are obtained from the dot product of query and key.
  Attention weights multiplied by the value gives output.
class_docstr_tok: ["Refer","Attention","is","All","You","Need","for","more","details",".","This","is","a","simplified","implementation","of","multihead","attention","optimized","for","exporting","using","torchscript",".","Usage","of","nn.Linear","(",")","instead","of","F.Linear","(",")","helps","to","quantize","the","linear","layers",".","Query","represents","the","output","from","last","decoder","step",".","Key","and","Values","are","obtained","from","encoder",".","Attention","weights","are","obtained","from","the","dot","product","of","query","and","key",".","Attention","weights","multiplied","by","the","value","gives","output","."]
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, Tensor], new_order: Tensor
  ):
      """Reorder buffered internal state (for incremental generation)."""
      all_keys = ["prev_key", "prev_value", "prev_key_padding_mask"]
      # ARBABU : why do we need to reorder_incremental_state as encoder_out
      # is always the same?
      for key in all_keys:
          input_buffer = self._get_input_buffer(incremental_state, key)
          if input_buffer is not None:
              # During incremental decoding, all candidates will be along
              # the batch dimension. We pick top candidates
              input_buffer = input_buffer.index_select(0, new_order)
              self._set_input_buffer(
                  incremental_state, key, input_buffer
              )
  
imports: from typing import Dict, Optional, Tuple
  import numpy
  import torch
  import torch.nn.functional
  from pytext.config import ConfigBase
  from pytext.utils.usage import log_class_usage
  from torch import nn, Tensor
  from .base import PyTextIncrementalDecoderComponent
  from .utils import Linear
label_desc: Use image node_id 4 for calling the MultiheadAttention obj's underlying member method code with example usage: obj.reorder_incremental_state(incremental_state, new_order) without return types