Skip to content

feat(early_stopping): rename min_delta→threshold, min_delta_mode→thre…#3619

Open
ramyars466 wants to merge 12 commits intopytorch:masterfrom
ramyars466:fix/early-stopping-param-rename
Open

feat(early_stopping): rename min_delta→threshold, min_delta_mode→thre…#3619
ramyars466 wants to merge 12 commits intopytorch:masterfrom
ramyars466:fix/early-stopping-param-rename

Conversation

@ramyars466
Copy link
Copy Markdown
Contributor

@ramyars466 ramyars466 commented Mar 2, 2026

Summary

This PR renames selected parameters of EarlyStopping to improve API clarity and align terminology with ReduceLROnPlateau, while preserving full backward compatibility.


Changes

  • Renamed:
    • min_deltathreshold
    • min_delta_modethreshold_mode
    • cumulative_deltacumulative
  • Added deprecation handling for old argument names
  • Deprecated arguments emit DeprecationWarning
  • Deprecated arguments override new ones to preserve existing behavior
  • Retained deprecated attribute names on the instance to avoid breaking user code
  • Preserved original validation error messages
  • Internal logic and behavior remain unchanged

Backward Compatibility

Backward compatibility is maintained by:

  • Accepting both new and deprecated argument names
  • Mapping deprecated arguments to new parameters before validation
  • Preserving existing error messages expected by current tests
  • Keeping deprecated attributes available on the handler instance

This ensures no behavior change for existing users.


Testing

  • All EarlyStopping handler tests pass
  • Validation behavior unchanged
  • Deprecated argument paths verified
  • No changes required to existing tests

Related

Addresses #3411

@github-actions github-actions bot added the module: handlers Core Handlers module label Mar 2, 2026
Comment on lines +135 to +137
self.min_delta = threshold
self.min_delta_mode = threshold_mode
self.cumulative_delta = cumulative
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.min_delta = threshold
self.min_delta_mode = threshold_mode
self.cumulative_delta = cumulative

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ramyars466 please address this comment

@ramyars466
Copy link
Copy Markdown
Contributor Author

Thank you for the detailed review and suggestions.

I have updated the PR accordingly:

  • Replaced Optional[...] with modern | None type hint syntax.
  • Reverted unnecessary docstring modifications and kept the original formatting style, only updating parameter names.
  • Ensured that internal logic remains unchanged to preserve behavior.
  • Kept existing validation error messages intact to avoid breaking tests.
  • Maintained full backward compatibility by:
    • Accepting deprecated arguments (min_delta, min_delta_mode, cumulative_delta)
    • Emitting DeprecationWarning when they are used
    • Ensuring deprecated arguments override the new ones
    • Preserving deprecated attribute names on the instance

All EarlyStopping tests pass locally (except distributed environment tests unrelated to this change).

Please let me know if any further adjustments are needed.

@ramyars466
Copy link
Copy Markdown
Contributor Author

@aaishwarymishra Thank you for the review.

I verified against upstream/master and confirmed that min_delta, min_delta_mode, and cumulative_delta are still the active parameter names there.

Since this PR performs the rename, I kept:

  • Deprecation handling for all renamed parameters
  • Deprecated attribute preservation (self.min_delta, etc.) to avoid breaking existing user code that may access those attributes

I have also updated the versionchanged section to explicitly document the renaming as suggested.

Please let me know if you would prefer limiting backward compatibility strictly to constructor arguments only.

@aaishwarymishra
Copy link
Copy Markdown
Collaborator

@aaishwarymishra Thank you for the review.

I verified against upstream/master and confirmed that min_delta, min_delta_mode, and cumulative_delta are still the active parameter names there.

Since this PR performs the rename, I kept:

  • Deprecation handling for all renamed parameters
  • Deprecated attribute preservation (self.min_delta, etc.) to avoid breaking existing user code that may access those attributes

I have also updated the versionchanged section to explicitly document the renaming as suggested.

Please let me know if you would prefer limiting backward compatibility strictly to constructor arguments only.

My bad, thanks

@aaishwarymishra
Copy link
Copy Markdown
Collaborator

@ramyars466 Are you still working on this pr?

@ramyars466
Copy link
Copy Markdown
Contributor Author

Yes, All the requested changes have been addressed, and the latest updates have been pushed.

Please let me know if any further modifications are needed.

@aaishwarymishra
Copy link
Copy Markdown
Collaborator

@ramyars466 I have added some comments I think you missed can you check them :)

@aaishwarymishra
Copy link
Copy Markdown
Collaborator

Also the tests needs to be modified too for the renamed parameters.

@aaishwarymishra
Copy link
Copy Markdown
Collaborator

@ramyars466 can you rename delta to threshold and update the tests which are using old names and it should be done :)

@TahaZahid05
Copy link
Copy Markdown
Collaborator

@ramyars466 are you still working on this?

@ramyars466
Copy link
Copy Markdown
Contributor Author

Yes, I am still actively working on this PR. All requested changes have already been addressed and pushed.
Currently, it is waiting for CI workflow approval from maintainers.
Please let me know if any further changes are needed.

@TahaZahid05
Copy link
Copy Markdown
Collaborator

Kindly review @aaishwarymishra last couple comments. He is suggesting that you may need to update tests with the modified parameters.

@vfdev-5
Copy link
Copy Markdown
Collaborator

vfdev-5 commented Mar 26, 2026

@ramyars466 can you please let us know if you will be able to finish this PR by today?
We are planing the release today and we would like to have this PR is in the release. If you can't, no problems, we can take over the work and finalize it from our side. Just let us know. Thanks!

@ramyars466
Copy link
Copy Markdown
Contributor Author

Hi @vfdev-5, apologies for the delayed response, and thank you for your review.

I’ve now updated the error messages in early_stopping.py to use the new parameter names (threshold, threshold_mode) as suggested. The implementation and tests are aligned with the updated API, and all relevant tests are passing without deprecation warnings.

Please let me know if anything else needs to be adjusted. Thanks again!

@vfdev-5
Copy link
Copy Markdown
Collaborator

vfdev-5 commented Mar 26, 2026

@ramyars466 there is a merge conflict with master branch to resolve please

@ramyars466
Copy link
Copy Markdown
Contributor Author

ramyars466 commented Mar 26, 2026

Hi @vfdev-5 , thank you for your review and guidance.

I’ve now resolved the merge conflicts with the latest master and restored the required imports. The implementation and tests are aligned with the updated API (threshold, threshold_mode, cumulative), and all checks (including linting) are passing successfully.

Please let me know if any further adjustments are needed.

@vfdev-5
Copy link
Copy Markdown
Collaborator

vfdev-5 commented Mar 26, 2026

@ramyars466 it remains this comment to address: #3619 (comment)

  • remove old attributes

@ramyars466
Copy link
Copy Markdown
Contributor Author

Hi @vfdev-5, thank you for the clarification.

I’ve now removed the deprecated attributes (min_delta, min_delta_mode, cumulative_delta) from the implementation and ensured that only the new parameters (threshold, threshold_mode, cumulative) are used internally.

Please let me know if anything else needs to be adjusted.

@ramyars466
Copy link
Copy Markdown
Contributor Author

ramyars466 commented Mar 27, 2026

Hi @vfdev-5 and @TahaZahid05,

I’ve addressed all the requested changes:

  • Added @Property aliases for deprecated attributes
  • Added deprecation warnings for legacy arguments and attributes
  • Updated documentation accordingly

All relevant tests are passing locally. Please let me know if anything else needs to be adjusted.

@TahaZahid05
Copy link
Copy Markdown
Collaborator

@ramyars466, I have added new review comments, but I would also like to specify that there are still some existing comments that you have not implemented:

Kindly address these past comments, and also the new review comments. Thanks for the updates!

@ramyars466
Copy link
Copy Markdown
Contributor Author

Hi @TahaZahid05,

Thank you for the detailed feedback and guidance.

I’ve now addressed all the remaining comments:

  • Removed internal usage of deprecated attributes
  • Added @property aliases (with setters) for backward compatibility
  • Added proper deprecation warnings indicating future removal
  • Added type hints for property methods
  • Added tests to verify legacy API behavior, including initialization with deprecated arguments, triggering warnings, and accessing deprecated attributes

Regarding min_delta_mode: although it has not been part of an official release, I retained it as a property alias (without internal storage) to preserve backward compatibility and to satisfy existing tests such as test_state_dict_with_mode, which expect this attribute to be accessible.

All relevant tests are passing locally. Please let me know if any further adjustments are needed.

@TahaZahid05
Copy link
Copy Markdown
Collaborator

@ramyars466 Thanks for the updates! Everything else looks fine. Regarding your comment of min_delta_mode, we treat arguments as requiring BC only if they have been part of the official release. If it hasn't, we can just update internal tests instead since the user hasn't seen the previous argument that was used.

However, we are currently in the middle of deploying a new release, and min_delta_mode will likely be included in it. Because of this, I will put this PR on hold until the release is finalized. Once it's out, your compatibility layer for min_delta_mode will officially be required anyway. Thanks for your patience!

@ramyars466
Copy link
Copy Markdown
Contributor Author

Hi @TahaZahid05,

Thank you for the clarification and update.

That makes sense regarding backward compatibility and the upcoming release. I understand the reasoning for putting the PR on hold.

I’ll wait for the release to be finalized. Please let me know if any adjustments are needed afterward.

Thanks again!

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.

5 participants