Skip to content

feat: extend EpochMetric to support more compute_fn output types#3789

Open
zongyang078 wants to merge 7 commits into
pytorch:masterfrom
zongyang078:feature/epoch-metric-output-types
Open

feat: extend EpochMetric to support more compute_fn output types#3789
zongyang078 wants to merge 7 commits into
pytorch:masterfrom
zongyang078:feature/epoch-metric-output-types

Conversation

@zongyang078

Copy link
Copy Markdown

Fixes #1757

Description:
Extends EpochMetric to support more output types returned by compute_fn, as requested in #1757.

Previously, compute_fn could only return scalar values (int/float). This PR adds support for:

  • torch.Tensor
  • tuple / list of tensors
  • Mapping (e.g. dict) of tensors

A TypeError with a clear message is raised for unsupported output types. The existing apply_to_type utility is reused for distributed broadcasting of non-scalar results.

Check list:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

@github-actions github-actions Bot added the module: metrics Metrics module label Jun 17, 2026
Comment thread ignite/metrics/epoch_metric.py Outdated
Comment thread ignite/metrics/epoch_metric.py Outdated
Comment thread ignite/metrics/epoch_metric.py
Comment thread tests/ignite/metrics/test_epoch_metric.py

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just to be sure we also should check if the output values are as expected or correct after the computation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added value verification for all output types — each test now checks that the result matches directly calling compute_fn on the concatenated data.

@Abhisri436

Copy link
Copy Markdown

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?

@aaishwarymishra

Copy link
Copy Markdown
Collaborator

@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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: metrics Metrics module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More EpochMetric's compute_fn output types

3 participants