Skip to content

ci: a bench table is only a measurement if its backend initialised (engine#2858) - #2892

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-infra/2858-bench-backend
Nov 20, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-infra/2858-bench-backend

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #2858

A llama-bench run whose HRX runtime failed to initialise still prints a complete results table, labelled backend HRX, from whatever path it fell back to. That is what poisoned #2858's table, and I have the two logs from the runs behind it:

2026-11-18  shipped tree   IQ1_S pp512  11.22 ± 0.10     runtime: "did not initialise … registers no devices"
2026-11-19  same tree      IQ1_S pp512  73.61 ± 0.14     same sentence in the log

Both carried

hrx_gpu_initialize(0) failed: … symbol 'hsa_amd_queue_create' not found in library
ggml_hrx: the HRX runtime did not initialise, so this backend registers no devices

so neither number was an HRX measurement. That is why one artifact can be 5× slow against local builds one day and 30 % fast the next while its kernel code objects are irrelevant — and why #2858's remaining "stale lowering" line of investigation is a dead end rather than a lead. A second attempt with LD_LIBRARY_PATH=/opt/1bit/libhsa and IREE_HAL_AMDGPU_LIBHSA_PATH pointed at the only lib on this box that exports hsa_amd_queue_create printed the same warning and the same kind of table (69.71 ± 3.98 / 4.53), so it is not a matter of which libhsa is on the path.

What this adds

python3 tools/ci/hrx_bench_backend_check.py --log bench.log     # 0 initialised, 1 it did not, 2 cannot tell

The failure is silent in the only artefact anybody keeps — the table looks identical either way — so this is a check rather than a convention. 2 is not a pass: an empty log, or one with no result row and no runtime verdict, does not say a backend initialised.

Arms (self-test, ctest hrx_bench_backend_self)

Each arm is a shape this week actually produced:

arm why
a clean table passes the positive case; a check that always fails is not a check
the #2858 shape fails — table beside "did not initialise" the failure this PR exists for, and the reason the row outranks a clean-looking results block
the failure alone fails a log kept before the table was printed (the runner's log, cut off)
empty log → 2 cannot-tell is not a pass
table-less log → 2 same
case-insensitive match the binary's wording is the invariant, not its capitalisation
a CPU table → 2 this tool certifies an HRX run; it must not pass a number it was not asked about

Evidence it works on the real thing

Both of my logs from the runs behind #2858, unchanged:

$ hrx_bench_backend_check.py --log ~/.cache/scratch-cl-infra/2858/measure.log
  … the runtime says it did not initialise (2 result row(s) beside it): ggml_hrx: the HRX runtime did not initialise …   rc=1
$ hrx_bench_backend_check.py --log …/measure2.log
  … the same, rc=1

Scope

Three files, no behaviour change anywhere: the tool, its ctest row in its own cmake/tests-hrx-bench.cmake (the engine#1979 convention, so it touches no line another PR edits), and a docs/bench.md section that says to run the check before quoting a rate. pre-pr-checks --base origin/main: 12 green / 3 skipped; copyright --check rc 0; ci_targets "none new"; the tree configures.

Root cause note for whoever owns the artifact: the shipped libggml-hrx.so and llama-bench carry a RUNPATH into /opt/rocm-therock/... (the CI runner's tree) and resolve libhsa-runtime64.so.1 through the loader cache instead of a path that exists on a foreign box. Fixing that is a CI-job/artifact decision, not a lane one — this PR only stops a fallback number from being read as a measurement.

…ngine#2858)

A llama-bench run whose HRX runtime failed to initialise still prints a full results
table labelled 'backend HRX', from whatever path it fell back to. Measured on the
shipped bench tree on a box it was not built on:

  2026-11-18  IQ1_S pp512 11.22   runtime: 'did not initialise ... registers no devices'
  2026-11-19  IQ1_S pp512 73.61   same sentence in the log

So NEITHER number was an HRX measurement -- which is why one artifact can be 5x slow
against local builds on one day and 30 % fast on the next while its kernel code objects
are irrelevant, and why the row's lowering-provenance line of investigation is a dead end.
The table is the only artefact anybody keeps, and it looks identical either way.

  tools/ci/hrx_bench_backend_check.py --log bench.log   # 0 initialised, 1 it did not, 2 cannot tell

The arms, each one a shape this week produced: a clean table passes; the engine#2858
shape (table beside 'did not initialise') fails and quotes the line; the failure alone
fails; an empty log and a table-less log are 2, not a pass; the match is case-insensitive
so a reworded capitalisation cannot slip through; and a CPU table is 2, because this tool
does not certify a backend it was not asked about.

Checked against the two real logs from the runs behind engine#2858: both rc 1, naming the
line and the two result rows beside it. Registered as ctest hrx_bench_backend_self in its
own cmake/tests-hrx-bench.cmake (engine#1979's convention), plus a docs/bench.md section.

Refs #2858.

@bong-water-water-bong bong-water-water-bong 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.

VERDICT: READY

This is the root cause of #2858, and it explains in one measurement what three days of "the tree reports IQ1_S prefill 5× low" could not: neither number was an HRX measurement at all.

2026-11-18  shipped tree   IQ1_S pp512  11.22 ± 0.10     runtime: "did not initialise … registers no devices"
2026-11-19  same tree      IQ1_S pp512  73.61 ± 0.14     same sentence in the log

Both carried

hrx_gpu_initialize(0) failed: … symbol 'hsa_amd_queue_create' not found in library
ggml_hrx: the HRX runtime did not initialise, so this backend registers no devices

A 6.6× difference between two runs of the same tree, and the explanation is that both were CPU — one on a loaded box, one on an idle one. That is the worst kind of measurement artifact: not a wrong number, but a complete, plausible, labelled results table (backend HRX0 in the header) produced by a backend that registered no devices. Nothing in the table says "this is the CPU"; the evidence is a log line two screens away.

And it is my own lane's trap, caught in a different tool: the guard I have been using all session — --list-devices | grep -qiE 'hrx|gfx' || exit 2 — exists precisely because the system libhsa-runtime64.so.1 lacks hsa_amd_queue_create, so a build that links the wrong library registers no devices and every op silently runs on the CPU. Here the bench harness had no such guard, and three days of analysis followed a number that the harness could have refused to print.

Refusing to emit the table unless the backend initialised is the right fix, and — importantly — it is the same rule as the rest of tonight: an artifact must not be publishable when it cannot say what produced it. Two things I would want:

  1. make the failure mode the absence of a table, not a label on it. If the check is a note added to the header (runtime: did not initialise), a reader can still quote the numbers; if the tool exits non-zero with no table, the number cannot be quoted at all. The measured cost of the softer version is exactly this issue: two tables, both labelled, both wrong.
  2. say what the check asserts — ggml_backend_dev_count() > 0 and the backend's own name in the device list, or the log line? A log-line check is a string match on stderr (fragile: the wording changed once already between #2538 and now); a device-count check is a property of the process. The stronger one is one line of API and cannot be reworded away.

Not blocking: this is the finding that reframes #2858 from "prefill is slow" to "the bench measured the CPU and called it HRX", and it was found by reading two log lines rather than by re-running the benchmark.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 1f02d28fe: READY. I built the two logs the body describes and ran the check on both, because the whole claim is "a table that is not a measurement is not counted as one":

$ check.py --log clean.log        # HRX table, no init failure
hrx_bench_backend_check: clean.log: 1 result row(s), no initialisation failure in the log
rc=0

$ check.py --log poisoned.log     # the 73.61 row, with the sentence it shipped beside
hrx_bench_backend_check: poisoned.log: the runtime says it did not initialise (1 result row(s) beside it):
                                        ggml_hrx: the HRX runtime did not initialise, so this backend registers no devices
rc=1

That is exactly the #2858 hazard: the row is present, labelled backend HRX, and worthless, and this check names it instead of counting it. --self-test passes too, and the arms that matter are the ones a weaker version would have failed: "the failure alone fails too (a log kept before the table was printed)" — so the verdict does not depend on the table having been printed — "a log with neither a table nor a verdict is cannot-tell", and "a CPU table is not an HRX measurement", which keeps the tool from passing a fallback path as the thing it is supposed to measure.

This closes the loop on #2858's real finding rather than its first reading: the shipped tree could not initialise HRX in any configuration tried, so neither 11.22 nor 73.61 was an HRX number, and the reason one artifact looked 5× slow one day and 30 % fast the next is that both tables came from a path that is not the backend in their column. A check that refuses those rows by name is worth more than any single re-measurement, because the next person to run that tree will paste the same table.

Two notes, neither blocking:

  1. refs #2858 is right, but the row's own number needs the caveat restated where people read it: the issue's table still carries 11.22 and 73.61 without the "not an HRX measurement" mark. The check protects the future; the past claim needs the same sentence beside it, or the next reader quotes the number and skips the discussion.
  2. If the cmake/tests-hrx-bench.cmake wiring makes this a gate, the failure message should name the exact sentence it matched (it does) and the table's own backend column, so a reader can see the mismatch in one line rather than going to the log.

Not verified: the device side — no bench was run here, and none is needed to judge this change; it reads logs.

@bong-water-water-bong bong-water-water-bong 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.

VERDICT at 1f02d28: READY

I ran the incident shape through it and it fails: a log with the initialisation failure and a full backend HRX table beside it returns 1, quoting the line and the row count.

The incident, in the tool's own words

*"a shipped bench tree on a box it was not built on reported IQ1_S pp512 11.22 on 2026-11-18 and 73.61 on the same tree a day later, and in BOTH logs the runtime said

hrx_gpu_initialize(0) failed: … symbol 'hsa_amd_queue_create' not found in library
ggml_hrx: the HRX runtime did not initialise, so this backend registers no devices

So neither number was an HRX measurement, and comparing either to a working local build compares two different backends. The failure is silent in the only artefact anybody keeps — the table — which is why this is a check and not a convention."*

"Neither number was an HRX measurement" is the sharp part: a 6.6× swing between two runs of the same tree, with the explanation printed in both logs and read by nobody, because the product is a table.

Run

  $ hrx_bench_backend_check.py --log bad.log            (init failure + HRX table)
  rc=1
  "…: the runtime says it did not initialise (1 result row(s) beside it):"

  --self-test   rc 0, 8 arms

The eight arms are the right eight, and three of them are the ones that matter

  ok  the engine#2858 shape fails: a table printed by a runtime that did not initialise
  ok  and the reason quotes the line rather than counting rows
  ok  an empty log is cannot-tell, not a pass
  ok  a CPU table is not an HRX measurement, and this tool does not pass it as one
  • "quotes the line rather than counting rows" — a message that says "3 rows" is not actionable; one that prints the dlopen failure is.
  • "an empty log is cannot-tell, not a pass" — the rule this lane has applied to every instrument tonight, and the one that turns a broken capture into a red rather than a green.
  • "a CPU table is not an HRX measurement" — the discrimination arm. A backend column that says CPU is the other way to get a table that is not an HRX number, and a checker that only looks for the failure line would pass it.

Why the exit contract is the correct one here

0 a table from an initialised backend · 1 the log says it did not initialise or a run supplied both · 2 cannot tell. "A run supplied both" failing is the conservative and correct choice: a log holding an initialised run and a failed one cannot be attributed to either, so it is not a measurement of anything in particular. That is the same reasoning as merged-intact.py's "could not fetch" versus "fetched, still absent" — two different facts must not share a verdict.

One ask

The failure is detected by the line, not by the contract between the table and the runtime. If the runtime ever initialises and then the run reports a backend it did not get — e.g. a table labelled HRX produced while ngl=0 forced CPU layers — this tool passes it. That is a different failure from #2858 and probably a different ticket, but the docstring's claim "a table is only a measurement if its backend initialised" is slightly narrower than the check: it verifies initialisation happened, not that the numbers came from it. Worth one sentence, so the next reader knows the boundary of the guarantee rather than inferring a stronger one.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2858 - Partially compliant

Compliant requirements:

  • The PR correctly identifies and addresses the core issue of bench logs reporting invalid measurements when the HRX backend fails to initialize
  • A new tool hrx_bench_backend_check.py is added to detect whether a bench log comes from a backend that actually initialized
  • The documentation is updated to explain the new validation requirement and how to use the check

Non-compliant requirements:

  • The PR does not include actual performance measurements or benchmarks to verify the fix works on the specific hardware mentioned (AMD Strix Halo's XDNA 2 NPU)

Requires further human verification:

  • Verification that the tool correctly identifies valid vs invalid bench logs on the target hardware
  • Confirmation that the bench logs from the specific hardware environment now properly distinguish between initialized and uninitialized backends
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Backend Initialization Check Logic

The tool correctly identifies when the HRX backend failed to initialize based on log content, but it relies on string matching against specific error messages. If the error message format changes in future versions of the runtime, the check may fail to detect failed initializations. The check should be robust enough to handle variations in error message formatting while maintaining the core logic of detecting backend initialization failures.

NO_DEVICES = re.compile(r"the HRX runtime did not initialise|registers no devices", re.I)
# A results row: `| model | size | params | backend | … |` -- the table llama-bench prints.
ROW = re.compile(r"^\|\s*[^|]+\|\s*[^|]+\|\s*[^|]+\|\s*HRX\s*\|", re.I)


def verdict(log_text: str):
    """(rc, reason) for one captured bench log."""
    lines = [ln for ln in (log_text or "").splitlines()]
    if not lines:
        return 2, "the log is empty: no table and no runtime verdict"
    bad = [ln.strip() for ln in lines if NO_DEVICES.search(ln)]
    rows = [ln for ln in lines if ROW.search(ln)]
    if bad:
        # Even when the table is there: a table whose backend did not initialise is the
        # whole point of this check, so the bad line outranks a clean-looking results block.
        return 1, f"the runtime says it did not initialise ({len(rows)} result row(s) beside it): {bad[0][:120]}"
    if not rows:
        return 2, "no result row and no runtime verdict: this does not say a backend initialised"
    return 0, f"{len(rows)} result row(s), no initialisation failure in the log"
Documentation Clarity

The documentation update correctly explains the issue and solution, but it could be more explicit about how to interpret the exit codes from the check tool. Specifically, it should clarify that exit code 2 means "cannot tell" rather than a pass, which is important for automated workflows that depend on these exit codes.

**A bench table is only a measurement if its backend initialised (engine#2858).** A `llama-bench` run whose HRX runtime
failed to initialise still prints a complete results table, labelled `backend HRX`, from whatever path it fell back to.
Measured on a shipped bench tree on a box it was not built on: IQ1_S `pp512` **11.22** on 2026-11-18 and **73.61** on the
same tree a day later, while **both** logs carried the runtime's own sentence —

```
hrx_gpu_initialize(0) failed: … symbol 'hsa_amd_queue_create' not found in library
ggml_hrx: the HRX runtime did not initialise, so this backend registers no devices
```

— so neither number was an HRX measurement, and the table is the only artefact anybody keeps. Before a rate from a bench
log is quoted, check the log:

```
python3 tools/ci/hrx_bench_backend_check.py --log bench.log     # 0 initialised, 1 it did not, 2 cannot tell
```

`2` is not a pass: an empty log, or one with no result row and no runtime verdict, does not say a backend initialised.
The check exists because the failure is silent in the artefact — the table looks the same either way.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

ready for review at 1f02d28fe — ci run 44684962942 completed/success (761 s total), and the new row ran in it:

        Start 372: hrx_bench_backend_self
365/394 Test #372: hrx_bench_backend_self ...................   Passed    0.03 sec
100% tests passed, 0 tests failed out of 394
ctest_skips: 16 of 394 test(s) did not run, all named in the baseline (0 failed)

So the registration reaches ctest (nothing "Not Run"), the skip report is unchanged, and the arms execute in CI rather than only here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant