Skip to content

Aggregation Metrics

About

d9d includes basic aggregation metrics that compute global sums and weighted means across all ranks.

Usage

1
2
3
4
5
6
7
8
import torch
from d9d.metric.impl.aggregation import SumMetric, WeightedMeanMetric

loss = WeightedMeanMetric()
loss.update(values=torch.tensor([0.5, 0.7]), weights=torch.tensor([32.0, 16.0]))

total_samples = SumMetric()
total_samples.update(torch.tensor(48.0))

API Reference

d9d.metric.impl.aggregation.SumMetric

Bases: Metric[Tensor]

Metric for the sum of input values.

__init__()

Constructs the SumMetric object.

update(value)

Adds the sum of all elements of value to the metric.

Parameters:

Name Type Description Default
value Tensor

The values to add.

required

d9d.metric.impl.aggregation.WeightedMeanMetric

Bases: Metric[Tensor]

Metric for the weighted mean of values.

accumulated_weight property

The total weight accumulated so far, as a scalar tensor.

__init__()

Constructs the WeightedMeanMetric object.

update(values, weights)

Adds values with their weights to the running mean.

Parameters:

Name Type Description Default
values Tensor

The values to average.

required
weights Tensor

The weight of each value. Must broadcast with values.

required