class_docstr: Transformer decoder consisting of *cfg.decoder.layers* layers. Each layer
  is a :class:`TransformerDecoderLayer`.
  
  Args:
      cfg (argparse.Namespace): parsed command-line arguments
      dictionary (~fairseq.data.Dictionary): decoding dictionary
      embed_tokens (torch.nn.Embedding): output embedding
      no_encoder_attn (bool, optional): whether to attend to encoder outputs
          (default: False).
class_docstr_tok: ["Transformer","decoder","consisting","of","*","cfg.decoder.layers","*","layers",".","Each","layer","is","a",":","class",":","`","TransformerDecoderLayer","`",".","Args",":","cfg","(","argparse.Namespace",")",":","parsed","command-line","arguments","dictionary","(","~fairseq.data.Dictionary",")",":","decoding","dictionary","embed_tokens","(","torch.nn.Embedding",")",":","output","embedding","no_encoder_attn","(","bool",",","optional",")",":","whether","to","attend","to","encoder","outputs","(","default",":","False",")","."]
docstr: Upgrade a (possibly old) state dict for new versions of fairseq.
docstr_tok: ["Upgrade","a","(","possibly","old",")","state","dict","for","new","versions","of","fairseq","."]
code: def upgrade_state_dict_named(self, state_dict, name):
      """Upgrade a (possibly old) state dict for new versions of fairseq."""
      if f"{name}.output_projection.weight" not in state_dict:
          if self.share_input_output_embed:
              embed_out_key = f"{name}.embed_tokens.weight"
          else:
              embed_out_key = f"{name}.embed_out"
          if embed_out_key in state_dict:
              state_dict[
                  f"{name}.output_projection.weight"
              ] = state_dict[embed_out_key]
              if not self.share_input_output_embed:
                  del state_dict[embed_out_key]
  
      for i in range(self.num_layers):
          # update layer norms
          layer_norm_map = {
              "0": "self_attn_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 = "{}.layers.{}.layer_norms.{}.{}".format(
                      name, i, old, m
                  )
                  if k in state_dict:
                      state_dict[
                          "{}.layers.{}.{}.{}".format(name, i, new, m)
                      ] = state_dict[k]
                      del state_dict[k]
  
      version_key = "{}.version".format(name)
      if (
          utils.item(state_dict.get(version_key, torch.Tensor([1]))[0])
          <= 2
      ):
          # earlier checkpoints did not normalize after the stack of layers
          self.layer_norm = None
          self.normalize = False
          state_dict[version_key] = torch.Tensor([1])
  
      return state_dict
  
imports: import math
  from typing import Any, Dict, List, Optional
  import torch
  import torch.nn
  from torch import Tensor
  from fairseq import utils
  from fairseq.distributed import fsdp_wrap
  from fairseq.models import FairseqIncrementalDecoder
  from fairseq.models.transformer import TransformerConfig
  from fairseq.modules import AdaptiveSoftmax, BaseLayer, FairseqDropout, LayerDropModuleList, LayerNorm, PositionalEmbedding, SinusoidalPositionalEmbedding, transformer_layer
  from fairseq.modules.checkpoint_activations import checkpoint_wrapper
  from fairseq.modules.quant_noise import quant_noise
label_desc: Use image node_id 10 for calling the TransformerDecoderBase obj's underlying member method code with example usage: obj.upgrade_state_dict_named(state_dict, name) and returns: state_dict