Skip to content

Add an instance-weighted (micro) suite aggregation strategy - #385

Merged
gregorybchris merged 5 commits into
mainfrom
chrisg/weighted-suite-average
Sep 24, 2026
Merged

gregorybchris merged 5 commits into
mainfrom
chrisg/weighted-suite-average

Conversation

@gregorybchris

@gregorybchris gregorybchris commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #384.

What changed

AggregationStrategy.WEIGHTED_AVERAGE weights each of a suite's leaf tasks by its instance count, matching oe-eval's "primary_metric": "micro" — sum(metric * num_instances) / sum(num_instances), as computed in oe_eval/tasks/aggregate_tasks.py. mmlu_pro, mmlu_pro:bpb and mmlu_pro:cot now use it. The 14 category tasks range from 381 to 1,351 questions, so per issue #384 the MC suite roll-up on OLMo-2-1124-7B moves from 33.02 to 30.77, against a model card figure of 31.0.

Instance counts had to reach every place a suite score is computed:

  • compute_suite_aggregations reads num_instances from the task results it already receives.
  • compute_scope_score takes a new task_instance_counts_by_name argument, keyed and ordered to match task_scores_by_name so task-hash variants collapse the same way.
  • The viewer results table selects TaskResult.num_instances and publishes a task_instance_counts map per model.
  • PairwiseResult carries model_task_instance_counts alongside model_task_scores.

A weighted suite reports its weighted mean or no score at all. When any contributing task lacks a positive instance count, the runner omits the suite aggregate and logs which tasks were missing, and the viewer and pairwise payload return None for that model's scope score. Publishing an unweighted mean under a weighted suite's name would put a different statistic behind the same label.

To keep that case rare, convert_runner_results now requires num_instances on every task it stores. The external runner always supplies an integer count for this: the number of predictions when there are any, else the benchmark's num_tasks, else 0. TaskResult.num_instances stays nullable, so results stored before this change can still lack a count.

A WEIGHTED_AVERAGE suite nested inside an AVERAGE_OF_AVERAGES parent is collapsed with its own weighting, in the runner (_compute_child_average), in the viewer (_child_scope_score), and in the runner's summary table, whose collapse check previously tested aggregation == "average" by string. No registered suite nests a weighted child today; this keeps the next one from being silently wrong.

The CLI already prints suite.aggregation.value in both olmo-eval suites and olmo-eval suite inspect, so the new strategy shows up there without further changes. README.md documents it.

Parity notes

  • mmlu_pro (5-shot MC) matches oe-eval's mmlu_pro:mc::none, which is micro. Unambiguous.
  • mmlu_pro:bpb has no oe-eval counterpart suite. Instance weighting is exactly right here anyway: the task's metric is BPBMetricInstanceAvg, so weighting each category's BPB by its instance count reproduces the bits per byte of the pooled question set.
  • mmlu_pro:cot ports the prompt of oe-eval's mmlu_pro:0shot_cot::tulu3, which macro-averages (its sampling and answer extraction follow the MMLU and GPQA CoT ports, per Add MMLU-Pro tasks (5-shot MC, 5-shot cloze, 0-shot CoT) #383's review). oe-eval's two micro CoT suites (mmlu_pro:cot::none, mmlu_pro:cot::llama3.1) are 5-shot and are not what we ported. Per Suite aggregation: add an instance-weighted (micro) average strategy #384 this suite is still weighted, so that all three MMLU-Pro suites here roll up the same way as the benchmark's own pooled reporting, but its description now names the divergence rather than claiming a parity that does not hold.

Audit of other ported suites

I enumerated oe-eval's TASK_SUITE_CONFIGS programmatically. Nineteen suites are micro: bbh:* (nine variants), bfcl_live_ast_micro::std, bfcl_live_micro::std, deepmind_math::tulu, deepmind_math::olmo3:heldout, minerva_math::llama3.1, mmlu::olmo1, and the four mmlu_pro:mc/cot suites.

MMLU-Pro is the only one that needs this strategy. We have no bbh or deepmind_math suites. Our mmlu follows mmlu:*::olmes (macro), not mmlu::olmo1. Our minerva_math follows minerva_math::olmes (macro), not ::llama3.1. BFCL (#387, merged since this PR opened) reproduces bfcl_live_ast_micro::std and bfcl_live_micro::std with the pooled tasks bfcl_live_ast and bfcl_live, which give the same number, so its suites stay as they are.

I had earlier flagged multipl_e_humaneval:olmo3base:v2 as a possible micro counterpart. That was wrong: oe-eval's multipl_e_humaneval:6lang::olmo3:n32:v2 has no primary_metric key at all, and TASK_GROUPS_RAW only admits suites that have one, so oe-eval computes no aggregate for it. Nothing to reconcile.

Testing

uv run pytest tests/ --ignore=tests/integration — 2528 passed, 30 skipped after rebasing onto current main. Lint, format, and ty check are clean apart from one pre-existing diagnostic in harness/sandbox/executor.py.

New coverage: weighted runner aggregation and the omitted aggregate when a count is missing, both flat and as a nested child under AVERAGE_OF_AVERAGES; the summary-table collapse; compute_scope_score weighting, including hash-variant collapsing and every missing-count path; the viewer results table exposing instance counts; the viewer and pairwise scope scores; convert_runner_results rejecting a task with no count; and the external runner storing results that carry no num_tasks.

Validation on a real run

Launched olmo-2-7b (allenai/OLMo-2-1124-7B) on the mmlu_pro suite at commit b14272a: beaker.org/ex/01M2RG6VM9N6PA4D3JGY0J9XEN. All 14 tasks succeeded, 12,032 instances scored, exit code 0.

task score instances
mmlu_pro_biology 59.41% 717
mmlu_pro_business 24.33% 789
mmlu_pro_chemistry 18.99% 1132
mmlu_pro_computer_science 29.76% 410
mmlu_pro_economics 45.85% 844
mmlu_pro_engineering 20.54% 969
mmlu_pro_health 38.14% 818
mmlu_pro_history 38.58% 381
mmlu_pro_law 24.16% 1101
mmlu_pro_math 17.25% 1351
mmlu_pro_other 34.20% 924
mmlu_pro_philosophy 36.27% 499
mmlu_pro_physics 21.71% 1299
mmlu_pro_psychology 53.13% 798
total 12,032

Computed from those per-task rows:

  • unweighted (macro) mean: 33.0237
  • instance-weighted (micro) mean: 30.7680

The runner's published suite aggregate was 0.3077 (mmlu_pro | Success | primary_score:average | 0.3077), so it published the weighted mean, not the unweighted one. Both figures reproduce #384 exactly: 33.02 unweighted, 30.77 micro, against a model card figure of 31.0. The 2.26-point gap is the whole point of the change, and it falls out of the spread in task sizes — 381 questions for history against 1,351 for math, with the large tasks scoring well below average.

This run covers the runner's weighted aggregation end to end. It does not cover the storage-boundary check or the viewer/pairwise read paths: it ran with --no-store because the launching machine had no AWS credentials, and --store fetches the Postgres password from AWS Secrets Manager inside the job. Those paths are covered by unit tests only.

🤖 Generated with Claude Code

@gregorybchris
gregorybchris force-pushed the chrisg/weighted-suite-average branch from 08506b4 to b14272a Compare September 17, 2026 20:10
Base automatically changed from chrisg/mmlu-pro to main September 18, 2026 21:57
@gregorybchris
gregorybchris force-pushed the chrisg/weighted-suite-average branch from b14272a to 6e67bbb Compare September 18, 2026 22:20

@gregorybchris gregorybchris left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was generated by an agent following REVIEW_GUIDE.md. It is not from a human reviewer. Reply in the PR thread and a maintainer will follow up.

Looks good overall! The weighted math is right and well tested, and the rebase left the MMLU-Pro suites consistent with the task module. One thing should be fixed before merge: the new "instance counts are required" storage check breaks persistence for external evals, which never carried a count.

I found one blocking issue and four non-blocking ones. The blocking one is a persistence regression introduced by the last commit. The others are documentation drift from that same commit and two test gaps.

Blocking

  1. src/olmo_eval/storage/base.py:181
    The external runner builds each task with "num_instances": result.metadata.get("num_tasks") (src/olmo_eval/runners/external/runner.py:303). Only some external benchmarks set num_tasks: terminal_bench and deepscholar always do, tau2 and asta only inside a success branch, and scicode never does. For those results num_instances is None, so convert_runner_results now raises. save_results catches that at src/olmo_eval/runners/io/storage.py:265, logs an error, and continues. The whole experiment is skipped from every storage backend and the run still exits normally. The external runner's failure path (runner.py:119) goes through the same _save_results, so a failed external eval's error record is dropped from storage too. That is the "error information dropped on persistence" case from section 3.4.

    I reproduced this by calling convert_runner_results on a result dict shaped exactly like the external runner's for scicode with num_instances=None: it raises ValueError: num_instances is required for task 'scicode'. On origin/main the same input converts and stores num_instances=None.

    Please make the external runner always supply an integer count before this check lands. len(result.predictions) when predictions exist, else num_tasks, else 0 would match what _write_metrics_json already does with task_data.get("num_instances") or 0 at runner.py:360. Please also add a regression test that runs an external-shaped result without num_tasks through convert_runner_results, and a direct test in tests/storage/test_base.py:265 (TestConvertRunnerResults) asserting that a missing num_instances raises.

    The silence here is a pre-existing framework fault, not this PR's: save_results swallows converter errors and the run exits 0 with nothing stored. Could you file a follow-up issue asking whether a converter failure should fail the run, or at least be reported alongside the hard-failure gate?

Non-blocking

  1. src/olmo_eval/evals/suites/registry.py:35
    The WEIGHTED_AVERAGE docstring still says "Falls back to the unweighted average when any contributing task has no instance count." The last commit removed that fallback. Since this docstring is what help(AggregationStrategy) and the next contributor will read, please change it to say the aggregate is omitted (runner) or None (viewer) when a count is missing, matching README.md:185.

  2. src/olmo_eval/runners/processing/aggregation.py:363 (and :159 for a nested child)
    When a weighted suite is omitted, the only trace is a logger.warning. The suite key is absent from results["suites"] in metrics.json, and the summary table has no row, so a reader of metrics.json cannot tell "omitted for missing counts" from "suite not requested". Today this branch is unreachable from the async runner, which always sets an integer count (src/olmo_eval/runners/asynq/results.py:451), so I am not asking for a change now. Should the omitted suite get an entry with an "error" field and no metrics, the way failed tasks do, so the omission is visible in the persisted file? A follow-up issue would be fine.

  3. tests/test_runner.py:977
    test_suite_aggregation_weighted_average_without_counts covers the flat case. The nested case (a WEIGHTED_AVERAGE child under AVERAGE_OF_AVERAGES where one leaf lacks a count, so _compute_child_average returns None and the parent averages the remaining children) is tested for compute_scope_score at tests/analysis/test_scope_scores.py:117 but not for the runner. Please add the runner counterpart so the two implementations cannot drift.

  4. PR description
    Several paragraphs describe behavior the last commit removed: "the aggregate falls back to the unweighted mean", "That fallback is decided once per scope", "scope_scores.weights_are_complete answers that question", "the viewer's aggregate tooltip says so", and the Testing section lists weights_are_complete and "the per-scope fallback". The PR body is the record of what merged, so please bring it in line with the code before merge.

Nits

  • Nit: src/olmo_eval/cli/results/viewer_server.py:570 relies on operator precedence: int(num_instances) or None if num_instances is not None else None parses as (int(x) or None) if x is not None else None. It is correct, but parentheses would save the next reader a trip to the grammar.
  • Nit: _task_weight exists in both runners/processing/aggregation.py:66 (returns 0.0 for missing) and analysis/scope_scores.py:24 (returns None for missing). Same name, different contract. Consider naming one to reflect the difference.

What I verified

  • uv run ruff check src/ tests/ clean. uv run ruff format --check clean (535 files). uv run ty check src/ alembic/ reports only the pre-existing unused type: ignore in harness/sandbox/executor.py:788. uv run pytest tests/ --ignore=tests/integration: 2402 passed, 23 skipped. All match the PR description.
  • Rebase consistency: expanded all three MMLU-Pro suites (14 tasks each) and resolved every spec through task_exists. None missing, no task name collides with a suite name. Primary metrics are LogprobMCAccuracyMetric (mmlu_pro), BPBMetricInstanceAvg (mmlu_pro:bpb), and AccuracyMetric over MMLUProCoTExactMatchScorer (mmlu_pro:cot), so the "weighting an instance-averaged BPB reproduces the pooled BPB" claim holds.
  • Weighted math: _weighted_mean uses zip(strict=True) over lists that are appended in lockstep, and _tasks_missing_instance_counts rejects <= 0 before any division, so denominators are positive. Recomputed the PR body's table: 12,032 instances, macro 33.02, micro 30.77.
  • Task identity and persisted formats: aggregation is a Suite attribute, not a TaskConfig field, so no task hash changes. convert_runner_results does not persist suites, so Postgres rows are unchanged. metrics.json suites[*].aggregation can now be "weighted_average"; the only consumer that switches on it (log_summary) was updated. PairwiseResult.model_task_instance_counts is built per request and not persisted. TaskResult.num_instances stays nullable and unchanged, so no Alembic migration is needed.
  • Hash-variant collapse in compute_scope_score: _group_model_task_scores_by_name and _group_model_task_instance_counts_by_name iterate the same columns list, and the pairwise payload's two _group_by_task_name calls iterate the same task_entries, so scores and counts align by position. zip_longest treats a length mismatch as a missing count. The "mean of variant counts" choice is documented in the docstring and tested.
  • Viewer query: func.greatest/coalesce is Postgres-only, and the repo has no SQLite path. The pairwise path already recovers counts from predictions in _update_task_rows_num_instances, so the two surfaces agree.
  • Runner: asynq/results.py:451 always writes an integer num_instances, including for failed tasks, so the "omit the aggregate" branch is reachable only from hand-built or imported result dicts.

Before merge

Fix Blocking 1 (external runner supplies a count; regression tests for the converter) and update the registry.py docstring and the PR description. Please file the two follow-up issues named above (converter failures surfacing; omitted weighted suites leaving a trace in metrics.json). After that you may merge once CI is green.

Comment thread src/olmo_eval/storage/base.py Resolved
Comment thread src/olmo_eval/evals/suites/registry.py Resolved
gregorybchris and others added 4 commits September 23, 2026 10:41
oe-eval suite configs support "primary_metric": "micro", an instance-count
weighted mean across a suite's tasks, and several benchmarks are reported
that way. MMLU-Pro is the first port where it matters: its 14 category
tasks range from 381 to 1,351 questions, so the unweighted suite average
sits about two points above the micro average oe-eval publishes.

AggregationStrategy.WEIGHTED_AVERAGE weights each leaf task by its
instance count. Instance counts now travel alongside task scores from
results storage into the viewer results table and the pairwise payload so
the displayed aggregate matches what the runner writes. When any
contributing task has no usable count the aggregate falls back to the
unweighted mean rather than mixing weighted and unweighted terms.

mmlu_pro, mmlu_pro:bpb and mmlu_pro:cot now use the new strategy.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The viewer and the pairwise payload decided the unweighted fallback once
per model, so one comparison column could hold a micro average for a run
with instance counts beside a macro average for a run without them. The
decision is now made once per scope: if any compared run is missing a
count, none of them are weighted, and the viewer's aggregate tooltip says
so. scope_scores.weights_are_complete answers that question for a scope.

A WEIGHTED_AVERAGE suite nested inside an AVERAGE_OF_AVERAGES parent was
collapsed with an unweighted mean of its leaves in both the runner and
the viewer, and the runner's summary table did not collapse its task rows
at all. All three now recognize the strategy.

mmlu_pro:cot ports oe-eval's mmlu_pro:0shot_cot::tulu3, which
macro-averages; the micro CoT suites there are 5-shot and are not what we
ported. Its description now names that divergence instead of claiming a
parity that does not hold. mmlu_pro:bpb says why instance weighting is
exact for an instance-averaged metric.

Also documents WEIGHTED_AVERAGE in the README, and zips the unfiltered
weight list in _weighted_mean so a length mismatch cannot silently pair
values with the wrong weights.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The fallback let one suite name mean two different statistics depending on
what happened to be stored, and nothing downstream could tell which one it
was looking at. A weighted suite now reports its instance-weighted mean or
no score at all: the runner omits the aggregate and logs the tasks that
lacked a count, and compute_scope_score returns None.

Counts are now guaranteed rather than hoped for. build_eval_result rejects
a task result with no num_instances, the way it already rejects one with
no task_hash, and the viewer's results-table query recovers a missing
count from the saved predictions the way the pairwise query already does.

This removes weights_are_complete and the per-scope use_instance_weights
plumbing from both viewer surfaces.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The external runner now always stores an integer instance count, so the
storage check that requires one no longer drops external results that
lack `num_tasks`. The viewer's two task-grouping helpers are merged into
one, and the WEIGHTED_AVERAGE docstring describes the current behavior
when a count is missing.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@gregorybchris
gregorybchris force-pushed the chrisg/weighted-suite-average branch from 6e67bbb to 402b0ab Compare September 23, 2026 17:41
@gregorybchris

Copy link
Copy Markdown
Collaborator Author

@mgmorgan23 could I please request your re-review when you get a chance?

@mgmorgan23 mgmorgan23 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@gregorybchris
gregorybchris enabled auto-merge (squash) September 24, 2026 20:21
@gregorybchris
gregorybchris merged commit 3176dab into main Sep 24, 2026
10 checks passed
@gregorybchris
gregorybchris deleted the chrisg/weighted-suite-average branch September 24, 2026 20:28
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.

Suite aggregation: add an instance-weighted (micro) average strategy

2 participants