code: def build_single_decoder(
      args,
      src_dict,
      dst_dict,
      embed_tokens,
      ngram_decoder=None,
      project_output=True,
      is_lm=False,
  ):
      if args.adaptive_softmax_cutoff is not None:
          project_output = False
      attention_type = args.attention_type
      encoder_hidden_dim = args.encoder_hidden_dim
      if is_lm:
          attention_type = "no"
          encoder_hidden_dim = 0
      if ngram_decoder:
          if args.ngram_activation_type == "relu":
              activation_fn = nn.ReLU
          elif args.ngram_activation_type == "tanh":
              activation_fn = nn.Tanh
          else:
              raise Exception(
                  "ngram_activation_type '%s' not implemented"
                  % args.ngram_activation_type
              )
          decoder = NGramDecoder(
              src_dict=src_dict,
              dst_dict=dst_dict,
              n=ngram_decoder,
              encoder_hidden_dim=encoder_hidden_dim,
              embed_dim=args.decoder_embed_dim,
              freeze_embed=args.decoder_freeze_embed,
              out_embed_dim=args.decoder_out_embed_dim,
              num_layers=args.decoder_layers,
              hidden_dim=args.decoder_hidden_dim,
              attention_type=attention_type,
              dropout_in=args.decoder_dropout_in,
              dropout_out=args.decoder_dropout_out,
              residual_level=args.residual_level,
              activation_fn=activation_fn,
              project_output=project_output,
              pretrained_embed=args.decoder_pretrained_embed,
              projection_pretrained_embed=args.decoder_out_pretrained_embed,
          )
      else:
          decoder = RNNDecoder(
              src_dict=src_dict,
              dst_dict=dst_dict,
              embed_tokens=embed_tokens,
              vocab_reduction_params=args.vocab_reduction_params,
              encoder_hidden_dim=encoder_hidden_dim,
              embed_dim=args.decoder_embed_dim,
              out_embed_dim=args.decoder_out_embed_dim,
              cell_type=args.cell_type,
              num_layers=args.decoder_layers,
              hidden_dim=args.decoder_hidden_dim,
              attention_type=attention_type,
              attention_heads=args.attention_heads,
              first_layer_attention=bool(args.first_layer_attention),
              dropout_in=args.decoder_dropout_in,
              dropout_out=args.decoder_dropout_out,
              residual_level=args.residual_level,
              averaging_encoder=args.averaging_encoder,
              project_output=project_output,
              pretrained_embed=args.decoder_pretrained_embed,
              projection_pretrained_embed=args.decoder_out_pretrained_embed,
              out_embed_norm=args.out_embed_norm,
              tie_embeddings=args.decoder_tie_embeddings,
              att_weighted_src_embeds=args.att_weighted_src_embeds,
              src_embed_dim=args.encoder_embed_dim,
              att_weighted_activation_type=args.att_weighted_activation_type,
              fp16=args.fp16,
          )
  
      # Being able to use adaptive softmax for RNN decoder
      decoder.adaptive_softmax = None
  
      if args.adaptive_softmax_cutoff is not None:
          decoder.adaptive_softmax = AdaptiveSoftmax(
              len(dst_dict),
              args.decoder_out_embed_dim or args.decoder_hidden_dim,
              options.eval_str_list(
                  args.adaptive_softmax_cutoff, type=int
              ),
              dropout=args.dropout,
          )
      return decoder
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.onnx.operators
  from fairseq import options, utils
  from fairseq.models import FairseqEncoder, FairseqEncoderDecoderModel, register_model, register_model_architecture
  from fairseq.modules import AdaptiveSoftmax
  from pytorch_translate import attention, rnn_cell, utils, vocab_reduction
  from pytorch_translate.common_layers import ContextEmbedding, DecoderWithOutputProjection, Embedding, Linear, RNNLayer, VariableTracker
  from pytorch_translate.data import data
  from pytorch_translate.multi_model import MultiDecoder, MultiEncoder
  from pytorch_translate.multilingual import MultilingualDecoder, MultilingualEncoder
  from pytorch_translate.ngram import NGramDecoder
  from pytorch_translate.semi_supervised import SemiSupervisedModel
  from pytorch_translate.utils import maybe_cat, maybe_cuda, torch_find
  from torch.nn.utils.rnn import pack_padded_sequence, PackedSequence, pad_packed_sequence
label_desc: Use image node_id 4 for calling the RNNModel obj's underlying member method code with example usage: obj.build_single_decoder(args, src_dict, dst_dict, embed_tokens, ngram_decoder, project_output, is_lm) and returns: decoder