nemo_rl.experience.metric_utils#

Shared aggregation helpers for rollout metrics.

Module Contents#

Functions#

is_histogram_metric

Return whether a metric key represents raw histogram observations.

calculate_single_metric

Compute summary statistics for a metric as slash-prefixed keys.

pct

Percentile helper for buffer starvation diagnostics.

API#

nemo_rl.experience.metric_utils.is_histogram_metric(name: str) → bool[source]#

Return whether a metric key represents raw histogram observations.

nemo_rl.experience.metric_utils.calculate_single_metric(
values: collections.abc.Sequence[float | int],
batch_size: int,
key_name: str,
) → dict[source]#

Compute summary statistics for a metric as slash-prefixed keys.

Parameters:
  • values – Per-sample metric values to aggregate.

  • batch_size – Denominator for the mean (sum(values) / batch_size, not len(values)); stddev still uses len(values).

  • key_name – Prefix for the returned metric keys (e.g. “total_reward”).

Returns:

Dict mapping “{key_name}/{stat}” to its value for stat in mean, max, min, median, stddev (nan for a single value), and histogram. Histogram values remain backend-agnostic raw observations until the logger serializes them.

nemo_rl.experience.metric_utils.pct(values: collections.abc.Sequence[float | int], p: float) → float[source]#

Percentile helper for buffer starvation diagnostics.