feat: extend EpochMetric to support more compute_fn output types#3789
feat: extend EpochMetric to support more compute_fn output types#3789zongyang078 wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
Just to be sure we also should check if the output values are as expected or correct after the computation.
There was a problem hiding this comment.
Added value verification for all output types — each test now checks that the result matches directly calling compute_fn on the concatenated data.
|
Hi! I’m working on issue #1757 for a course contribution and noticed this PR already covers the main source changes. I added value-checking tests on my fork for scalar tensor, vector tensor, tuple/list of tensors, and mapping outputs. These tests check the actual computed values, which seems related to the review comment about verifying output correctness. Test commit: Abhisri436@56345826 Would it be useful for me to adapt these tests into this PR or keep them as a separate reference? |
|
@Abhisri436 It's generally not a good Idea to implement the changes as an external pr until explicitly mentioned that the change if a future improvement or can be done separately :) |
|
@zongyang078 Are you panning to work on it? |
Yes, I'm planning to continue! I've reviewed PR #3802 and found several improvements worth incorporating, particularly the recursive _check_output_type method and the conservative distributed handling with NotImplementedError. I'll update this PR with these improvements shortly. |
|
The refactor has been pushed. Changes include:
Also thanks to @Abhisri436 for the discussion in #3802 — the safer distributed approach was a valuable direction to explore. |
|
Hi, thank you for the acknowledgement. I’m glad the safer distributed approach was useful. Since the latest version of #3789 now incorporates the recursive validation, status-code distributed handling, #3802 also includes permanent Could a maintainer advise on the preferred consolidation path and the appropriate way to preserve attribution for the implementation originally introduced in #3802? |
|
Hi @zongyang078 sorry, I missed your previous pushes. I think the ignite boradcast method itself checks for types in |
Hi @aaishwarymishra, you're right that broadcast() in base.py rejects Sequence/Mapping. The status-code exists because only rank 0 runs compute_fn — without it, rank 0 would hit that TypeError and exit while other ranks deadlock waiting in broadcast's safe_mode path. That said, I think the better direction is to support container outputs in distributed mode by recursively broadcasting each leaf tensor individually. Would that be welcome? |
|
@vfdev-5 what's your thoughts on it? |
Fixes #1757
Description:
Extends
EpochMetricto support more output types returned bycompute_fn, as requested in #1757.Previously,
compute_fncould only return scalar values (int/float). This PR adds support for:torch.Tensortuple/listof tensorsMapping(dict) with string keys and tensor valuesA recursive
_check_output_typemethod validates the output, including nested containers. Unsupported types raise a clearTypeError.Distributed handling (world_size > 1):
torch.Tensoroutputs are broadcast across processestuple/list/Mappingoutputs raiseNotImplementedError(single-process only for now)Tests:
Note: This iteration adopts a more conservative approach to distributed handling, with recursive type validation and NotImplementedError for non-scalar container outputs when world_size > 1.
Check list: