Skip to content

Add min_delta_mode parameter to EarlyStopping and update logic for sc…#3516

Merged
vfdev-5 merged 4 commits intopytorch:masterfrom
aaishwarymishra:feature_early-stopping
Feb 6, 2026
Merged

Add min_delta_mode parameter to EarlyStopping and update logic for sc…#3516
vfdev-5 merged 4 commits intopytorch:masterfrom
aaishwarymishra:feature_early-stopping

Conversation

@aaishwarymishra
Copy link
Copy Markdown
Collaborator

@aaishwarymishra aaishwarymishra commented Feb 5, 2026

This pull request enhances the EarlyStopping handler in ignite/handlers/early_stopping.py by introducing a new parameter to control how min_delta is interpreted, allowing users to specify whether the minimum improvement threshold should be considered as an absolute or relative increase. This makes early stopping more flexible and suitable for a wider range of training scenarios.

Early stopping configuration improvements:

  • Added a new min_delta_mode parameter (with options "abs" or "rel") to the EarlyStopping class, allowing users to specify whether min_delta is treated as an absolute or relative improvement. Default is "rel". [1] [2]
  • Updated the constructor to validate the min_delta_mode argument and store it as an instance attribute. [1] [2]
  • Modified the early stopping logic in __call__ to compute the improvement threshold based on the selected min_delta_mode.

Type annotation updates:

  • Updated type annotations to import Literal from typing for the new parameter.

Part of issue #3411

@github-actions github-actions bot added the module: handlers Core Handlers module label Feb 5, 2026
@aaishwarymishra
Copy link
Copy Markdown
Collaborator Author

aaishwarymishra commented Feb 5, 2026

The pytest and tests look very scary. Anyways, I could also refactor type annotations for these file in this pr if its fine.

@aaishwarymishra aaishwarymishra marked this pull request as ready for review February 5, 2026 17:55
@aaishwarymishra aaishwarymishra marked this pull request as draft February 6, 2026 08:09
@aaishwarymishra aaishwarymishra marked this pull request as ready for review February 6, 2026 08:32
@vfdev-5
Copy link
Copy Markdown
Collaborator

vfdev-5 commented Feb 6, 2026

…arify absolute and relative increase thresholds
Copy link
Copy Markdown
Collaborator

@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks !

@vfdev-5 vfdev-5 added this pull request to the merge queue Feb 6, 2026
github-merge-queue bot pushed a commit that referenced this pull request Feb 6, 2026
#3516)

This pull request enhances the `EarlyStopping` handler in
`ignite/handlers/early_stopping.py` by introducing a new parameter to
control how `min_delta` is interpreted, allowing users to specify
whether the minimum improvement threshold should be considered as an
absolute or relative increase. This makes early stopping more flexible
and suitable for a wider range of training scenarios.

**Early stopping configuration improvements:**

* Added a new `min_delta_mode` parameter (with options `"abs"` or
`"rel"`) to the `EarlyStopping` class, allowing users to specify whether
`min_delta` is treated as an absolute or relative improvement. Default
is `"rel"`.
[[1]](diffhunk://#diff-90b35f252a4f1589bd64e544cc0fa83f556b0ae987d0f625cf66aa74df7ffcbfR23-R24)
[[2]](diffhunk://#diff-90b35f252a4f1589bd64e544cc0fa83f556b0ae987d0f625cf66aa74df7ffcbfR54)
* Updated the constructor to validate the `min_delta_mode` argument and
store it as an instance attribute.
[[1]](diffhunk://#diff-90b35f252a4f1589bd64e544cc0fa83f556b0ae987d0f625cf66aa74df7ffcbfR68-R70)
[[2]](diffhunk://#diff-90b35f252a4f1589bd64e544cc0fa83f556b0ae987d0f625cf66aa74df7ffcbfR79-R90)
* Modified the early stopping logic in `__call__` to compute the
improvement threshold based on the selected `min_delta_mode`.

**Type annotation updates:**

* Updated type annotations to import `Literal` from `typing` for the new
parameter.

Part of issue #3411
Merged via the queue into pytorch:master with commit 2f75787 Feb 6, 2026
25 of 27 checks passed
i.e. an increase of less than or equal to the minimum delta threshold (as determined by min_delta and min_delta_mode), will count as no improvement.
cumulative_delta: It True, `min_delta` defines an increase since the last `patience` reset, otherwise,
it defines an increase after the last event. Default value is False.
min_delta_mode: Determine whether `min_delta` is an absolute increase or a relative increase.
Copy link
Copy Markdown
Collaborator

@vfdev-5 vfdev-5 Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaishwarymishra I forgot, we should update the docstring with .. versionchanged:: directlve for the new arg. For example:

.. versionchanged:: 0.4.5
``y_pred`` and ``y`` can be torch tensors or list of tensors/numbers

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add all the changes in docs together in next pr if it sounds good?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: handlers Core Handlers module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants