class_docstr: Provide an opt-producer and CLI argument parser.
  
  Pseudo-extension of ``argparse`` which sets a number of parameters
  for the ParlAI framework. More options can be added specific to other
  modules by passing this object and calling ``add_arg()`` or
  ``add_argument()`` on it.
  
  For an example, see ``parlai.core.dict.DictionaryAgent.add_cmdline_args``.
  
  :param add_parlai_args:
      (default True) initializes the default arguments for ParlAI
      package, including the data download paths and task arguments.
  :param add_model_args:
      (default False) initializes the default arguments for loading
      models, including initializing arguments from that model.
class_docstr_tok: ["Provide","an","opt-producer","and","CLI","argument","parser",".","Pseudo-extension","of","``","argparse","``","which","sets","a","number","of","parameters","for","the","ParlAI","framework",".","More","options","can","be","added","specific","to","other","modules","by","passing","this","object","and","calling","``","add_arg","(",")","``","or","``","add_argument","(",")","``","on","it",".","For","an","example",",","see","``","parlai.core.dict.DictionaryAgent.add_cmdline_args","``",".",":","param","add_parlai_args",":","(","default","True",")","initializes","the","default","arguments","for","ParlAI","package",",","including","the","data","download","paths","and","task","arguments",".",":","param","add_model_args",":","(","default","False",")","initializes","the","default","arguments","for","loading","models",",","including","initializing","arguments","from","that","model","."]
docstr: Add more args depending on how known args are set.
docstr_tok: ["Add","more","args","depending","on","how","known","args","are","set","."]
code: def add_extra_args(self, args=None):
      """
      Add more args depending on how known args are set.
      """
      parsed = vars(self.parse_known_args(args, nohelp=True)[0])
      # Also load extra args options if a file is given.
      if parsed.get("init_opt") is not None:
          try:
              self._load_known_opts(parsed.get("init_opt"), parsed)
          except FileNotFoundError:
              # don't die if -o isn't found here. See comment in second call
              # later on.
              pass
      parsed = self._infer_datapath(parsed)
  
      partial = Opt(parsed)
  
      # find which image mode specified if any, and add additional arguments
      image_mode = parsed.get("image_mode", None)
      if image_mode is not None and image_mode != "no_image_model":
          self.add_image_args(image_mode)
  
      # find which task specified if any, and add its specific arguments
      task = parsed.get("task", None)
      if task is not None:
          self.add_task_args(task, partial)
      evaltask = parsed.get("evaltask", None)
      if evaltask is not None:
          self.add_task_args(evaltask, partial)
  
      # find which model specified if any, and add its specific arguments
      model = get_model_name(parsed)
      if model is not None:
          self.add_model_subargs(model, partial)
  
      # add world args, if we know a priori which world is being used
      if task is not None:
          self.add_world_args(
              task,
              parsed.get("interactive_task", False),
              parsed.get("selfchat_task", False),
              partial,
          )
  
      # reparse args now that we've inferred some things.  specifically helps
      # with a misparse of `-opt` as `-o pt`, which causes opt loading to
      # try to load the file "pt" which doesn't exist.
      # After adding model arguments, -opt becomes known (it's in TorchAgent),
      # and we parse the `-opt` value correctly.
      parsed = vars(self.parse_known_args(args, nohelp=True)[0])
      if parsed.get("init_opt") is not None:
          self._load_known_opts(parsed.get("init_opt"), parsed)
  
      # reset parser-level defaults over any model-level defaults
      try:
          self.set_defaults(**self._defaults)
      except AttributeError:
          raise RuntimeError(
              "Please file an issue on github that argparse "
              "got an attribute error when parsing."
          )
  
imports: import argparse
  import importlib
  import os
  import sys
  import datetime
  import parlai
  import parlai.utils.logging
  from parlai.core.build_data import modelzoo_path
  from parlai.core.loader import load_teacher_module, load_agent_module, load_world_module
  from parlai.tasks.tasks import ids_to_tasks
  from parlai.core.opt import Opt
  from parlai.utils.io import PathManager
  from typing import List, Optional
label_desc: Use image node_id 14 for calling the ParlaiParser obj's underlying member method code with example usage: obj.add_extra_args(args) without return types