docstr: Build a new (multi-)decoder instance.
docstr_tok: ["Build","a","new","(","multi-",")","decoder","instance","."]
code: def build_decoder(cls, args, src_dict, dst_dict, embed_tokens):
      """Build a new (multi-)decoder instance."""
      if args.multi_decoder is not None:
          ngram_decoder_args = [None] * args.multi_decoder
          if args.ngram_decoder is not None:
              ngram_decoder_args = args.ngram_decoder
              if len(ngram_decoder_args) == 1:
                  ngram_decoder_args = [
                      ngram_decoder_args[0]
                  ] * args.multi_decoder
              assert len(ngram_decoder_args) == args.multi_decoder
          is_lm_args = [False] * args.multi_decoder
          if args.multi_decoder_is_lm is not None:
              is_lm_args = list(map(bool, args.multi_decoder_is_lm))
          assert len(is_lm_args) == args.multi_decoder
          decoders = [
              RNNModel.build_single_decoder(
                  args,
                  src_dict,
                  dst_dict,
                  embed_tokens=embed_tokens,
                  ngram_decoder=n,
                  project_output=False,
                  is_lm=is_lm,
              )
              for is_lm, n in zip(is_lm_args, ngram_decoder_args)
          ]
          decoder = MultiDecoder(
              src_dict,
              dst_dict,
              decoders=decoders,
              combination_strategy=args.multi_decoder_combination_strategy,
              is_lm=is_lm_args,
              split_encoder=args.multi_encoder is not None,
              vocab_reduction_params=args.vocab_reduction_params,
              training_schedule=args.multi_model_training_schedule,
              fixed_weights=args.multi_model_fixed_weights,
          )
      else:
          if args.multi_encoder:
              args.encoder_hidden_dim *= args.multi_encoder
          n = args.ngram_decoder[0] if args.ngram_decoder else None
          decoder = RNNModel.build_single_decoder(
              args,
              src_dict,
              dst_dict,
              embed_tokens=embed_tokens,
              ngram_decoder=n,
          )
      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 7 for calling the RNNModel obj's underlying member method code with example usage: obj.build_decoder(cls, args, src_dict, dst_dict, embed_tokens) and returns: decoder