Skip to content

Comments

Feat/early stopping feature implementation#75

Merged
debug-soham merged 4 commits intoetsi-ai:mainfrom
Madhavi1108:feat/early-stopping
Feb 13, 2026
Merged

Feat/early stopping feature implementation#75
debug-soham merged 4 commits intoetsi-ai:mainfrom
Madhavi1108:feat/early-stopping

Conversation

@Madhavi1108
Copy link
Contributor

Fixes

Closes: #39

Type of Change

  • Bug fix
  • New feature
  • Documentation / Refactor
  • Math / Logic correction

Description

This PR adds native early stopping support to the Python API Model.train() method.

The following optional parameters are introduced:

  • early_stopping
  • patience
  • restore_best

The training loop now tracks loss per epoch, maintains a best-loss checkpoint, and stops training when the loss does not improve for a configurable number of consecutive epochs.
When enabled, the model weights from the best-performing epoch are restored after training completes.

The default behavior remains unchanged when early_stopping=False, ensuring full backward compatibility.

How Has This Been Tested?

  • Unit Tests: Not added yet
  • Manual Testing: Verified behavior using a small dummy training loop and checked that training stops after the specified patience.
  • Integration: Not applicable for this change

Screenshots / Logs

Screenshot 2026-02-11 211716 Screenshot 2026-02-11 211651

Contribution Context

  • I am contributing through the SWOC program.

@github-actions
Copy link

Thank you for opening this PR! Our automated system is currently verifying the PR requirements.
Internal Discussion: Discord

@github-actions github-actions bot added the SWoC26 Contributions specifically for the Social Winter of Code program. label Feb 11, 2026
@github-actions
Copy link

Validation Successful!

This pull request has been verified and linked to issue #39. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes.

@github-actions github-actions bot added area: python-api The user-facing Python library, Model class, and top-level CLI. feature New ML layers or API functionality. Medium Requires good codebase knowledge. labels Feb 11, 2026
Copy link
Collaborator

@Aamod007 Aamod007 left a comment

Choose a reason for hiding this comment

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

Hi @Madhavi1108! Good work on the Rust implementation. Here are the issues:

What's Wrong

Critical:

  1. Python API (etna/api.py) doesn't expose the new early_stopping, patience, restore_best parameters
  2. These parameters aren't passed to the Rust call
  3. No tests for the new feature
  4. No documentation/docstring updates

Minor:
5. Missing newline at end of optimizer.rs
6. Silent failure if model restoration fails

What to Fix

  • Add the 3 parameters to Python train() method
  • Pass them through to Rust
  • Write tests
  • Update docs

The Rust code is solid, just needs Python integration!

@github-actions
Copy link

Validation Successful!

This pull request has been verified and linked to issue #39. The system is now synchronizing metadata from the referenced issue. Kindly await maintainer review of your changes.

@github-actions github-actions bot requested a review from Aamod007 February 12, 2026 13:30
@Madhavi1108
Copy link
Contributor Author

Hi @Aamod007 ,
Thanks for suggesting the changes
I have implemented the changes based on my understanding
Any changes required do let me know
I will make them and update the docs accordingly

Copy link
Collaborator

@Aamod007 Aamod007 left a comment

Choose a reason for hiding this comment

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

Everything is good, Excellent job !

@debug-soham debug-soham merged commit 83de7ce into etsi-ai:main Feb 13, 2026
2 checks passed
@github-actions
Copy link

This PR has been successfully merged. We appreciate your effort in improving the library and look forward to your future contributions to the Etsi AI ecosystem.

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

Labels

area: python-api The user-facing Python library, Model class, and top-level CLI. feature New ML layers or API functionality. Medium Requires good codebase knowledge. SWoC26 Contributions specifically for the Social Winter of Code program.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Early Stopping with Best Model Checkpoint

3 participants