Skip to content

Ensure final evaluation runs with step-based evaluation strategy#44146

Merged
SunMarc merged 24 commits intohuggingface:mainfrom
khushali9:add-eval-on-end
Mar 26, 2026
Merged

Ensure final evaluation runs with step-based evaluation strategy#44146
SunMarc merged 24 commits intohuggingface:mainfrom
khushali9:add-eval-on-end

Conversation

@khushali9
Copy link
Copy Markdown
Contributor

@khushali9 khushali9 commented Feb 19, 2026

What does this PR do?

When using a step-based evaluation strategy (IntervalStrategy.STEPS), the trainer may skip evaluation at the final step if the last step does not align with eval_steps.

This avoids missing the final evaluation while also preventing duplicate evaluations when the last step already matches eval_steps.

In short:
We now guarantee a final evaluation for step-based strategies without double-evaluating.

Fixes #43935

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.


Open with Devin

Comment thread src/transformers/trainer.py Outdated
@Rocketknight1
Copy link
Copy Markdown
Member

cc @SunMarc

Copy link
Copy Markdown
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Hey, as I commented, I think that the easier solution would be to update the callback to set should_evaluate to True at the end of the training is the user choose step

@khushali9
Copy link
Copy Markdown
Contributor Author

Hey, as I commented, I think that the easier solution would be to update the callback to set should_evaluate to True at the end of the training is the user choose step

Not able to see your comment, but I think I understood, let me update PR.

@khushali9 khushali9 requested a review from SunMarc February 20, 2026 18:31
Comment thread src/transformers/trainer_callback.py Outdated
Comment thread src/transformers/trainer_callback.py Outdated
@khushali9
Copy link
Copy Markdown
Contributor Author

@SunMarc what do you think ?

Copy link
Copy Markdown
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Thanks ! just left a couple of questions !

Comment thread src/transformers/trainer_callback.py Outdated
Comment thread src/transformers/trainer_callback.py Outdated
Comment thread src/transformers/trainer_callback.py Outdated
Comment thread src/transformers/trainer_callback.py Outdated
@khushali9
Copy link
Copy Markdown
Contributor Author

Thanks ! just left a couple of questions !

Agreed with yours asks, there were specific test failures related to some of them in CI that I had to add these many, else my first commit after your comment was just simple if and setting should_evaluate=True

@khushali9
Copy link
Copy Markdown
Contributor Author

@SunMarc I have updated PR, earlier I added condition to avoid test changes as behavior changed for some, so now I have kept logic to check simple and changed some tests. Thanks

@khushali9 khushali9 requested a review from SunMarc February 25, 2026 00:40
@khushali9
Copy link
Copy Markdown
Contributor Author

@SunMarc Any update on this ? I updated and addressed all your queries.

Copy link
Copy Markdown
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Thanks, please update the description of the PR. cc @qgallouedec @winglian wdyt ?

@SunMarc SunMarc requested review from qgallouedec and winglian March 2, 2026 17:17
@khushali9 khushali9 changed the title added eval_on_end to trainer Ensure final evaluation runs with step-based evaluation strategy Mar 2, 2026
Copy link
Copy Markdown
Member

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

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

Devin Review found 3 potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment thread src/transformers/trainer_callback.py Outdated
Comment thread tests/trainer/test_trainer_callback.py
Comment thread tests/trainer/test_trainer.py Outdated
@khushali9
Copy link
Copy Markdown
Contributor Author

@qgallouedec addressed delay issue with tests update, can you review it again. Thanks

@khushali9 khushali9 requested a review from qgallouedec March 2, 2026 23:52
@khushali9
Copy link
Copy Markdown
Contributor Author

@SunMarc how can I take this forward to merge, I did took care of @qgallouedec' all feedback.

Comment thread tests/trainer/test_trainer_callback.py Outdated
@khushali9 khushali9 requested a review from qgallouedec March 4, 2026 16:19
@khushali9
Copy link
Copy Markdown
Contributor Author

@qgallouedec how can I take this forward ? already made changes as per your feedback.

@khushali9
Copy link
Copy Markdown
Contributor Author

@SunMarc @qgallouedec how can I take this forward to merge. Thanks

@khushali9
Copy link
Copy Markdown
Contributor Author

@Rocketknight1 any help to take this forward, as it is approved and I took care of all feedbacks.

@khushali9
Copy link
Copy Markdown
Contributor Author

khushali9 commented Mar 16, 2026

@Rocketknight1 @qgallouedec @SunMarc Any help to merge this forward ? I took care of all the feedback.

@khushali9
Copy link
Copy Markdown
Contributor Author

@Rocketknight1 @SunMarc breaking test does not seem to be related to my change

@khushali9
Copy link
Copy Markdown
Contributor Author

@SunMarc @Rocketknight1 ANy update for this issue. Thanks

@khushali9
Copy link
Copy Markdown
Contributor Author

@SunMarc @qgallouedec can you please help with taking this forward to merge. Thanks

@SunMarc SunMarc enabled auto-merge March 26, 2026 14:48
@SunMarc
Copy link
Copy Markdown
Member

SunMarc commented Mar 26, 2026

merged !

@SunMarc SunMarc added this pull request to the merge queue Mar 26, 2026
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 26, 2026
@khushali9
Copy link
Copy Markdown
Contributor Author

@SunMarc thanks for trying to merge, I think it needed branch update wit main, and CI test failure were not related to my change. So if you merge now it will be successful. Thanks

@SunMarc SunMarc enabled auto-merge March 26, 2026 16:08
@SunMarc SunMarc added this pull request to the merge queue Mar 26, 2026
Merged via the queue into huggingface:main with commit ec19614 Mar 26, 2026
29 checks passed
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request Mar 27, 2026
…gingface#44146)

* rebase

* merge conflict

* merge conflict1

* merge conflict trainer

* blank space qulity run

* lint error

* modify test to address our change

* rebase

* rebase

* rebase

* rebase

* test updated with delay check

* checkpoint tests updated

* test updated in utils

* correct test condition

* style format
NielsRogge pushed a commit to NielsRogge/transformers that referenced this pull request Mar 30, 2026
…gingface#44146)

* rebase

* merge conflict

* merge conflict1

* merge conflict trainer

* blank space qulity run

* lint error

* modify test to address our change

* rebase

* rebase

* rebase

* rebase

* test updated with delay check

* checkpoint tests updated

* test updated in utils

* correct test condition

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add eval_on_end flag (analogous to eval_on_start)

5 participants