class_docstr: Transformer encoder consisting of *cfg.encoder.layers* layers. Each layer
  is a :class:`TransformerEncoderLayer`.
  
  Args:
      args (argparse.Namespace): parsed command-line arguments
      dictionary (~fairseq.data.Dictionary): encoding dictionary
      embed_tokens (torch.nn.Embedding): input embedding
class_docstr_tok: ["Transformer","encoder","consisting","of","*","cfg.encoder.layers","*","layers",".","Each","layer","is","a",":","class",":","`","TransformerEncoderLayer","`",".","Args",":","args","(","argparse.Namespace",")",":","parsed","command-line","arguments","dictionary","(","~fairseq.data.Dictionary",")",":","encoding","dictionary","embed_tokens","(","torch.nn.Embedding",")",":","input","embedding"]
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."""
      for i in range(self.num_layers):
          # update layer norms
          self.layers[i].upgrade_state_dict_named(
              state_dict, "{}.layers.{}".format(name, i)
          )
  
      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 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 FairseqEncoder
  from fairseq.models.transformer import TransformerConfig
  from fairseq.modules import 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 9 for calling the TransformerEncoderBase obj's underlying member method code with example usage: obj.upgrade_state_dict_named(state_dict, name) and returns: state_dict