Repository navigation
ReduceLROnPlateau: monitor val_loss like early stopping - #120
Merged
Merged
Conversation
ReduceLROnPlateau was hard-coded to monitor train_loss while EarlyStopping and ModelCheckpoint monitor val_loss. Train loss keeps decreasing while val loss plateaus, so early stopping fired before the LR was ever reduced. - TextClassificationModule gets a scheduler_monitor argument (default "train_loss", unchanged for direct users). - train() computes one monitor metric and shares it between the scheduler, ModelCheckpoint and EarlyStopping. - Warn when ReduceLROnPlateau patience (PyTorch default: 10) is not lower than patience_early_stopping (default: 3). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
meilame-tayebjee
added a commit
that referenced
this pull request
Nov 25, 2026
Follow-up to #120. TrainingConfig gets scheduler_monitor (default None: same metric as early stopping, i.e. val_loss with a validation set, train_loss otherwise). Setting it to "train_loss" keeps the previous behaviour. Asking for a val_* metric without a validation set raises a clear ValueError instead of an obscure Lightning error. Docs: document scheduler_monitor, which metric early stopping and checkpointing watch, the patience constraint with ReduceLROnPlateau (PyTorch default patience is 10), and add a ReduceLROnPlateau example. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problème
Dans
train(),ModelCheckpointetEarlyStoppingsurveillentval_loss(quand un jeu de validation est fourni), maisTextClassificationModule.configure_optimizerscodait en dur"monitor": "train_loss"pourReduceLROnPlateau.Conséquence : la train loss continue de baisser pendant que la val loss stagne, donc le LR n'est quasiment jamais réduit et l'early stopping coupe l'entraînement avant. Le commentaire qui justifiait ce choix (« val_loss pas toujours disponible ») ne tient pas : avec
interval="epoch", Lightning fait avancer le scheduler après la boucle de validation.S'y ajoute un problème de valeurs par défaut : la
patiencedeReduceLROnPlateauvaut 10 dans PyTorch, alors quepatience_early_stoppingvaut 3. Même en surveillant la bonne métrique, le LR ne serait jamais réduit.Changements
TextClassificationModuleprend un nouvel argumentscheduler_monitor(défaut"train_loss": comportement inchangé pour qui instancie le module directement, et compatible avec les anciens checkpoints).train()calcule une seule métriquemonitor(val_losssi validation, sinontrain_loss), partagée par le scheduler,ModelCheckpointetEarlyStopping.ReduceLROnPlateau(celle passée dansscheduler_params, sinon le défaut lu dans la signature du scheduler) n'est pas strictement inférieure àpatience_early_stopping.Tests
Nouveau fichier
tests/test_scheduler_monitor.py:configure_optimizers: monitor par défaut, monitor personnalisé, scheduler non-plateau ;train()avec / sans validation →val_loss/train_loss;5 de ces tests échouent sur
mainet passent avec ce correctif ;test_sample_weights.pyettest_torchTextClassifiers.pypassent toujours.🤖 Generated with Claude Code