Fix CharacterErrorRate checkpoint and distributed state - #3829
Open
aswanth-07 wants to merge 2 commits into
Open
Fix CharacterErrorRate checkpoint and distributed state#3829aswanth-07 wants to merge 2 commits into
aswanth-07 wants to merge 2 commits into
Conversation
aswanth-07
force-pushed
the
fix/cer-distributed-state
branch
from
August 23, 2026 13:18
ad71802 to
63c494b
Compare
Comment on lines
+127
to
+134
| @pytest.mark.skipif(not idist.has_native_dist_support, reason="Skip if no native dist support") | ||
| @pytest.mark.usefixtures("distributed") | ||
| def test_distributed_with_empty_rank(): | ||
| cer = CharacterErrorRate() | ||
| if idist.get_rank() == 0: | ||
| cer.update((["bat"], ["cat"])) | ||
|
|
||
| assert cer.compute() == pytest.approx(1 / 3) |
Collaborator
There was a problem hiding this comment.
do we need this ?
Author
There was a problem hiding this comment.
I think we do. The regression is not only that an empty rank should avoid raising. _num_errors, _num_refs, and _num_examples must all reduce to the same global state. Checking 1 / 3 verifies that the numerator and denominator remain correct on every rank, so I kept this assertion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #3828.
CharacterErrorRatewas missing two pieces of standard Ignite metric bookkeeping:_state_dict_all_req_keys, so metric checkpoint round-trips discarded all accumulated errors, reference characters, and update state;_num_exampleslocal, causing ranks with no local batches to raiseNotComputableErroreven when other ranks had valid input.This PR declares the three existing accumulators as the metric state and includes
_num_examplesin the existing distributed sum. It does not change CER calculation or the public API.The tests cover both failure modes: a state-dict round trip retains a CER of
0.2, and a distributed test updates only rank 0 before computing collectively.Validation
pytest tests/ignite/metrics/nlp/test_character_error_rate.py -q -m "not distributed"— 18 passedpytest tests/ignite/metrics/nlp/test_character_error_rate.py -q -m distributed -k gloo_cpu— passed locally; the multi-rank CI configuration exercises the empty-rank branchpre-commit run --files ignite/metrics/nlp/character_error_rate.py tests/ignite/metrics/nlp/test_character_error_rate.py— passedpyrefly check ignite/metrics/nlp/character_error_rate.py— 0 errorsgit diff --check— passedChecklist
Disclosure: I used OpenAI Codex to assist with auditing the accumulator protocol, reproducing the state loss, and running validation. I reviewed the complete diff against the conventions used by Ignite's other accumulating metrics.