Support flexible EpochMetric compute_fn outputs#3802
Open
Abhisri436 wants to merge 3 commits into
Open
Conversation
Author
|
Hi maintainers and reviewers! I’ve added permanent I also compared the distributed behavior with the overlapping PR and found a meaningful difference in how multi-rank outputs are handled. I’ve documented the tested behavior and added regression coverage in commit I would appreciate a review when someone has time, and I’m happy to adjust or consolidate the approach if preferred. Thank you! |
3 tasks
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.
Fixes #1757
Description:
EpochMetric is currently typed and documented around scalar outputs, while issue #1757 requests support for richer compute_fn return types. My investigation also showed that unsupported values such as strings could pass through without clear validation in single-process mode.
This PR extends EpochMetric.compute_fn output handling beyond scalar values. It adds validation for supported output types including int, float, torch.Tensor, sequences, and mappings with string keys. Unsupported output types now raise a clear TypeError.
It also adds tests for scalar tensor, vector tensor, tuple/list tensor outputs, mapping outputs, and unsupported output behavior.
For distributed mode, this implementation takes a conservative approach: scalar and tensor outputs can still be broadcast, while tuple/list/mapping outputs raise a clear NotImplementedError when world_size > 1 instead of attempting unverified recursive distributed container broadcasting.
Validation:
strcould return without a clear error in single-process mode.TypeError.pytest tests/ignite/metrics/test_epoch_metric.py -vv→ 17 passed, 57 skippedWORLD_SIZE=2distributed tests with thegloobackend → 10 passedruff check ignite/metrics/epoch_metric.py tests/ignite/metrics/test_epoch_metric.py→ All checks passedruff format --check ignite/metrics/epoch_metric.py tests/ignite/metrics/test_epoch_metric.py→ 2 files already formattedNote: I saw that PR #3789 also addresses this issue. I had already selected and started working on issue #1757 before discovering the overlapping PR. I am submitting my completed branch for review and am happy to adjust this PR if maintainers prefer.