original_docstring: Upgrade a (possibly old) state dict for new versions of fairseq.
docstring: Upgrade a (possibly old) state dict for new versions of fairseq.
docstring_tokens: 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:
                  print("deleting {0}".format(weights_key))
                  del state_dict[weights_key]
              state_dict[
                  "{}.embed_positions._float_tensor".format(name)
              ] = torch.FloatTensor(1)
          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
code_tokens: def upgrade_state_dict_named ( self , state_dict , name ) : if isinstance ( self . embed_positions , SinusoidalPositionalEmbedding ) : weights_key = "{}.embed_positions.weights" . format ( name ) if weights_key in state_dict : print ( "deleting {0}" . format ( weights_key ) ) del state_dict [ weights_key ] state_dict [ "{}.embed_positions._float_tensor" . format ( name ) ] = torch . FloatTensor ( 1 ) for i in range ( self . num_layers ) : 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 : self . layer_norm = None self . normalize = False state_dict [ version_key ] = torch . Tensor ( [ 1 ] ) return state_dict
short_docstring: Upgrade a (possibly old) state dict for new versions of fairseq.
short_docstring_tokens: Upgrade a ( possibly old ) state dict for new versions of fairseq .
comment: """Upgrade a (possibly old) state dict for new versions of fairseq."""$SEP$# update layer norms$SEP$# earlier checkpoints did not normalize after the stack of layers