Skip to content

Compute aggregate metrics - #890

Merged
bxyu-nvidia merged 9 commits into
mainfrom
georgea/aggregate-metrics-v2
Mar 12, 2026
Merged

bxyu-nvidia merged 9 commits into
mainfrom
georgea/aggregate-metrics-v2

Conversation

@gwarmstrong

Copy link
Copy Markdown
Contributor

Note: Continuation of #866, moved to a new branch to fix DCO sign-off (branch protection prevented force-push).

Add /aggregate_metrics route to resources and agent servers

Adds an /aggregate_metrics HTTP route to both SimpleResourcesServer and SimpleResponsesAPIAgent, enabling server-side computation of evaluation metrics after rollout collection.

What it does

After rollouts complete, the rollout collection pipeline POSTs all verify responses to /aggregate_metrics on each agent server. The agent either computes metrics itself (base agent default) or proxies to the resources server (simple_agent). The response contains three levels of metrics:

  • group_level_metrics: Per-task stats (mean/max/min/median/std per numeric field)
  • agent_metrics: Overall stats across all rollouts, plus any custom metrics from compute_metrics()
  • key_metrics: Headline numbers selected by get_key_metrics()

Override points

Resources servers and agent servers have two hooks for custom metrics via AggregateMetricsMixin (in reward_profile.py):

Hook Signature Purpose
compute_metrics(tasks) List[List[Dict]] → Dict[str, Any] Full access to all raw verify responses grouped by task. Merged into agent_metrics.
get_key_metrics(agent_metrics) Dict[str, Any] → Dict[str, Any] Select headline numbers from the final agent_metrics.

Why compute_metrics instead of describe_dataframe

The original spec proposed describe_dataframe(df: DataFrame) -> Series as the override point, where RewardProfiler passes a pandas DataFrame of numeric fields per group. This works for simple numeric aggregations but cannot express several categories of metrics that benchmarks need:

  1. Metrics on non-numeric fields. RewardProfiler filters to numeric columns only before building the DataFrame. majority@k requires extracted_answer (a string) for majority voting. ArenaMetrics requires judgement-gen-base (a string) for win-rate parsing. These fields are dropped before describe_dataframe ever sees them.

  2. Two-level aggregations. describe_dataframe is called independently per task group AND once overall. At the overall (agent) level, all rollouts are flattened into one DataFrame with task boundaries removed (TASK_INDEX_KEY_NAME is dropped). This makes it impossible to compute "average of per-task pass@k" (= mean(max(reward) per task)) because you can't recover which rollouts belong to which task. df["reward"].max() gives the global max, not the average of per-task maxes.

  3. Cross-run statistics. std_dev_across_runs requires the full N tasks × k rollouts matrix to compute per-run averages then take their standard deviation. The flat agent-level DataFrame has lost this structure.

  4. Full-population metrics. ArenaMetrics computes bootstrap confidence intervals over the entire set of pairwise comparison scores. This fundamentally cannot be decomposed into per-group-then-aggregate — it needs all scores at once in their original structure.

compute_metrics(tasks: List[List[Dict]]) receives all raw verify responses (numeric and non-numeric) grouped by task, which is a strict superset of what describe_dataframe could express. RewardProfiler still runs with its defaults to provide the baseline numeric stats.

Example output (default, no overrides)

5 tasks × 2 rollouts, all correct:

[
  {
    "agent_ref": {"name": "example_single_tool_call_simple_agent"},
    "agent_metrics": {
      "mean/reward": 1.0,
      "mean/input_tokens": 442.8,
      "mean/output_tokens": 719.8,
      "mean/total_tokens": 1162.6,
      "max/reward": 1.0,
      "max/input_tokens": 531.0,
      "max/output_tokens": 1841.0,
      "max/total_tokens": 2366.0,
      "min/reward": 1.0,
      "min/input_tokens": 316.0,
      "min/output_tokens": 202.0,
      "min/total_tokens": 518.0,
      "median/reward": 1.0,
      "median/input_tokens": 516.0,
      "median/output_tokens": 498.0,
      "median/total_tokens": 1021.5,
      "std/reward": 0.0,
      "std/input_tokens": 105.0,
      "std/output_tokens": 544.6,
      "std/total_tokens": 598.0
    },
    "key_metrics": {
      "mean/reward": 1.0,
      "mean/input_tokens": 442.8,
      "mean/output_tokens": 719.8,
      "mean/total_tokens": 1162.6
    },
    "group_level_metrics": [
      {"mean/reward": 1.0, "mean/input_tokens": 531.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 525.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 516.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 316.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 326.0, "...": "..."}
    ]
  }
]

Example output (with compute_metrics override)

Same structure, but agent_metrics includes custom fields from compute_metrics() (e.g. pass@k, pass@1, majority@k) and key_metrics is selected by get_key_metrics():

[
  {
    "agent_ref": {"name": "math_simple_agent"},
    "agent_metrics": {
      "mean/reward": 0.5,
      "max/reward": 1.0,
      "min/reward": 0.0,
      "std/reward": 0.522,
      "pass@k": 0.667,
      "pass@1": 0.5
    },
    "key_metrics": {
      "pass@k": 0.667,
      "pass@1": 0.5
    },
    "group_level_metrics": [
      {"mean/reward": 1.0, "std/reward": 0.0},
      {"mean/reward": 0.0, "std/reward": 0.0},
      {"mean/reward": 0.5, "std/reward": 0.577}
    ]
  }
]

- Remove try/except around aggregate_metrics call
- Loop over all agent names instead of just first
- Extract AggregateMetricsMixin to reward_profile.py, inherited by both
  SimpleResourcesServer and SimpleResponsesAPIAgent
- Replace local RewardProfiler flow with server-side /aggregate_metrics
- Write single _aggregate_metrics.json with nested agent_metrics structure
- Preserve response.usage through stripping for usage-based metrics

Signed-off-by: George Armstrong <[email protected]>
…rics

Signed-off-by: George Armstrong <[email protected]>

# Conflicts:
#	docs/index.md
#	nemo_gym/rollout_collection.py
@copy-pr-bot

copy-pr-bot Bot commented Mar 12, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

bxyu-nvidia
bxyu-nvidia previously approved these changes Mar 12, 2026
Comment thread nemo_gym/base_resources_server.py Resolved
Comment thread nemo_gym/rollout_collection.py Resolved
- Move aggregate-metrics docs to environment-tutorials/
- Parallelize /aggregate_metrics calls with asyncio.gather

Signed-off-by: George Armstrong <[email protected]>
@bxyu-nvidia
bxyu-nvidia merged commit 1db6818 into main Mar 12, 2026
5 checks passed
@bxyu-nvidia
bxyu-nvidia deleted the georgea/aggregate-metrics-v2 branch March 12, 2026 20:32
mahanfathi pushed a commit that referenced this pull request Mar 24, 2026
> **Note:** Continuation of #866, moved to a new branch to fix DCO
sign-off (branch protection prevented force-push).

## Add `/aggregate_metrics` route to resources and agent servers

Adds an `/aggregate_metrics` HTTP route to both `SimpleResourcesServer`
and `SimpleResponsesAPIAgent`, enabling server-side computation of
evaluation metrics after rollout collection.

### What it does

After rollouts complete, the rollout collection pipeline POSTs all
verify responses to `/aggregate_metrics` on each agent server. The agent
either computes metrics itself (base agent default) or proxies to the
resources server (simple_agent). The response contains three levels of
metrics:

- **`group_level_metrics`**: Per-task stats (mean/max/min/median/std per
numeric field)
- **`agent_metrics`**: Overall stats across all rollouts, plus any
custom metrics from `compute_metrics()`
- **`key_metrics`**: Headline numbers selected by `get_key_metrics()`

### Override points

Resources servers and agent servers have two hooks for custom metrics
via `AggregateMetricsMixin` (in `reward_profile.py`):

| Hook | Signature | Purpose |
|---|---|---|
| `compute_metrics(tasks)` | `List[List[Dict]] → Dict[str, Any]` | Full
access to all raw verify responses grouped by task. Merged into
`agent_metrics`. |
| `get_key_metrics(agent_metrics)` | `Dict[str, Any] → Dict[str, Any]` |
Select headline numbers from the final agent_metrics. |

### Why `compute_metrics` instead of `describe_dataframe`

The original spec proposed `describe_dataframe(df: DataFrame) -> Series`
as the override point, where RewardProfiler passes a pandas DataFrame of
numeric fields per group. This works for simple numeric aggregations but
cannot express several categories of metrics that benchmarks need:

1. **Metrics on non-numeric fields.** RewardProfiler filters to numeric
columns only before building the DataFrame. `majority@k` requires
`extracted_answer` (a string) for majority voting. `ArenaMetrics`
requires `judgement-gen-base` (a string) for win-rate parsing. These
fields are dropped before `describe_dataframe` ever sees them.

2. **Two-level aggregations.** `describe_dataframe` is called
independently per task group AND once overall. At the overall (agent)
level, all rollouts are flattened into one DataFrame with task
boundaries removed (`TASK_INDEX_KEY_NAME` is dropped). This makes it
impossible to compute "average of per-task pass@k" (= `mean(max(reward)
per task)`) because you can't recover which rollouts belong to which
task. `df["reward"].max()` gives the global max, not the average of
per-task maxes.

3. **Cross-run statistics.** `std_dev_across_runs` requires the full N
tasks × k rollouts matrix to compute per-run averages then take their
standard deviation. The flat agent-level DataFrame has lost this
structure.

4. **Full-population metrics.** `ArenaMetrics` computes bootstrap
confidence intervals over the entire set of pairwise comparison scores.
This fundamentally cannot be decomposed into per-group-then-aggregate —
it needs all scores at once in their original structure.

`compute_metrics(tasks: List[List[Dict]])` receives all raw verify
responses (numeric and non-numeric) grouped by task, which is a strict
superset of what `describe_dataframe` could express. RewardProfiler
still runs with its defaults to provide the baseline numeric stats.

### Example output (default, no overrides)

5 tasks × 2 rollouts, all correct:

```json
[
  {
    "agent_ref": {"name": "example_single_tool_call_simple_agent"},
    "agent_metrics": {
      "mean/reward": 1.0,
      "mean/input_tokens": 442.8,
      "mean/output_tokens": 719.8,
      "mean/total_tokens": 1162.6,
      "max/reward": 1.0,
      "max/input_tokens": 531.0,
      "max/output_tokens": 1841.0,
      "max/total_tokens": 2366.0,
      "min/reward": 1.0,
      "min/input_tokens": 316.0,
      "min/output_tokens": 202.0,
      "min/total_tokens": 518.0,
      "median/reward": 1.0,
      "median/input_tokens": 516.0,
      "median/output_tokens": 498.0,
      "median/total_tokens": 1021.5,
      "std/reward": 0.0,
      "std/input_tokens": 105.0,
      "std/output_tokens": 544.6,
      "std/total_tokens": 598.0
    },
    "key_metrics": {
      "mean/reward": 1.0,
      "mean/input_tokens": 442.8,
      "mean/output_tokens": 719.8,
      "mean/total_tokens": 1162.6
    },
    "group_level_metrics": [
      {"mean/reward": 1.0, "mean/input_tokens": 531.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 525.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 516.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 316.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 326.0, "...": "..."}
    ]
  }
]
```

### Example output (with `compute_metrics` override)

Same structure, but `agent_metrics` includes custom fields from
`compute_metrics()` (e.g. `pass@k`, `pass@1`, `majority@k`) and
`key_metrics` is selected by `get_key_metrics()`:

```json
[
  {
    "agent_ref": {"name": "math_simple_agent"},
    "agent_metrics": {
      "mean/reward": 0.5,
      "max/reward": 1.0,
      "min/reward": 0.0,
      "std/reward": 0.522,
      "pass@k": 0.667,
      "pass@1": 0.5
    },
    "key_metrics": {
      "pass@k": 0.667,
      "pass@1": 0.5
    },
    "group_level_metrics": [
      {"mean/reward": 1.0, "std/reward": 0.0},
      {"mean/reward": 0.0, "std/reward": 0.0},
      {"mean/reward": 0.5, "std/reward": 0.577}
    ]
  }
]
```

---------

Signed-off-by: George Armstrong <[email protected]>
jsw-zorro pushed a commit to niletron/Gym that referenced this pull request Apr 7, 2026
> **Note:** Continuation of NVIDIA-NeMo#866, moved to a new branch to fix DCO
sign-off (branch protection prevented force-push).

## Add `/aggregate_metrics` route to resources and agent servers

Adds an `/aggregate_metrics` HTTP route to both `SimpleResourcesServer`
and `SimpleResponsesAPIAgent`, enabling server-side computation of
evaluation metrics after rollout collection.

### What it does

After rollouts complete, the rollout collection pipeline POSTs all
verify responses to `/aggregate_metrics` on each agent server. The agent
either computes metrics itself (base agent default) or proxies to the
resources server (simple_agent). The response contains three levels of
metrics:

- **`group_level_metrics`**: Per-task stats (mean/max/min/median/std per
numeric field)
- **`agent_metrics`**: Overall stats across all rollouts, plus any
custom metrics from `compute_metrics()`
- **`key_metrics`**: Headline numbers selected by `get_key_metrics()`

### Override points

Resources servers and agent servers have two hooks for custom metrics
via `AggregateMetricsMixin` (in `reward_profile.py`):

| Hook | Signature | Purpose |
|---|---|---|
| `compute_metrics(tasks)` | `List[List[Dict]] → Dict[str, Any]` | Full
access to all raw verify responses grouped by task. Merged into
`agent_metrics`. |
| `get_key_metrics(agent_metrics)` | `Dict[str, Any] → Dict[str, Any]` |
Select headline numbers from the final agent_metrics. |

### Why `compute_metrics` instead of `describe_dataframe`

The original spec proposed `describe_dataframe(df: DataFrame) -> Series`
as the override point, where RewardProfiler passes a pandas DataFrame of
numeric fields per group. This works for simple numeric aggregations but
cannot express several categories of metrics that benchmarks need:

1. **Metrics on non-numeric fields.** RewardProfiler filters to numeric
columns only before building the DataFrame. `majority@k` requires
`extracted_answer` (a string) for majority voting. `ArenaMetrics`
requires `judgement-gen-base` (a string) for win-rate parsing. These
fields are dropped before `describe_dataframe` ever sees them.

2. **Two-level aggregations.** `describe_dataframe` is called
independently per task group AND once overall. At the overall (agent)
level, all rollouts are flattened into one DataFrame with task
boundaries removed (`TASK_INDEX_KEY_NAME` is dropped). This makes it
impossible to compute "average of per-task pass@k" (= `mean(max(reward)
per task)`) because you can't recover which rollouts belong to which
task. `df["reward"].max()` gives the global max, not the average of
per-task maxes.

3. **Cross-run statistics.** `std_dev_across_runs` requires the full N
tasks × k rollouts matrix to compute per-run averages then take their
standard deviation. The flat agent-level DataFrame has lost this
structure.

4. **Full-population metrics.** `ArenaMetrics` computes bootstrap
confidence intervals over the entire set of pairwise comparison scores.
This fundamentally cannot be decomposed into per-group-then-aggregate —
it needs all scores at once in their original structure.

`compute_metrics(tasks: List[List[Dict]])` receives all raw verify
responses (numeric and non-numeric) grouped by task, which is a strict
superset of what `describe_dataframe` could express. RewardProfiler
still runs with its defaults to provide the baseline numeric stats.

### Example output (default, no overrides)

5 tasks × 2 rollouts, all correct:

```json
[
  {
    "agent_ref": {"name": "example_single_tool_call_simple_agent"},
    "agent_metrics": {
      "mean/reward": 1.0,
      "mean/input_tokens": 442.8,
      "mean/output_tokens": 719.8,
      "mean/total_tokens": 1162.6,
      "max/reward": 1.0,
      "max/input_tokens": 531.0,
      "max/output_tokens": 1841.0,
      "max/total_tokens": 2366.0,
      "min/reward": 1.0,
      "min/input_tokens": 316.0,
      "min/output_tokens": 202.0,
      "min/total_tokens": 518.0,
      "median/reward": 1.0,
      "median/input_tokens": 516.0,
      "median/output_tokens": 498.0,
      "median/total_tokens": 1021.5,
      "std/reward": 0.0,
      "std/input_tokens": 105.0,
      "std/output_tokens": 544.6,
      "std/total_tokens": 598.0
    },
    "key_metrics": {
      "mean/reward": 1.0,
      "mean/input_tokens": 442.8,
      "mean/output_tokens": 719.8,
      "mean/total_tokens": 1162.6
    },
    "group_level_metrics": [
      {"mean/reward": 1.0, "mean/input_tokens": 531.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 525.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 516.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 316.0, "...": "..."},
      {"mean/reward": 1.0, "mean/input_tokens": 326.0, "...": "..."}
    ]
  }
]
```

### Example output (with `compute_metrics` override)

Same structure, but `agent_metrics` includes custom fields from
`compute_metrics()` (e.g. `pass@k`, `pass@1`, `majority@k`) and
`key_metrics` is selected by `get_key_metrics()`:

```json
[
  {
    "agent_ref": {"name": "math_simple_agent"},
    "agent_metrics": {
      "mean/reward": 0.5,
      "max/reward": 1.0,
      "min/reward": 0.0,
      "std/reward": 0.522,
      "pass@k": 0.667,
      "pass@1": 0.5
    },
    "key_metrics": {
      "pass@k": 0.667,
      "pass@1": 0.5
    },
    "group_level_metrics": [
      {"mean/reward": 1.0, "std/reward": 0.0},
      {"mean/reward": 0.0, "std/reward": 0.0},
      {"mean/reward": 0.5, "std/reward": 0.577}
    ]
  }
]
```

---------

Signed-off-by: George Armstrong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants