Make training-callback and LR-scheduler monitored metrics configurable via YAML - #85
Make training-callback and LR-scheduler monitored metrics configurable via YAML#85p-grontas wants to merge 14 commits into
Conversation
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
|
@albanpuech ready for review |
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
albanpuech
left a comment
There was a problem hiding this comment.
THANK YOU!!
just a few things to check
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip wheel | ||
| # setuptools>=83.0.0 clears PYSEC-2026-3447 |
There was a problem hiding this comment.
@romeokienzler @p-grontas Maybe for a future PR we will want to also pin the version of setuptools in the pyproject... but no need to do it now
| Note: A monitored metric name must exactly match a logged validation metric. | ||
| For example, `Validation layer_11_residual` is only produced by the | ||
| `LayeredWeightedPhysics` loss and requires a model deep enough to have a | ||
| layer index 11 (a 12-layer model). Pointing a monitor at a metric that is | ||
| never logged aborts the run once training begins. |
| patience: 100 | ||
| tol: 0 | ||
| early_stopping_monitor: Validation loss | ||
| checkpoint_monitor: Validation layer_11_residual |
There was a problem hiding this comment.
| checkpoint_monitor: Validation layer_11_residual | |
| checkpoint_monitor: Validation loss |
| patience: 100 | ||
| tol: 0 | ||
| early_stopping_monitor: Validation loss | ||
| checkpoint_monitor: Validation layer_11_residual |
There was a problem hiding this comment.
| checkpoint_monitor: Validation layer_11_residual | |
| checkpoint_monitor: Validation loss |
| patience: 100 | ||
| tol: 0 | ||
| early_stopping_monitor: Validation loss | ||
| checkpoint_monitor: Validation layer_11_residual |
There was a problem hiding this comment.
| checkpoint_monitor: Validation layer_11_residual | |
| checkpoint_monitor: Validation loss |
| patience: 100 | ||
| tol: 0 | ||
| early_stopping_monitor: Validation loss | ||
| checkpoint_monitor: Validation layer_11_residual |
There was a problem hiding this comment.
| checkpoint_monitor: Validation layer_11_residual | |
| checkpoint_monitor: Validation loss |
| lr_scheduler_monitor = getattr( | ||
| self.args.callbacks, | ||
| "lr_scheduler_monitor", | ||
| "Validation loss", |
There was a problem hiding this comment.
could use DEFAULT_MONITOR https://github.com/gridfm/gridfm-graphkit/pull/85/changes#diff-2453c8aec0e4d354dfe0c000a28790240cf2de314239087c06e01902066e3a5dR30
DEFAULT_MONITOR should be defined somewhere else than in cli in this case
otherwise, fine to not use DEFAULT_MONITOR, but it should be clear in cli.py that DEFAULT_MONITOR is not the the LR scheduler
| @@ -1,3 +1,5 @@ | |||
| default_install_hook_types: [pre-push] | |||
There was a problem hiding this comment.
If you install the pre-commit hooks (with pre-commit install), then when you git push, the pre-commit checks run and the branch is only pushed if they pass. So that the pre-commits are not forgotten and caught by the CI
|
|
||
| * [ ] **Rebase your branch onto the latest `main` before opening a PR.** | ||
| * [ ] **Sign off all commits** with the Developer Certificate of Origin (`git commit -s`). See [Developer Certificate of Origin signoff]. | ||
| * [ ] Open a PR with a short description of your changes and add Alban Puech as a reviewer. |
There was a problem hiding this comment.
| * [ ] Open a PR with a short description of your changes and add Alban Puech as a reviewer. | |
| * [ ] Open a PR with a short description of your changes. |
|
@romeokienzler JFYI |
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
|
Some comments from cc are useful: @p-grontas
|
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
|
@p-grontas Should I check again? |
albanpuech
left a comment
There was a problem hiding this comment.
Two final things
- docs/quick_start/yaml_config.md still says checkpoint_monitor is for “best-model saving and checkpointing” — slightly stale now that ModelCheckpoint only writes last.ckpt.
- Test comment in test_pipeline.py still says save-best and checkpoint “share” checkpoint_monitor.
Thank you!
Signed-off-by: Panagiotis Grontas <72163196+p-grontas@users.noreply.github.com>
|
@albanpuech Thanks, good catch! |
|
Thanks for the work @p-grontas |
Summary
Makes the validation metric monitored by the training callbacks and the LR scheduler
configurable through the YAML
callbacks:section, instead of being hard-coded to"Validation loss". Three independent keys are introduced:early_stopping_monitor— metric watched byEarlyStopping.checkpoint_monitor— metric watched by best-model saving andModelCheckpoint.lr_scheduler_monitor— metric watched by theReduceLROnPlateauscheduler.Each defaults to
Validation losswhen omitted. All are minimized (mode="min", lower isbetter); the direction is fixed and not configurable. This lets a run be driven by, e.g., a
per-layer physics residual (
Validation layer_11_residual) rather than the aggregate loss.Changes
cli.py):get_training_callbacksreadscallbacks.early_stopping_monitorand
callbacks.checkpoint_monitor, each defaulting toDEFAULT_MONITOR="Validation loss".tasks/base_task.py):ReduceLROnPlateaunow readscallbacks.lr_scheduler_monitor(previously hard-coded to"Validation loss").no-op'ing.
checkpoint_monitor— checked explicitly bySaveBestModelStateDict(training/callbacks.py):it skips the sanity-check pass, then raises
KeyErrorlisting the available metrics. Thisis the sole consumer of the key —
ModelCheckpointis configured monitor-free(
save_last=True, save_top_k=0, only writeslast.ckpt), so it no longer watches any metric.early_stopping_monitor—EarlyStopping(strict=True)(Lightning's default, now setexplicitly in
cli.py) raises when the metric is missing.lr_scheduler_monitor— theReduceLROnPlateauscheduler dict setsstrict=Trueexplicitly(
base_task.py), so Lightning raisesMisconfigurationExceptionwith the available metricsat the end of the first training epoch.
examples/config/*.yamlandtests/config/*.yaml.docs/quick_start/yaml_config.mddocuments the new keys and constraints; READMECLI tables updated.
tests/test_pipeline.pycover the config-driven wiring and thedefault fallback.
baseline updated (ignore
*.ipynb, whitelist a known false positive); CONTRIBUTING checklisttorch-scatter/torch-sparseinstall for PyTorch versions without a prebuilt PyG wheel.Formatting-only fixes applied to
integrationtests/test_base_set.py.setuptools >= 83.0.0, pinned in CI, to clear advisoryPYSEC-2026-3447.
Backward compatibility
No behavior change for existing configs: all three keys default to
Validation losswhenabsent, matching the previous hard-coded behavior.
Usage
Testing