Repository navigation
Compute aggregate metrics - #866
gwarmstrong wants to merge 5 commits into
Conversation
Signed-off-by: George Armstrong <[email protected]>
Signed-off-by: George Armstrong <[email protected]>
Signed-off-by: George Armstrong <[email protected]>
| del result_strs | ||
|
|
||
| # Sort to ensure consistent ordering | ||
| rows.sort(key=lambda r: (r[TASK_INDEX_KEY_NAME], r[ROLLOUT_INDEX_KEY_NAME])) |
There was a problem hiding this comment.
we should be replacing the logic here with the new flow right?
There was a problem hiding this comment.
Yes. Removed the local RewardProfiler.profile_from_data + write_to_disk block entirely. _aggregate_metrics.json now replaces both _reward_profiling.jsonl and _agent_metrics.json.
| # Strip heavyweight fields before sending | ||
| stripped = [{k: v for k, v in r.items() if k not in ("response", "responses_create_params")} for r in results] | ||
|
|
||
| try: |
There was a problem hiding this comment.
can we omit this try/except pls? our metrics should always work
| server_client = self.setup_server_client() | ||
| agg_request = AggregateMetricsRequest(verify_responses=stripped) | ||
| agg_response = await server_client.post( | ||
| server_name=agent_name, |
There was a problem hiding this comment.
i think we need to for loop over all the agent names in the dataset we're running collection on
There was a problem hiding this comment.
Done. _call_aggregate_metrics now groups results by agent_ref.name and calls /aggregate_metrics once per agent. All examples are updated accordingly.
| async def verify(self, body: BaseVerifyRequest) -> BaseVerifyResponse: | ||
| pass | ||
|
|
||
| def compute_metrics(self, tasks: List[List[Dict[str, Any]]]) -> Dict[str, Any]: |
There was a problem hiding this comment.
we need to apply these functions to the agent server too right? maybe we can make a AggregateMetricsMixin class in reward_profile.py that contains the majority of this logic and can be inherited from by the base resources and agent servers?
There was a problem hiding this comment.
Done. Created AggregateMetricsMixin in reward_profile.py with compute_metrics() and get_key_metrics() hooks. Both SimpleResourcesServer and SimpleResponsesAPIAgent inherit from it.
- 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
|
Made a couple more changes that improve ergonomics outside of the scope of the review. Preserve
|
|
Moved to #890 — new branch to fix DCO sign-off (branch protection prevented force-push on this branch). |
> **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]>
> **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]>
> **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]>
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} ] } ]