class_docstr: Transformer decoder.
class_docstr_tok: ["Transformer","decoder","."]
code: def upgrade_state_dict_named(self, state_dict, name):
      if isinstance(
          self.embed_positions, SinusoidalPositionalEmbedding
      ):
          if f"{name}.embed_positions.weights" in state_dict:
              del state_dict[f"{name}.embed_positions.weights"]
          state_dict[
              f"{name}.embed_positions._float_tensor"
          ] = torch.FloatTensor(1)
  
      if self.vocab_reduction_module is None:
          prefix = name + "." if name != "" else ""
          items_to_add = {}
          keys_to_remove = []
          for k in state_dict.keys():
              if self.share_input_output_embed is True:
                  if k.endswith(prefix + "embed_tokens.weight"):
                      items_to_add[
                          prefix + "output_projection.weight"
                      ] = state_dict[k]
                      bias = nn.Parameter(
                          torch.Tensor(state_dict[k].shape[0])
                      )
                      nn.init.constant_(bias, 0.0)
                      items_to_add[
                          prefix + "output_projection.bias"
                      ] = bias
              else:
                  if k.endswith(prefix + "embed_out"):
                      items_to_add[
                          prefix + "output_projection.weight"
                      ] = state_dict[k]
                      bias = nn.Parameter(
                          torch.Tensor(state_dict[k].shape[0])
                      )
                      nn.init.constant_(bias, 0.0)
                      items_to_add[
                          prefix + "output_projection.bias"
                      ] = bias
  
          for k in keys_to_remove:
              del state_dict[k]
  
          for key, value in items_to_add.items():
              state_dict[key] = value
  
      return state_dict
  
imports: import math
  import random
  import torch
  import torch.nn
  import torch.nn.functional
  from fairseq import options, utils
  from fairseq.models import FairseqEncoder, FairseqEncoderDecoderModel, FairseqIncrementalDecoder, register_model, register_model_architecture, transformer
  from fairseq.modules import AdaptiveSoftmax, LayerNorm, MultiheadAttention, SinusoidalPositionalEmbedding
  from pytorch_translate import utils, vocab_reduction
  from pytorch_translate.average_attention import AverageAttention
  from pytorch_translate.common_layers import TransformerEmbedding, TransformerEncoderGivenEmbeddings, TransformerTokenEmbedding, VariableTracker
  from pytorch_translate.semi_supervised import SemiSupervisedModel
  from pytorch_translate.utils import torch_find
label_desc: Use image node_id 6 for calling the TransformerDecoder obj's underlying member method code with example usage: obj.upgrade_state_dict_named(state_dict, name) and returns: state_dict