Opt is the system for passing around options throughout ParlAI.

class parlai.core.opt.Opt(*args, **kwargs)[source]

Bases: dict

Class for tracking options.

Functions like a dict, but allows us to track the history of arguments as they are set.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.


Display all deepcopies.


Display the history for an item in the dict.

save(filename: str) → None[source]

Save the opt to disk.

Attempts to ‘clean up’ any residual values automatically.

classmethod load(optfile: str) → parlai.core.opt.Opt[source]

Load an Opt from disk.

classmethod load_init(optfile: str) → parlai.core.opt.Opt[source]

Like load, but also looks in opt_presets folders.

optfile may also be a comma-separated list of multiple presets/files.


Provide an argument parser and default command line options for using ParlAI.


Print the current git commit of ParlAI and parlai_internal.


Output any announcements the ParlAI team wishes to make to users.

Also gives the user the option to suppress the output.


Get the model name from either –model or –model-file.

parlai.core.params.str2none(value: str)[source]

If the value is a variant of none, return None.

Otherwise, return the original value.


Convert ‘yes’, ‘false’, ‘1’, etc.

into a boolean.


Look for single float or comma-separated floats.


From import path string, returns the class specified.

For example, the string ‘parlai.agents.hugging_face.dict:Gpt2DictionaryAgent’ returns <class ‘parlai.agents.hugging_face.dict.Gpt2DictionaryAgent’>.


Inverse of params.str2class().


Convert underscores to hyphens in args.

For example, converts ‘–gradient_clip’ to ‘–gradient-clip’.


args – iterable, possibly containing args strings with underscores.

class parlai.core.params.CustomHelpFormatter(*args, **kwargs)[source]

Bases: argparse.HelpFormatter

Produce a custom-formatted –help option.

See for details.

__init__(*args, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

class parlai.core.params.ParlaiParser(add_parlai_args=True, add_model_args=False, description=None, **kwargs)[source]

Bases: argparse.ArgumentParser

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.

  • add_parlai_args – (default True) initializes the default arguments for ParlAI package, including the data download paths and task arguments.

  • add_model_args – (default False) initializes the default arguments for loading models, including initializing arguments from that model.

__init__(add_parlai_args=True, add_model_args=False, description=None, **kwargs)[source]

Initialize the ParlAI parser.


Add –datapath CLI arg.


Add standard mechanical turk arguments.


Arguments for all chat services.


Add websocket arguments.


Add Facebook Messenger arguments.


Add common ParlAI args across all scripts.


Add CLI args for distributed training.


Add arguments related to models such as model files.

add_model_subargs(model: str, partial: parlai.core.opt.Opt)[source]

Add arguments specific to a particular model.

add_task_args(task: str, partial: parlai.core.opt.Opt)[source]

Add arguments specific to the specified task.

add_world_args(task: str, interactive_task: Optional[str], selfchat_task: Optional[str], partial: parlai.core.opt.Opt)[source]

Add arguments specific to the world.


Add additional arguments for handling images.


Add more args depending on how known args are set.

parse_known_args(args=None, namespace=None, nohelp=False)[source]

Parse known args to ignore help flag.


Parse provided arguments and return parlai opts and unknown arg list.

Runs the same arg->opt parsing that parse_args does, but doesn’t throw an error if the args being parsed include additional command line arguments that parlai doesn’t know what to do with.

parse_args(args=None, namespace=None, **kwargs)[source]

Parse the provided arguments and returns a dictionary of the args.

We specifically remove items with None as values in order to support the style opt.get(key, default), which would otherwise return None.


Parse kwargs, with type checking etc.


Set overridable kwargs.

add_argument(*args, **kwargs)[source]

Override to convert underscores to hyphens for consistency.

add_argument_group(*args, **kwargs)[source]

Override to make arg groups also convert underscores to hyphens.


Override to print custom error message.

parlai.core.params.default(val, default)[source]

shorthand for explicit None check for optional arguments.