[PR #4326] [Benchmark] tools/strata_bench.py --compare: say what a standard report is instead of KeyError (Fix #4325) #5007

Open
opened 2026-11-07 16:31:59 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4326
Author: @XiaoBinGan
Created: 10/27/2026
Status: 🔄 Open

Base: main ← Head: fix/bench-compare-standard-report


📝 Commits (1)

  • 3fef2e8 Fix #4325: say what a standard benchmark report is, instead of KeyError: 'results'

📊 Changes

2 files changed (+37 additions, -1 deletions)

View changed files

📝 tools/strata_bench.py (+11 -1)
📝 tools/test_strata_bench.py (+26 -0)

📄 Description

Problem and result

tools/strata_bench.py --compare OLD --compare-only NEW — the comparison docs/COMMUNITY_BENCHMARKS.md names for
two saved runs — dies on a folder written by the default strata bench run suite:

Traceback (most recent call last):
  File ".../tools/strata_bench.py", line 1042, in main
    print(compare_table(load_results(Path(a.compare)), load_results(Path(a.compare_only))))
  File ".../tools/strata_bench.py", line 968, in compare_table
    a, b = summary_metrics(old["results"]), summary_metrics(new["results"])
KeyError: 'results'

Two report schemas share the file name results.json in a run folder: --suite standard-v1 (the default)
writes bench_standard.py's document with summaries, and this tool reads its own results list. After the
change the tool recognises the standard report and stops with one sentence instead of a traceback:

$ python3 tools/strata_bench.py --compare /runs/shared --compare-only /runs/exclusive
strata_bench: /runs/shared/results.json is a standard benchmark report (`strata bench run`, suite standard-v1).
This comparison reads the serving-suite reports the tool writes itself; `strata bench report /runs/shared` shows
this one. Comparing two standard runs is #4325.
$ echo $?
2

strata bench report on the same folder was always fine — the run folders are not broken, only this reader.

#4325 (filed with the same reproduction, and with what a real comparison would need). This PR
is the part that is an improvement whichever way that scope goes: it removes a traceback from a documented command
and points at the command that does work.

Approach

load_results() is the single place both comparison paths read a folder through, so the check lives there:

STANDARD_FORMAT = "strata-standard-benchmark"

def load_results(path: Path) -> dict:
    ...
    data = json.loads(p.read_text(encoding="utf-8"))
    if data.get("format") == STANDARD_FORMAT:
        print(f"strata_bench: {p} is a standard benchmark report (`strata bench run`, suite standard-v1). "
              "This comparison reads the serving-suite reports the tool writes itself; "
              f"`strata bench report {p.parent}` shows this one. Comparing two standard runs is #4325.",
              file=sys.stderr)
        raise SystemExit(2)
    return data
  • Exit 2, like the argument errors in the same main() (ap.error for --compare-only without --compare).
  • The message names the folder, what the folder is, the command that reads it, and the issue for the missing
    comparison.
  • No schema is guessed and nothing is silently converted: a wrong comparison would be worse than a clear refusal.
  • Everything else is untouched: the tool's own serving-suite reports still load, and the running-comparison path
    (--compare OLD while measuring a new run) goes through the same load_results() and behaves as before.

Validation

Passed: the end-to-end case in the image that has the bug, with the patched file mounted over the image's and two
real standard-v1 run folders (2026-10-21 shared card, 2026-10-24 exclusive card, both strata bench run from
0.2.2-cuda13):

case before after
--compare /runs/shared --compare-only /runs/exclusive KeyError: 'results' traceback the sentence above, exit 2
a serving-suite report ({"schema": 1, "results": []}) through load_results loads loads, unchanged
--compare /runs/shared (no --compare-only) argparse error, exit 2 same argparse error, exit 2

Passed: python -m unittest tools.test_strata_bench: 24 tests, OK, including the two new cases in
StandardReportIsNotAServingReport. With tools/strata_bench.py reverted the same class fails with
AssertionError: SystemExit not raised, so the test does pin the change.

Failed: none.

Not run: an actual comparison of two standard runs, which is #4325's feature and deliberately not attempted here.
Also not run: the live path that compares a finished run with one being measured now (--compare OLD without
--compare-only) — it needs a serving engine, and it calls the same load_results() I tested directly.

Limits

  • This makes the failure legible; it does not compare standard runs. If that is wanted, the natural shape is a
    per-case table from summaries (the figures strata bench report already prints), and I can write it with tests.
  • strata bench compare BASELINE CANDIDATE (the CLI command) still answers strata: unsupported benchmark report
    for a standard report. That is the same root cause on another surface; I left it alone so this PR does not touch
    the CLI's error contract without agreement.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4326 **Author:** [@XiaoBinGan](https://github.com/XiaoBinGan) **Created:** 10/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/bench-compare-standard-report` --- ### 📝 Commits (1) - [`3fef2e8`](https://github.com/Niko1221/Strata/commit/3fef2e8c585af99d6ad5b4f19e8ea49fa068086b) Fix #4325: say what a standard benchmark report is, instead of KeyError: 'results' ### 📊 Changes **2 files changed** (+37 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `tools/strata_bench.py` (+11 -1) 📝 `tools/test_strata_bench.py` (+26 -0) </details> ### 📄 Description ## Problem and result `tools/strata_bench.py --compare OLD --compare-only NEW` — the comparison `docs/COMMUNITY_BENCHMARKS.md` names for two saved runs — dies on a folder written by the **default** `strata bench run` suite: ```text Traceback (most recent call last): File ".../tools/strata_bench.py", line 1042, in main print(compare_table(load_results(Path(a.compare)), load_results(Path(a.compare_only)))) File ".../tools/strata_bench.py", line 968, in compare_table a, b = summary_metrics(old["results"]), summary_metrics(new["results"]) KeyError: 'results' ``` Two report schemas share the file name `results.json` in a run folder: `--suite standard-v1` (the default) writes `bench_standard.py`'s document with `summaries`, and this tool reads its own `results` list. After the change the tool recognises the standard report and stops with one sentence instead of a traceback: ```text $ python3 tools/strata_bench.py --compare /runs/shared --compare-only /runs/exclusive strata_bench: /runs/shared/results.json is a standard benchmark report (`strata bench run`, suite standard-v1). This comparison reads the serving-suite reports the tool writes itself; `strata bench report /runs/shared` shows this one. Comparing two standard runs is #4325. $ echo $? 2 ``` `strata bench report` on the same folder was always fine — the run folders are not broken, only this reader. ## Related discussion #4325 (filed with the same reproduction, and with what a real comparison would need). This PR is the part that is an improvement whichever way that scope goes: it removes a traceback from a documented command and points at the command that does work. ## Approach `load_results()` is the single place both comparison paths read a folder through, so the check lives there: ```python STANDARD_FORMAT = "strata-standard-benchmark" def load_results(path: Path) -> dict: ... data = json.loads(p.read_text(encoding="utf-8")) if data.get("format") == STANDARD_FORMAT: print(f"strata_bench: {p} is a standard benchmark report (`strata bench run`, suite standard-v1). " "This comparison reads the serving-suite reports the tool writes itself; " f"`strata bench report {p.parent}` shows this one. Comparing two standard runs is #4325.", file=sys.stderr) raise SystemExit(2) return data ``` - Exit 2, like the argument errors in the same `main()` (`ap.error` for `--compare-only` without `--compare`). - The message names the folder, what the folder is, the command that reads it, and the issue for the missing comparison. - No schema is guessed and nothing is silently converted: a wrong comparison would be worse than a clear refusal. - Everything else is untouched: the tool's own serving-suite reports still load, and the running-comparison path (`--compare OLD` while measuring a new run) goes through the same `load_results()` and behaves as before. ## Validation **Passed:** the end-to-end case in the image that has the bug, with the patched file mounted over the image's and two **real** standard-v1 run folders (2026-10-21 shared card, 2026-10-24 exclusive card, both `strata bench run` from `0.2.2-cuda13`): | case | before | after | | --- | --- | --- | | `--compare /runs/shared --compare-only /runs/exclusive` | `KeyError: 'results'` traceback | the sentence above, **exit 2** | | a serving-suite report (`{"schema": 1, "results": []}`) through `load_results` | loads | loads, unchanged | | `--compare /runs/shared` (no `--compare-only`) | argparse error, exit 2 | same argparse error, exit 2 | **Passed:** `python -m unittest tools.test_strata_bench`: **24 tests, OK**, including the two new cases in `StandardReportIsNotAServingReport`. With `tools/strata_bench.py` reverted the same class fails with `AssertionError: SystemExit not raised`, so the test does pin the change. **Failed:** none. **Not run:** an actual comparison of two standard runs, which is #4325's feature and deliberately not attempted here. Also not run: the live path that compares a finished run with one being measured now (`--compare OLD` without `--compare-only`) — it needs a serving engine, and it calls the same `load_results()` I tested directly. ## Limits - This makes the failure legible; it does not compare standard runs. If that is wanted, the natural shape is a per-case table from `summaries` (the figures `strata bench report` already prints), and I can write it with tests. - `strata bench compare BASELINE CANDIDATE` (the CLI command) still answers `strata: unsupported benchmark report` for a standard report. That is the same root cause on another surface; I left it alone so this PR does not touch the CLI's error contract without agreement. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5007
No description provided.