feat(early_stopping): add get_default_score_fn and get_default_event_filter helpers (#3411)#3745
Draft
MukundaKatta wants to merge 1 commit intopytorch:masterfrom
Draft
Conversation
…filter helpers Adds two helper methods to EarlyStopping mirroring patterns in Checkpoint and the maintainer's preferred design from the issue thread: - EarlyStopping.get_default_score_fn(metric_name, score_sign=1.0): a static helper that builds a score_function reading engine.state.metrics[metric_name] and applying score_sign (use -1.0 for error-like metrics). - EarlyStopping.get_default_event_filter(after): an instance method that returns a (engine, event) -> bool filter consulting the trainer's epoch counter, so callers can implement a warmup window via Events.COMPLETED( event_filter=handler.get_default_event_filter(after=N)) without coupling the warmup logic to the handler. Uses the trainer epoch (not the host engine's event count) so the warmup is well-defined when the handler is attached to an evaluator that re-runs from scratch each epoch. Both helpers are additive with backwards-compatible defaults and do not change any existing public behavior. Closes part of pytorch#3411
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.
Summary
Closes part of #3411. Two enhancements explicitly suggested by maintainer @vfdev-5 in the issue thread:
EarlyStopping.get_default_score_fn— analogous toCheckpoint.get_default_score_fn, supportsscore_sign=-1.0for error-like metrics.EarlyStopping.get_default_event_filter— events filtering helper for warmup that consultsself.trainer.state.epoch(fixes the gotcha that evaluators reset their epoch counter on eachrun()).The maintainer pushed back on PR #3661's
min_evalsparameter and explicitly preferred event filtering, which is why this PR ships the filter helper instead.Files
ignite/handlers/early_stopping.py(+88) — both helpers, additive, BC-safe.tests/ignite/handlers/test_early_stopping.py(+136) — 9 new tests covering positive/negative sign, invalid sign, integration withmode="min", invalidafter, zero/non-zero warmup, full engine integration, and attach signature compatibility.Test plan
ruff check+ruff format --checkclean.