kirad.launcher_utils¶
kirad.launcher_utils
¶
Turns the YAML config into objects: params, model, datasets, loaders, W&B logger.
Stage: launch (plus outputs: checkpoint replication and W&B artifact logging). Used by scripts/launcher.py.
SPLITS = ['train', 'val', 'test']
module-attribute
¶
DistributedModelCheckpoint
¶
Bases: ModelCheckpoint
ModelCheckpoint that also keeps a copy of the best checkpoint on every node.
Source code in kirad/launcher_utils.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
on_validation_end(trainer, pl_module)
¶
Save best/last ckpt after validation (with tuned thresholds); replicate on nodes.
Non-zero nodes (local rank 0) store only {"state_dict"} and delete the old best. Note: needs torch.distributed initialized (uses barriers).
Source code in kirad/launcher_utils.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
SchedulerParams
¶
Bases: BaseModel
LR scheduler settings from training_params.scheduler (gamma, milestones).
Source code in kirad/launcher_utils.py
79 80 81 82 83 84 85 86 87 | |
OptimizerParams
¶
Bases: BaseModel
Optimizer settings for one parameter group (lr, weight_decay).
Source code in kirad/launcher_utils.py
90 91 92 93 94 95 96 97 98 | |
TrainingParams
¶
Bases: BaseModel
Validated training_params: batch sizes, epochs, monitor metric, optimizer, seed.
Grad accumulation = effective_batch_size / (world_size * batch_size); must divide. Note: constructing it calls pl.seed_everything(seed).
Source code in kirad/launcher_utils.py
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 | |
model_config = ConfigDict(extra='forbid', arbitrary_types_allowed=True)
class-attribute
instance-attribute
¶
batch_size
instance-attribute
¶
effective_batch_size
instance-attribute
¶
max_epochs
instance-attribute
¶
monitor_loss
instance-attribute
¶
scheduler
instance-attribute
¶
optimizer
instance-attribute
¶
tasks = None
class-attribute
instance-attribute
¶
seed = 42
class-attribute
instance-attribute
¶
early_stopping_patience = 10
class-attribute
instance-attribute
¶
training_examples_per_eval = None
class-attribute
instance-attribute
¶
deterministic = True
class-attribute
instance-attribute
¶
cpus_per_worker = None
class-attribute
instance-attribute
¶
total_accum_grad_batches
property
¶
Gradient-accumulation steps: effective_batch_size // global batch size.
__init__(*args, **kwargs)
¶
Compute the global batch size (WORLD_SIZE x batch_size) and seed everything.
Source code in kirad/launcher_utils.py
127 128 129 130 131 132 133 134 135 136 | |
ModelParams
¶
Bases: BaseModel
Validated model_params: model class path, config kwargs and checkpoint to load.
ckpt_path may be local, a W&B artifact URL or "entity/project/run:tag"; W&B ones
are downloaded. A data_params backbone_cache replaces ckpt_path (not both).
Note: restore_training_state with a local ckpt_path fails (run is undefined).
Source code in kirad/launcher_utils.py
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 | |
model_config = ConfigDict(extra='forbid', arbitrary_types_allowed=True)
class-attribute
instance-attribute
¶
model_path
instance-attribute
¶
ckpt_path = None
class-attribute
instance-attribute
¶
config = dict()
class-attribute
instance-attribute
¶
restore_training_state = False
class-attribute
instance-attribute
¶
__init__(backbone_cache=None, *args, **kwargs)
¶
Resolve ckpt_path (W&B download or backbone cache) and check restored config.
Source code in kirad/launcher_utils.py
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 | |
LauncherConfig
¶
Everything built from one YAML config; datasets and loaders are created lazily.
Source code in kirad/launcher_utils.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 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 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
experiment_dir = Path(config).expanduser().resolve().parent
instance-attribute
¶
config = config
instance-attribute
¶
experiment_name = config['experiment_name']
instance-attribute
¶
description = config['description']
instance-attribute
¶
training_params = TrainingParams(**config['training_params'])
instance-attribute
¶
model_params = ModelParams(**config['model_params'], backbone_cache=backbone_cache)
instance-attribute
¶
metadata = dict()
instance-attribute
¶
dataset = dict()
instance-attribute
¶
data_loader = dict()
instance-attribute
¶
__init__(config, experiment_dir=None)
¶
Read YAML, parse training/data/model params and instantiate the model.
experiment_dir (default: the config's folder) is added to sys.path so the experiment's model.py can be imported by model_path.
Source code in kirad/launcher_utils.py
234 235 236 237 238 239 240 241 242 243 244 245 246 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 | |
get_metadata(split)
¶
Build (once) and return the metadata object for a split.
Source code in kirad/launcher_utils.py
408 409 410 411 412 413 414 415 416 | |
get_dataset(split)
¶
StackDataset of metadata + each modality dataset for a split (built once).
Each item: {"metadata": ..., "audio": ..., "text": ...}, merged by broadcast_collate.
Source code in kirad/launcher_utils.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
get_data_loader_kwargs(split, training_mode)
¶
DataLoader kwargs: broadcast_collate, UuidSampler (shuffled + drop_last if train).
Source code in kirad/launcher_utils.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
get_data_loader(split, training_mode)
¶
DataLoader for a split (cached per split and mode); batch_size = recordings.
Source code in kirad/launcher_utils.py
464 465 466 467 468 469 470 471 472 473 474 475 476 | |
resolve_artifact_path(artifact_path)
¶
Resolve the absolute path for a file path specified in the config file.
If the file path is absolute, then return the same path (after resolving symlinks). If the file path is relative, then assume that the path is relative to the experiment directory, so prepend the experiment directory to the file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artifact_path
|
str or Path
|
Absolute or relative path to an artifact to be used by the trainer (eg. "ideal_logmel_energies.npz"). A relative path will be assumed to be relative to the experiment directory. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Absolute path (with symlinks resolved) to the artifact. |
Source code in kirad/launcher_utils.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | |
resolve_artifact_paths_in_param_dict(param_dict)
¶
Make relative string params absolute when they point to an existing file.
Resolves the absolute paths for any file path parameters in the parameter dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param_dict
|
dict
|
Mapping from parameter name to parameter value, which may or may not be a file path to some artifact. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Same format as the input parameter dictionary but with any artifact file paths resolved to be absolute. |
Source code in kirad/launcher_utils.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
get_params_by_split(all_splits_params, split, include_dataset_splits)
¶
Merge config params for one split: default < val_test (val/test) < split.
Return parameters for a given split after merging the parameters from "default" and "val_test" sections.
Parameters for a given split are set in the following order of priority: 1. parameters specified in the split-specific section 2. parameters specified in the "val_test" section if the requested split is "val" or "test" 3. parameters specified in the "default" section
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
all_splits_params
|
dict
|
A dictionary that maps "train", "val", test", "val_test", and "default" to a dictionary of parameters. |
required |
split
|
str
|
Requested split to get parameters for. Can be "train", "val", or "test". |
required |
include_dataset_splits
|
bool
|
Indicate whether to include "dataset_splits" as a parameter. Needed when
setting parameters for |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary that maps parameter names to parameter values for the requested split after merging parameters from the "default" and "val_test" sections. |
Source code in kirad/launcher_utils.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
LauncherLogger
¶
W&B run for the experiment; logs code and pandas tables as artifacts.
Source code in kirad/launcher_utils.py
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |
wandb_logger = WandbLogger(name=config['experiment_name'], save_dir=log_path, entity=entity, project=project, log_model=True, notes=config['description'], config=config)
instance-attribute
¶
run = self.wandb_logger.experiment
instance-attribute
¶
wandb_run_id = self.wandb_logger.version
instance-attribute
¶
__init__(log_path, config, entity, project)
¶
Start a WandbLogger (log_model=True uploads checkpoints) under log_path/wandb.
Source code in kirad/launcher_utils.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | |
log_code(code_path, artifact_name)
¶
Upload a source folder as the code artifact
Source code in kirad/launcher_utils.py
605 606 607 608 | |
log_table_artifacts(data)
¶
Upload {artifact: {table_name: DataFrame}} as W&B table artifacts.
Source code in kirad/launcher_utils.py
610 611 612 613 614 615 616 617 618 619 620 | |