The main.py script serves as the primary entrypoint for training and testing models. It uses a combination of YAML configuration files and command-line arguments to define the model, data, and trainer settings.
Configuration Hierarchy:
- Base YAML configs (loaded via
-b/--base, merged left-to-right). - Command-line arguments (overwriting YAML parameters using
--key value or nested.key=value syntax).
Key CLI Flags:
-t, --train: Enables training mode.--no-test: Disables the testing phase after training.-r, --resume: Resumes training from a specific log directory or checkpoint.-r2, --resume2: Loads a state dict from a specific checkpoint file into the model (non-strict).-n, --name: Adds a postfix to the log directory name.-l, --logdir: Specifies the base directory for logging (default: logs).-s, --seed: Sets the random seed (default: 23).-d, --debug: Enables post-mortem debugging on failure.
# Example: Train using a base config and override a parameter
python main.py -b configs/base_config.yaml --model.params.lr=0.0001 -t
# Example: Resume training from a log directory
python main.py -r logs/2023-01-01T12-00-00_config_name -t