class_docstr: A task for training multiple translation models simultaneously.
  
  We iterate round-robin over batches from multiple language pairs, ordered
  according to the `--lang-pairs` argument.
  
  The training loop is roughly:
  
      for i in range(len(epoch)):
          for lang_pair in args.lang_pairs:
              batch = next_batch_for_lang_pair(lang_pair)
              loss = criterion(model_for_lang_pair(lang_pair), batch)
              loss.backward()
          optimizer.step()
  
  In practice, `next_batch_for_lang_pair` is abstracted in a FairseqDataset
  (e.g., `RoundRobinZipDatasets`) and `model_for_lang_pair` is a model that
  implements the `FairseqMultiModel` interface.
  
  During inference it is required to specify a single `--source-lang` and
  `--target-lang`, which indicates the inference langauge direction.
  `--lang-pairs`, `--encoder-langtok`, `--decoder-langtok` have to be set to
  the same value as training.
class_docstr_tok: ["A","task","for","training","multiple","translation","models","simultaneously",".","We","iterate","round-robin","over","batches","from","multiple","language","pairs",",","ordered","according","to","the","`","--","lang-pairs","`","argument",".","The","training","loop","is","roughly",":","for","i","in","range","(","len","(","epoch",")",")",":","for","lang_pair","in","args.lang_pairs",":","batch","=","next_batch_for_lang_pair","(","lang_pair",")","loss","=","criterion","(","model_for_lang_pair","(","lang_pair",")",",","batch",")","loss.backward","(",")","optimizer.step","(",")","In","practice",",","`","next_batch_for_lang_pair","`","is","abstracted","in","a","FairseqDataset","(","e.g.",",","`","RoundRobinZipDatasets","`",")","and","`","model_for_lang_pair","`","is","a","model","that","implements","the","`","FairseqMultiModel","`","interface",".","During","inference","it","is","required","to","specify","a","single","`","--","source-lang","`","and","`","--","target-lang","`",",","which","indicates","the","inference","langauge","direction",".","`","--","lang-pairs","`",",","`","--","encoder-langtok","`",",","`","--","decoder-langtok","`","have","to","be","set","to","the","same","value","as","training","."]
code: def __init__(self, args, dicts, training):
      super().__init__(args)
      self.dicts = dicts
      self.training = training
      if training:
          self.lang_pairs = args.lang_pairs
      else:
          self.lang_pairs = [
              "{}-{}".format(args.source_lang, args.target_lang)
          ]
      # eval_lang_pairs for multilingual translation is usually all of the
      # lang_pairs. However for other multitask settings or when we want to
      # optimize for certain languages we want to use a different subset. Thus
      # the eval_lang_pairs class variable is provided for classes that extend
      # this class.
      self.eval_lang_pairs = self.lang_pairs
      # model_lang_pairs will be used to build encoder-decoder model pairs in
      # models.build_model(). This allows multitask type of sub-class can
      # build models other than the input lang_pairs
      self.model_lang_pairs = self.lang_pairs
      self.langs = list(dicts.keys())
  
imports: import contextlib
  import logging
  import os
  from collections import OrderedDict
  from argparse import ArgumentError
  import torch
  from fairseq import options, utils
  from fairseq.logging import metrics
  from fairseq.data import Dictionary, LanguagePairDataset, RoundRobinZipDatasets, TransformEosLangPairDataset
  from fairseq.models import FairseqMultiModel
  from fairseq.tasks.translation import load_langpair_dataset
  from .None import LegacyFairseqTask, register_task
label_desc: Use image node_id 2 to create a new MultilingualTranslationTask object from inherited base classes: LegacyFairseqTask with example: obj = MultilingualTranslationTask(args, dicts, training)