class_docstr: Transformer decoder consisting of *args.decoder_layers* layers. Each layer
  is a :class:`TransformerAANDecoderLayer`.
class_docstr_tok: ["Transformer","decoder","consisting","of","*","args.decoder_layers","*","layers",".","Each","layer","is","a",":","class",":","`","TransformerAANDecoderLayer","`","."]
docstr: Upgrade a (possibly old) state dict for new versions of fairseq.
code: def upgrade_state_dict(self, state_dict):
      """Upgrade a (possibly old) state dict for new versions of fairseq."""
      if isinstance(
          self.embed_positions, SinusoidalPositionalEmbedding
      ):
          if "decoder.embed_positions.weights" in state_dict:
              del state_dict["decoder.embed_positions.weights"]
          state_dict[
              "decoder.embed_positions._float_tensor"
          ] = torch.FloatTensor(1)
  
      for i in range(len(self.layers)):
          # update layer norms
          layer_norm_map = {
              "0": "aan_layer_norm",
              "1": "encoder_attn_layer_norm",
              "2": "final_layer_norm",
          }
          for old, new in layer_norm_map.items():
              for m in ("weight", "bias"):
                  k = "decoder.layers.{}.layer_norms.{}.{}".format(
                      i, old, m
                  )
                  if k in state_dict:
                      state_dict[
                          "decoder.layers.{}.{}.{}".format(i, new, m)
                      ] = state_dict[k]
                      del state_dict[k]
      if (
          utils.item(
              state_dict.get("decoder.version", torch.Tensor([1]))[0]
          )
          < 2
      ):
          # earlier checkpoints did not normalize after the stack of layers
          self.layer_norm = None
          self.normalize = False
          state_dict["decoder.version"] = torch.Tensor([1])
  
      return state_dict
  
imports: import math
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import options, utils
  from fairseq.models import FairseqEncoderDecoderModel, FairseqIncrementalDecoder, register_model, register_model_architecture, transformer
  from fairseq.modules import AdaptiveSoftmax, LearnedPositionalEmbedding, MultiheadAttention, SinusoidalPositionalEmbedding
  from pytorch_translate import transformer, vocab_reduction
  from pytorch_translate.average_attention import AverageAttention, AverageWindowAttention
  from pytorch_translate.utils import torch_find
label_desc: Use image node_id 6 for calling the TransformerAANDecoder obj's underlying member method code with example usage: obj.upgrade_state_dict(state_dict) and returns: state_dict