Skip to content

Add HarmonicMean metric to ignite.metrics#3649

Draft
leelakrishnaRajasimha wants to merge 1 commit intopytorch:masterfrom
leelakrishnaRajasimha:harmonic-mean-final
Draft

Add HarmonicMean metric to ignite.metrics#3649
leelakrishnaRajasimha wants to merge 1 commit intopytorch:masterfrom
leelakrishnaRajasimha:harmonic-mean-final

Conversation

@leelakrishnaRajasimha
Copy link
Copy Markdown
Contributor

Fixes #3648

This PR introduces a new metric HarmonicMean to compute the harmonic mean of input values.

Features:

  • Device support
  • Distributed training support via sync_all_reduce
  • Unit tests
  • Documentation

@github-actions github-actions bot added the module: metrics Metrics module label Mar 6, 2026
@vfdev-5 vfdev-5 marked this pull request as draft March 6, 2026 14:20
@Prathamesh8989
Copy link
Copy Markdown
Contributor

Hey @leelakrishnaRajasimha ,

Nice addition! One small thing I noticed in harmonic_mean.py within the reset() method: _num_examples is currently initialized as a Python integer (self._num_examples = 0), but it's later included in the @sync_all_reduce("_sum_reciprocal", "_num_examples") decorator used in the compute() method.

Since sync_all_reduce usually operates on tensors for distributed reduction, would it be safer to store _num_examples as a tensor on self._device for consistency with _sum_reciprocal?

For example, this could be adjusted in reset() where _num_examples is initialized.

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.

HarmonicMean metric for ignite.metrics

2 participants