CLI entrypoints.


OTXCLI([args, run])

OTX CLI entrypoint.

class otx.cli.cli.OTXCLI(args: list[str] | None = None, run: bool = True)[source]#

Bases: object

OTX CLI entrypoint.

Initialize OTX CLI.

add_subcommands() None[source]#

Adds subcommands to the CLI parser.

This method initializes and configures subcommands for the OTX CLI parser. It iterates over the available subcommands, adds arguments specific to each subcommand, and registers them with the parser.



static engine_subcommand_parser(subcommand: str, **kwargs) tuple[ArgumentParser, list][source]#

Creates an ArgumentParser object for the engine subcommand.


**kwargs – Additional keyword arguments to be passed to the ArgumentParser constructor.


The created ArgumentParser object.

Return type:


static engine_subcommands() dict[str, set[str]][source]#

Returns dictionary the subcommands of engine, and whose value is the argument to be skipped in the CLI.

This allows the CLI to skip duplicate keys when creating the Engine and when running the subcommand.


A dictionary where the keys are the subcommands and the values are sets of skipped arguments.

get_config_value(config: Namespace, key: str, default: Any | None = None) Any[source]#

Retrieves the value of a configuration key from the given config object.

  • config (Namespace) – The config object containing the configuration values.

  • key (str) – The key of the configuration value to retrieve.

  • default (Any, optional) – The default value to return if the key is not found. Defaults to None.


The value of the configuration key, or the default value if the key is not found.

if the value is a Namespace, it is converted to a dictionary.

Return type:


get_subcommand_parser(subcommand: str | None) ArgumentParser[source]#

Returns the argument parser for the specified subcommand.


subcommand (str | None) – The name of the subcommand. If None, returns the main parser.


The argument parser for the specified subcommand.

Return type:


init_parser() ArgumentParser[source]#

Initialize the argument parser for the OTX CLI.


The initialized argument parser.

Return type:


instantiate_classes(instantiate_engine: bool = True) None[source]#

Instantiate the necessary classes based on the subcommand.

This method checks if the subcommand is one of the engine subcommands. If it is, it instantiates the necessary classes such as config, datamodule, model, and engine.


instantiate_engine (bool, optional) – Whether to instantiate the engine. Defaults to True.

instantiate_engine() Engine[source]#

Instantiate an Engine object with the specified parameters.


An instance of the Engine class.

instantiate_model(model_config: Namespace) OTXModel[source]#

Instantiate the model based on the subcommand.

This method checks if the subcommand is one of the engine subcommands. If it is, it instantiates the model.


model_config (Namespace) – The model configuration.


The model and optimizer and scheduler.

Return type:


prepare_subcommand_kwargs(subcommand: str) dict[str, Any][source]#

Prepares the keyword arguments to pass to the subcommand to run.

run() None[source]#

Executes the specified subcommand.


ValueError – If the subcommand is not recognized.

save_config(work_dir: Path) None[source]#

Save the configuration for the specified subcommand.


work_dir (Path) – The working directory where the configuration file will be saved.

The configuration is saved as a YAML file in the engine’s working directory.

set_seed() None[source]#

Set the random seed for reproducibility.

This method retrieves the seed value from the argparser and uses it to set the random seed. If a seed value is provided, it will be used to set the random seed using the seed_everything function from the lightning module.

update_latest(work_dir: Path) None[source]#

Update the latest cache directory with the latest configurations and checkpoint file.


work_dir (Path) – The working directory where the configurations and checkpoint files are located.