Repository navigation
Compute aggregate metrics - #890
Merged
Merged
Conversation
Signed-off-by: George Armstrong <[email protected]>
Signed-off-by: George Armstrong <[email protected]>
Signed-off-by: George Armstrong <[email protected]>
- 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]>
Signed-off-by: George Armstrong <[email protected]>
…rics Signed-off-by: George Armstrong <[email protected]> # Conflicts: # docs/index.md # nemo_gym/rollout_collection.py
Signed-off-by: George Armstrong <[email protected]>
bxyu-nvidia
previously approved these changes
Mar 12, 2026
Signed-off-by: George Armstrong <[email protected]>
- Move aggregate-metrics docs to environment-tutorials/ - Parallelize /aggregate_metrics calls with asyncio.gather Signed-off-by: George Armstrong <[email protected]>
bxyu-nvidia
approved these changes
Mar 12, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
/aggregate_metricsroute to resources and agent serversAdds an
/aggregate_metricsHTTP route to bothSimpleResourcesServerandSimpleResponsesAPIAgent, 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_metricson 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 fromcompute_metrics()key_metrics: Headline numbers selected byget_key_metrics()Override points
Resources servers and agent servers have two hooks for custom metrics via
AggregateMetricsMixin(inreward_profile.py):compute_metrics(tasks)List[List[Dict]] → Dict[str, Any]agent_metrics.get_key_metrics(agent_metrics)Dict[str, Any] → Dict[str, Any]Why
compute_metricsinstead ofdescribe_dataframeThe original spec proposed
describe_dataframe(df: DataFrame) -> Seriesas 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:Metrics on non-numeric fields. RewardProfiler filters to numeric columns only before building the DataFrame.
majority@krequiresextracted_answer(a string) for majority voting.ArenaMetricsrequiresjudgement-gen-base(a string) for win-rate parsing. These fields are dropped beforedescribe_dataframeever sees them.Two-level aggregations.
describe_dataframeis 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_NAMEis 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.Cross-run statistics.
std_dev_across_runsrequires 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.Full-population metrics.
ArenaMetricscomputes 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 whatdescribe_dataframecould 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_metricsoverride)Same structure, but
agent_metricsincludes custom fields fromcompute_metrics()(e.g.pass@k,pass@1,majority@k) andkey_metricsis selected byget_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} ] } ]