Skip to content

Do not train another epoch when resuming a run that was stopped early - #6865

Merged
mergify[bot] merged 2 commits into
espnet:masterfrom
antonsoo:fix/resume-after-early-stopping
Oct 9, 2026
Merged

mergify[bot] merged 2 commits into
espnet:masterfrom
antonsoo:fix/resume-after-early-stopping

Conversation

@antonsoo

@antonsoo antonsoo commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

What did you change?

Trainer.run checks the restored reporter for early stopping before entering the epoch loop. If the current patience is already exhausted, it skips training and still runs final model averaging. Increasing or disabling patience allows training to continue.


Why did you make this change?

Recipe scripts pass --resume true. After a run stops early, repeating the same training command currently trains and saves one extra epoch before checking patience again. Each restart adds another epoch.

Reproduced with the stock Trainer and a small Conformer/RNN transducer using the native warp-transducer loss, log-mel speech features and Adam. It trained on two public LibriSpeech recordings and validated on two different recordings (21.175 seconds total). Validation loss reached its minimum at epoch 13 and worsened at epochs 14 and 15, so patience=1 stopped training naturally.

Run Current master This PR
Initial early stop epoch 15, 30 optimizer steps same saved checkpoint
First restart epoch 16, 32 steps epoch 15, 30 steps
Second restart epoch 17, 34 steps epoch 15, 30 steps

With this change, both restarts leave checkpoint.pth byte-for-byte unchanged. On master, the second restart changes 56 trainable parameter tensors (maximum absolute change 0.04975). Increasing patience from 1 to 4 resumes epochs 16-18 with this change, as intended. The best-two averaged model stayed unchanged in this experiment on both versions; this is a restart/checkpoint correctness check, not an accuracy improvement claim.

The regression tests use a tiny constant-loss model to reproduce the same restart behavior quickly and check that a larger patience still continues training.


Is your PR small enough?

Yes. Eleven source lines and one test file. The test setup supplies TrainerOptions, whose fields have no defaults.


Additional Context

  • Reuses the same Reporter.check_early_stopping call as the end of an epoch. No new checkpoint state or format change.
  • The real-speech run used CPU and one process. GPU and distributed resume were not exercised.
  • pytest --no-cov --execution-timeout=10 test/espnet2/train/test_reporter.py test/espnet2/train/test_trainer.py: 38 passed. The new repeated-resume test fails on current master. Pre-commit and CI flake8 checks pass.

@github-actions github-actions Bot added this to the v.202612 milestone Oct 9, 2026
@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: espnet/espnet/.coderabbit.yaml
  • Review profile: QUIET
  • Plan: Advanced
  • Run ID: 05df03b8-1d14-49a3-893f-afa66f40b7dc

📥 Commits

Reviewing files that changed from the base of the PR and between 30bc270 and 9ae32e2.


📒 Files selected for processing (2)
  • espnet2/train/trainer.py
  • test/espnet2/train/test_trainer.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.



📝 Walkthrough

Walkthrough

When training resumes after epoch 1, Trainer.run checks the early-stopping condition if patience is configured and the required criterion values are available. If the condition is met, it advances start_epoch past max_epoch, skipping the training loop. Tests cover resuming with unchanged patience and with increased patience.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: copilot


Merge Risk: ⚪ Minimal · up to 9ae32

The change appears ready to merge after normal checks; no actionable resume-time risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check Passed The description clearly explains the Trainer.run change, its purpose, expected resume behavior, test coverage, and validation results. It is directly related to the changeset.
Title check Passed The title clearly and concisely describes the main change: preventing an additional training epoch when resuming after early stopping.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.


  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.47%. Comparing base (79e22b5) to head (b0070a2).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6865   +/-   ##
=======================================
  Coverage   74.47%   74.47%           
=======================================
  Files         910      910           
  Lines       83766    83768    +2     
=======================================
+ Hits        62381    62386    +5     
+ Misses      21385    21382    -3     
Flag Coverage Δ
test_configuration_espnet2 26.70% <0.00%> (-0.01%) ⬇️
test_integration_espnet2 48.80% <50.00%> (+<0.01%) ⬆️
test_integration_espnet3 31.54% <0.00%> (-0.01%) ⬇️
test_python_espnet2 62.10% <100.00%> (+0.02%) ⬆️
test_python_espnet3 22.81% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sw005320 sw005320 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks, @antonsoo!

@sw005320 sw005320 added the auto-merge Enable auto-merge label Oct 9, 2026
@mergify

mergify Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@sw005320 sw005320 added the Bugfix label Oct 9, 2026
@mergify
mergify Bot merged commit fff2068 into espnet:master Oct 9, 2026
79 checks passed
@sw005320 sw005320 modified the milestones: v.202612, v.202611 Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants