class_docstr: Second phase of decoder layer block
      Each layer will be of type TransformerDecoderLayerPhase2
  Args:
      args (argparse.Namespace): parsed command-line arguments
      dictionary (~fairseq.data.Dictionary): encoding dictionary
      embed_tokens (torch.nn.Embedding): input embedding
      no_encoder_decoder_attn: If encoder decoder attention is required or not
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 isinstance(
          self.embed_positions, SinusoidalPositionalEmbedding
      ):
          weights_key = "{}.embed_positions.weights".format(name)
          if weights_key in state_dict:
              del state_dict[weights_key]
          state_dict[
              "{}.embed_positions._float_tensor".format(name)
          ] = torch.FloatTensor(1)
  
      for i in range(len(self.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
  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
  from fairseq.models.transformer import Embedding, Linear, TransformerDecoder, TransformerEncoder
  from fairseq.modules import AdaptiveSoftmax, LayerNorm, MultiheadAttention, PositionalEmbedding, SinusoidalPositionalEmbedding
label_desc: Use image node_id 7 for calling the TransformerDecoderPhase2 obj's underlying member method code with example usage: obj.upgrade_state_dict_named(state_dict, name) and returns: state_dict