Command line
GPULayerCLI (also glt.LightningCLI) builds a command line from the __init__ signatures of
the Trainer, your model and your DataModule, like Lightning's LightningCLI.
# train.pyimport gpulayer.pytorch as gltfrom my_project import MyModel, MyDataif __name__ == "__main__":glt.LightningCLI(MyModel, MyData, trainer_defaults={"accelerator": "auto"})
python train.py fit --trainer.max_epochs 10 --model.lr 0.01 --data.batch_size 64python train.py fit --trainer.devices 4 --trainer.num_nodes 2 --trainer.accelerator cudapython train.py fit --print_config > experiment.yaml # the full configurationpython train.py fit --config experiment.yaml --trainer.max_epochs 20python train.py test --ckpt_path gpulayer_runs/my_project-train/checkpoints/best.ckpt
- Subcommands:
fit,validate,test,predict. - Values follow the type annotation; lists and dicts are JSON.
- Config files are JSON, or YAML with PyYAML, with sections
trainer,model,data,seed_everythingandckpt_path. Several--configfiles merge in order; flags win. - Objects such as callbacks use
class_pathandinit_args:
trainer:max_epochs: 30callbacks:- class_path: gpulayer.pytorch.EarlyStoppinginit_args: {monitor: val_loss, patience: 3}model:lr: 0.003
-
seed_everythingdefaults totrue(a recorded random seed); give a number orfalse. -
run=Falseskips subcommands and buildscli.model,cli.datamoduleandcli.trainer. -
--optimizer AdamW --optimizer.lr 1e-3and--lr_schedulerdefineconfigure_optimizersfrom the command line;--model MyModelpicks a subclass (subclass_mode_model=True). -
The resolved configuration is saved as
config.yamlin the run's log folder (save_config_callback). -
Subclass the CLI and override Lightning's hooks (
add_arguments_to_parser,before_instantiate_classes, ...);parser.link_arguments("data.num_classes", "model.num_classes", apply_on="instantiate")links sections.
It uses the standard library's argparse, not jsonargparse: values are converted from the
type annotations, and there are no environment-variable configs. cli.config is flat, not
nested under the subcommand.