Skip to content

fix: prevent once handlers from refiring on epoch termination#3790

Open
nightcityblade wants to merge 1 commit into
pytorch:masterfrom
nightcityblade:fix/issue-3625
Open

fix: prevent once handlers from refiring on epoch termination#3790
nightcityblade wants to merge 1 commit into
pytorch:masterfrom
nightcityblade:fix/issue-3625

Conversation

@nightcityblade

Copy link
Copy Markdown
Contributor

Summary

Fixes a case where Events.GET_BATCH_STARTED(once=N) could fire twice if engine.terminate_epoch(False) was called from that handler. once filters now consume matched values and each registered handler gets an independent once filter instance.

Changes

  • Make once event filters stateful so matched values are only emitted once.
  • Clone once filters per handler registration to avoid sharing consumed state between handlers.
  • Add a regression assertion to the epoch-termination event sequence test.

Testing

  • python3 -m pytest tests/ignite/engine/test_engine.py::TestEngine::test_terminate_epoch_events_sequence -q
  • python3 -m pytest tests/ignite/engine/test_custom_events.py::test_once_event_filter tests/ignite/engine/test_custom_events.py::test_custom_events_with_events_list -q
  • python3 -m pytest tests/ignite/engine/test_engine.py tests/ignite/engine/test_custom_events.py -q -m 'not distributed'

Fixes #3625

@github-actions github-actions Bot added the module: engine Engine module label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: engine Engine module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Events.GET_BATCH_STARTED(once=N) fires twice when engine.terminate_epoch(False) is called inside handler

1 participant