runner
Runner module for executing training stages with configuration management. Contains the Runner class and CLI entry point.
ConfigLoader
Loads and validates configuration using Sparkwheel.
Source code in src/lighter/engine/runner.py
load(inputs)
staticmethod
Load config from inputs (files, dicts, overrides).
Sparkwheel auto-detects: - Strings without '=' → file paths - Strings with '=' → overrides - Dicts → merged into config
Source code in src/lighter/engine/runner.py
ProjectImporter
Discovers and imports user project modules.
Source code in src/lighter/engine/runner.py
auto_discover_and_import()
staticmethod
Auto-discover project from lighter.py marker file. Returns True if project was imported, False otherwise.
Source code in src/lighter/engine/runner.py
Runner
Orchestrates training stage execution by coordinating helper classes.
Runner delegates responsibilities to specialized helper classes: - ProjectImporter: Auto-discovers and imports user project modules via lighter.py marker - ConfigLoader: Loads and validates configurations using Sparkwheel
Runner focuses on resolving and validating components (model, trainer, datamodule) and executing the requested training stage.
Source code in src/lighter/engine/runner.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
_execute(stage, model, trainer, datamodule, **stage_kwargs)
Execute the training stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stage
|
Stage
|
Stage to execute (fit, validate, test, predict) |
required |
model
|
LightningModule
|
Resolved model |
required |
trainer
|
Trainer
|
Resolved trainer |
required |
datamodule
|
LightningDataModule | None
|
Resolved datamodule (None if model defines its own dataloaders) |
required |
**stage_kwargs
|
Any
|
Additional keyword arguments from CLI (e.g., ckpt_path, verbose) |
{}
|
Source code in src/lighter/engine/runner.py
_resolve_datamodule(config, model)
Resolve and validate datamodule from config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration object |
required |
model
|
LightningModule
|
Resolved model (checked for built-in dataloaders) |
required |
Returns:
| Type | Description |
|---|---|
LightningDataModule | None
|
LightningDataModule instance or None if model defines its own dataloaders |
Raises:
| Type | Description |
|---|---|
TypeError
|
If data key exists but is not a LightningDataModule |
Source code in src/lighter/engine/runner.py
_resolve_model(config)
Resolve and validate model from config.
Source code in src/lighter/engine/runner.py
_resolve_trainer(config)
Resolve and validate trainer from config.
Source code in src/lighter/engine/runner.py
_save_config(config, trainer, model)
Save configuration to multiple destinations.
Saves the configuration to: - Model (for checkpoint access via model.hparams) - Logger (for experiment tracking via log_hyperparams) - Log directory (as config.yaml file)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
Configuration object to save |
required |
trainer
|
Trainer
|
Trainer (uses trainer.logger and trainer.log_dir) |
required |
model
|
LightningModule
|
Model to save hyperparameters to |
required |
Source code in src/lighter/engine/runner.py
run(stage, inputs, **stage_kwargs)
Run a training stage with configuration inputs.
Orchestrates the complete training workflow: 1. Loads configuration via ConfigLoader (delegates to Sparkwheel for auto-detection) 2. Auto-discovers and imports project modules via ProjectImporter 3. Resolves and validates model, trainer, and datamodule components 4. Saves configuration (to log directory, logger, and model hyperparameters) 5. Executes the requested training stage
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stage
|
Stage
|
Stage to run (fit, validate, test, predict) |
required |
inputs
|
list
|
List of config file paths, dicts, and/or overrides. Passed to ConfigLoader.load() which delegates to Sparkwheel for auto-detection: - Strings without '=' → file paths - Strings with '=' → overrides - Dicts → merged into config |
required |
**stage_kwargs
|
Any
|
Additional keyword arguments from CLI (e.g., ckpt_path, verbose) passed directly to the trainer stage method |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If config validation fails or required components are missing |
TypeError
|
If model or trainer are not the correct type |
Source code in src/lighter/engine/runner.py
cli()
Entry point for the lighter CLI.
Source code in src/lighter/engine/runner.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |