CLI Reference
Complete reference for Lighter's command-line interface.
Commands
Lighter provides four main commands:
lighter fit # Train and validate
lighter validate # Validate only
lighter test # Test only
lighter predict # Run inference
All commands use the same configuration system.
lighter fit
Train your model with automatic validation.
Basic Usage
Arguments
| Argument | Description | Required |
|---|---|---|
CONFIG |
Path to YAML config file | Yes |
--ckpt_path PATH |
Checkpoint path to resume from ("last", "best", or file path) | No |
--weights_only BOOL |
Load only weights (security option) | No |
OVERRIDES |
Config overrides (key::path=value) | No |
Examples
# Basic training
lighter fit config.yaml
# Resume from checkpoint
lighter fit config.yaml --ckpt_path checkpoints/last.ckpt
# With config overrides
lighter fit config.yaml model::optimizer::lr=0.01
# Multiple configs
lighter fit base.yaml,experiment.yaml
# Combine CLI flags and overrides
lighter fit config.yaml --ckpt_path last trainer::max_epochs=100
Config Structure
trainer:
_target_: pytorch_lightning.Trainer
# ... trainer args ...
model:
_target_: your.Module
# ... model args ...
data:
_target_: lighter.LighterDataModule
# ... data args ...
Output
Creates directory structure:
outputs/
└── YYYY-MM-DD/
└── HH-MM-SS/
├── config.yaml # Config used
├── checkpoints/
│ └── last.ckpt # Latest checkpoint
└── logs/ # Training logs
lighter validate
Run validation on a trained model.
Basic Usage
Arguments
| Argument | Description | Required |
|---|---|---|
CONFIG |
Path to YAML config file | Yes |
--ckpt_path PATH |
Checkpoint path for validation ("last", "best", or file path) | No |
--verbose BOOL |
Print validation results (default: True) | No |
--weights_only BOOL |
Load only weights (security option) | No |
OVERRIDES |
Config overrides | No |
Examples
# Validate with checkpoint
lighter validate config.yaml --ckpt_path checkpoints/best.ckpt
# Override config
lighter validate config.yaml \
--ckpt_path checkpoints/best.ckpt \
data::val_dataloader::batch_size=128
Config Structure
Same as fit command.
Requirements
- Checkpoint file (
.ckpt) val_dataloaderin data configvalidation_stepin your module
lighter test
Run test on a trained model.
Basic Usage
Arguments
| Argument | Description | Required |
|---|---|---|
CONFIG |
Path to YAML config file | Yes |
--ckpt_path PATH |
Checkpoint path for testing ("last", "best", or file path) | No |
--verbose BOOL |
Print test results (default: True) | No |
--weights_only BOOL |
Load only weights (security option) | No |
OVERRIDES |
Config overrides | No |
Examples
# Test with checkpoint
lighter test config.yaml --ckpt_path checkpoints/best.ckpt
# Multiple test sets
lighter test config.yaml \
--ckpt_path checkpoints/best.ckpt \
data::test_dataloader::dataset::root=./test_data
Config Structure
Same as fit command, with a test dataloader:
Requirements
- Checkpoint file (
.ckpt) test_dataloaderin data configtest_stepin your module
lighter predict
Run inference on data.
Basic Usage
Arguments
| Argument | Description | Required |
|---|---|---|
CONFIG |
Path to YAML config file | Yes |
--ckpt_path PATH |
Checkpoint path for predictions ("last", "best", or file path) | No |
--return_predictions BOOL |
Whether to return predictions (default: True) | No |
--weights_only BOOL |
Load only weights (security option) | No |
OVERRIDES |
Config overrides | No |
Examples
# Basic prediction
lighter predict config.yaml --ckpt_path checkpoints/best.ckpt
# With writer to save results
lighter predict config.yaml \
--ckpt_path checkpoints/best.ckpt \
'trainer::callbacks=[{_target_: lighter.callbacks.CSVWriter}]'
Config Structure
Same as fit command, with a predict dataloader:
data:
predict_dataloader:
_target_: torch.utils.data.DataLoader
# ... predict dataloader config ...
trainer:
callbacks:
- _target_: lighter.callbacks.CSVWriter # Optional: save predictions
write_interval: batch
Requirements
- Checkpoint file (
.ckpt) predict_dataloaderin data configpredict_stepin your module- Optional: Writer callback to save results
Config Overrides
Override any config value from command line.
Syntax
Examples
Simple Values
# Numbers
lighter fit config.yaml model::optimizer::lr=0.01
# Strings
lighter fit config.yaml trainer::logger::name=my_experiment
# Booleans
lighter fit config.yaml trainer::enable_checkpointing=false
Nested Values
# Deep nesting
lighter fit config.yaml \
model::optimizer::lr=0.01 \
model::optimizer::weight_decay=0.0001 \
model::network::num_classes=100
Lists
Objects
# YAML object syntax
lighter fit config.yaml \
'trainer::callbacks=[{_target_: pytorch_lightning.callbacks.EarlyStopping, monitor: val/loss, patience: 10}]'
Path Syntax
Use :: to navigate config hierarchy:
Config Merging
Combine multiple config files.
Syntax
Behavior
Later files override earlier ones (dictionary merge).
Examples
# Base + experiment
lighter fit base.yaml,experiment.yaml
# Multiple overrides
lighter fit base.yaml,data.yaml,model.yaml,overrides.yaml
Example Files
base.yaml:
experiment.yaml:
Result: Merged config with max_epochs=200 and new optimizer.
Environment Variables
LIGHTER_OUTPUT_DIR
Change default output directory:
Or in config:
CUDA_VISIBLE_DEVICES
Control GPU visibility:
# Use only GPU 2
CUDA_VISIBLE_DEVICES=2 lighter fit config.yaml
# Use GPUs 0 and 3
CUDA_VISIBLE_DEVICES=0,3 lighter fit config.yaml trainer::devices=2
MASTER_ADDR / MASTER_PORT
For multi-node training:
Common Patterns
Quick Debugging
# Fast dev run (1 batch)
lighter fit config.yaml trainer::fast_dev_run=true
# Overfit 10 batches
lighter fit config.yaml trainer::overfit_batches=10
# Limit batches
lighter fit config.yaml trainer::limit_train_batches=0.1
Hyperparameter Tuning
# Learning rate sweep
for lr in 0.0001 0.001 0.01; do
lighter fit config.yaml model::optimizer::lr=$lr
done
# Batch size sweep
for bs in 32 64 128 256; do
lighter fit config.yaml data::train_dataloader::batch_size=$bs
done
Multi-GPU
# All GPUs
lighter fit config.yaml trainer::devices=-1 trainer::strategy=ddp
# Specific GPUs
lighter fit config.yaml trainer::devices=4 trainer::strategy=ddp
# Specific GPU IDs
lighter fit config.yaml 'trainer::devices=[0,2,3]' trainer::strategy=ddp
Resume Training
# Resume from last checkpoint
lighter fit config.yaml --ckpt_path outputs/.../checkpoints/last.ckpt
# Resume with different LR
lighter fit config.yaml \
--ckpt_path outputs/.../checkpoints/last.ckpt \
model::optimizer::lr=0.0001
Save Predictions
# CSV output
lighter predict config.yaml \
--ckpt_path checkpoints/best.ckpt \
'trainer::callbacks=[{_target_: lighter.callbacks.CSVWriter}]'
# File output
lighter predict config.yaml \
--ckpt_path checkpoints/best.ckpt \
'trainer::callbacks=[{_target_: lighter.callbacks.FileWriter}]'
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Config error (invalid YAML, missing files) |
| 2 | Runtime error (training failed, OOM, etc.) |
Verbosity
PyTorch Lightning controls logging verbosity.
Reduce Logging
Increase Logging
Tips
Shell Completion
Add to your shell config:
# Bash
eval "$(_LIGHTER_COMPLETE=bash_source lighter)"
# Zsh
eval "$(_LIGHTER_COMPLETE=zsh_source lighter)"
Config Validation
Validate config without training:
Find Config Issues
Enable Sparkwheel debug output:
See Resolved Config
Add print in your module:
def __init__(self, ...):
super().__init__()
self.save_hyperparameters()
print(self.hparams) # See final values
Next Steps
- Configuration Guide - Learn config syntax
- Training Guide - Training workflows
- Example Projects - Complete examples
Quick Reference
# Basic commands
lighter fit config.yaml
lighter validate config.yaml
lighter test config.yaml
lighter predict config.yaml
# Overrides
lighter fit config.yaml key::path=value
# Multiple configs
lighter fit base.yaml,experiment.yaml
# Checkpoints
lighter fit config.yaml --ckpt_path path/to/checkpoint.ckpt
lighter validate config.yaml --ckpt_path path/to/checkpoint.ckpt
lighter test config.yaml --ckpt_path path/to/checkpoint.ckpt
lighter predict config.yaml --ckpt_path path/to/checkpoint.ckpt
# Multi-GPU
lighter fit config.yaml trainer::devices=4 trainer::strategy=ddp
# Debugging
lighter fit config.yaml trainer::fast_dev_run=true