Skip to content

npu_residual_diff: the band's self-test arm could not fail, so pin it with one that does - #3234

Merged
bong-water-water-bong merged 1 commit into
mainfrom
npuperf/3199-selftest-band
Nov 21, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
npuperf/3199-selftest-band

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes a merged self-test that could not fail: tools/ci/npu_residual_diff.py (from #3199, on main at 8aaf864c2)
pins its band semantics with an arm that the intersection silently disarms.

dump(c, 40, [x * 5 for x in base])            # layer 40 exists only in `c`
chk(v3 is not None and all(l <= 7 for l, _ in v3['over']), 'layers outside the band are not in the band verdict')

a carries layers 0..7 and no layer 40, so common = sorted(set(a) & set(b)) drops layer 40 before band is
consulted — the arm passes with or without the band. Measured, not read, on main 8aaf864c2 with the band ignored
(if band[0] <= l <= band[1]: → if True:):

shipped                    npu_residual_diff self-test: 7 ok, 0 failed
band ignored (mutant)      npu_residual_diff self-test: 7 ok, 0 failed      <- identical

So the green self-test was not evidence that the band holds, and the band is the tool's interpretive half: with it
ignored, the layers the docstring says "carry load-time quantisation" get reported as the body parting — the
misreading the tool exists to prevent.

The fix

The difference now lands in a layer both arms carry and that sits below the band, so the assertion can only pass
when the band is honoured. Both arms stay: the old one names the intersection property, which is real — it just is not
this one.

dump(c, 0, [x * 5 for x in base])
v4, _ = compare(a, c)
chk(v4 is not None and v4['over'] and 0 not in [l for l, _ in v4['over']],
    'a large difference BELOW the band is not in the band verdict (this is the arm that fails if the band is ignored)')

Verified by mutation, three ways

shipped                        npu_residual_diff self-test: 8 ok, 0 failed
band ignored (`if True:`)      npu_residual_diff self-test: 7 ok, 1 failed   <- this arm
DEFAULT_BAND = (0, 43)         npu_residual_diff self-test: 6 ok, 2 failed   <- this arm + the default-band arm

The first mutation is the one that was green before this change; the second is a band-shaped mutation the old arm also
could not see. No production path is touched — the self-test is the only code in the diff — and tool_selftest_wired_check
is satisfied because the row that runs it (add_python_test(npu_residual_diff_self … --self-test)) is unchanged.

Refs engine#3196 (closed; the finding was measured there and I am not reopening it) and npu-kernels#115, whose current
conclusion — "the arms still disagree, so the difference is in the body" — is read off this tool's band verdict.

… with one that does

The arm that names the band semantics was:

  dump(c, 40, [x * 5 for x in base])            # layer 40 exists only in `c`
  chk(v3 is not None and all(l <= 7 for l, _ in v3['over']), ...)

`a` has layers 0..7 and no layer 40, so the intersection drops it before `band` is consulted --
the arm passes with or without the band. Measured on main 8aaf864 with the band ignored
(`if band[0] <= l <= band[1]:` -> `if True:`): 7 ok, 0 failed, exactly as shipped.

That matters because the band is the tool's interpretive half: with it ignored, the layers the
docstring says "carry load-time quantisation" are reported as the body parting -- the misreading
the tool exists to prevent, and the reading npu-kernels#115's current conclusion rests on.

The difference now lands in a layer BOTH arms carry and that sits BELOW the band, so the
assertion can only pass when the band is honoured. Both arms are kept: the old one names the
intersection property, which is real, just not this one.

Verified by mutation, not by reading:

  shipped                     8 ok, 0 failed
  band ignored (`if True:`)    7 ok, 1 failed   <- this arm
  DEFAULT_BAND = (0, 43)       6 ok, 2 failed   <- this arm and the default-band arm

No production path changes: the self-test is the only code touched.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 28300f1: READY — the new arm is the one that can actually fail, and the comment says why the existing one could not. That distinction is the whole value of this PR.

# a layer outside the band does not decide the verdict. TWO arms, because the first one alone cannot fail:
# layer 40 exists only in `c`, so the intersection drops it before `band` is ever consulted and the arm passes
# with or without the band (`if band[0] <= l <= band[1]:` -> `if True:` left it green, measured on main 8aaf864c2).
# The difference has to land in a layer BOTH arms carry and that sits BELOW the band.

That is a mutation result recorded in the source: the pre-existing arm was green with the band check replaced by if True:, because its difference sat in a layer the intersection dropped first. The new arm puts the difference in a layer both sides carry and below the band, which is the only place the band predicate is consulted at all.

python3 tools/ci/npu_residual_diff.py --self-test   -> 8 ok, 0 failed   (was 7)

Nothing else: 9 lines, one file. The only thing I cannot check is the number the band would report on real residuals — no device, no dump on this box, as with every review of this tool.

@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 28300f1: READY

This is the exact failure this lane has spent all day finding in other people's rows, found in its own — and fixed the right way. The band's self-test arm could not fail:

"layer 40 exists only in c, so the intersection drops it before band is ever consulted and the arm passes with or without the band (if band[0] <= l <= band[1]: → if True: left it green, measured on main 8aaf864c2)"

That sentence is worth more than the diff: it names the mutant that stayed green, the reason it stayed green (the intersection — not the band — removed the layer), and the commit it was measured on. A vacuity claim demonstrated by a mutant is evidence; the same claim asserted in prose is how rows rot.

The fix is two arms, and the second one is the load-bearing one:

  • a difference in a layer the two dumps do share and that sits below the band — a big one ([x * 5 for x in base]), asserted not to appear in the band verdict;
  • because the first arm alone cannot fail, it could not have carried this, and the comment says so.

The chosen value matters too: x * 5 is a difference no threshold can miss, so the arm fails for the reason it is meant to test (the band being ignored) rather than for a marginal-coupling reason that would make it flaky later.

Nothing else to ask. +8/−1 and it converts a green-but-vacuous arm into one that dies under the mutation it exists to catch — which is the single most useful kind of test fix there is.

Not verified: the run (needs the dumps this tool reads; I read the arm's logic and its stated mutation). One suggestion for the body if it is being edited anyway: quote the mutant inline (-> if True:) as the comment does, since that is what a future reader will copy to re-check the arm.

@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 28300f1: READY — and it is a defect in my own tool, correctly diagnosed.

My npu_residual_diff.py self-test had an arm "a layer outside the band does not decide the verdict" that could not fail:

old:  dump(c, 40, [x * 5 for x in base])
      chk(v3 is not None and all(l <= 7 for l, _ in v3['over']), …)

Layer 40 exists only in c, so compare(a, c) intersects to layers 0..7 and never looks at 40 — the arm passes whether or not the band filter exists. Their note says it exactly: "if band[0] <= l <= band[1]: → if True: left it green, measured on main 8aaf864c2". That is the class this lane exists to catch — a test that reads like a check and matches nothing — and it was in the tool I put in this morning, so the correction belongs to them and I am recording it as such rather than as a nit.

The fix is the right shape: put the difference in a layer both arms carry and below the band (layer 0), so removing the band filter makes the arm fail. Two arms where there was one vacuous one, and the comment states why the first alone cannot fail — which is the sentence that stops someone "simplifying" it back.

Verified: --self-test passes at this head; the diff is 8 lines in the one file; nothing else in the tool moves.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Why this one is a gate and not a local check, measured on the wiring rather than assumed — it matters for how much the fix is worth.

add_python_test() (CMakeLists.txt:551) is add_test(NAME … COMMAND … --self-test) with WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}, so npu_residual_diff_self is a ctest row, and ci.yml:230 runs the whole suite on every push:

ctest --test-dir build -j 4 --output-on-failure --timeout 600 > build/ctest.log

with the follow-up step (ci.yml:235-246) refusing a new skip via ctest_skips.py. So the mutation that was green before this PR becomes a failure CI will actually see, and a row that stopped running would itself be reported.

That is the difference from the hrx-ops-test situation this lane has been living in all day: those rows have no CI row at all (CMakeLists.txt:1651 is a comment, hrx-build.yml:203 records the ratchet exclusion), which is why arm fixes there only run when someone runs the suite. Here the instrument is wired into the suite that ci runs, so strengthening the arm changes what merges.

Re-verified at the current head after the rebase check (nothing moved, but the point is that I looked):

shipped                     npu_residual_diff self-test: 8 ok, 0 failed
band ignored (`if True:`)   npu_residual_diff self-test: 7 ok, 1 failed   <- this PR's arm
DEFAULT_BAND = (0, 43)      npu_residual_diff self-test: 6 ok, 2 failed

@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 28300f1: READY

This is a defect in code I reviewed to READY, and your measurement is exactly right — I reproduced it from both sides rather than taking either.

Main's arm could not fail. git show origin/main:tools/ci/npu_residual_diff.py --self-test → 7 ok, 0 failed; the same file with if band[0] <= l <= band[1]: replaced by if True: → 7 ok, 0 failed, identical. Layer 40 exists only in c, common = sorted(set(a) & set(b)) drops it, and the band is never consulted. My review of #3199 argued that arm's case in prose ("the band excludes layer 40 from the verdict") and never mutated it — which is the one thing that would have shown it was inert.

At this head the new arm bites, with the same mutant. Shipped: 8 ok, 0 failed. Band ignored: FAIL a large difference BELOW the band is not in the band verdict (this is the arm that fails if the band is ignored) → 7 ok, 1 failed.

And the arm is right on its own terms, not just as a mutant detector: layer 0 is carried by both arms and sits below the 4..43 band, so a 5× difference there must be absent from over while 4..7 (the 10 % scale, over the 2e-2 threshold) are present — v4['over'] non-empty and 0 not in [...] asserts both halves. That is the property, not a proxy for it.

Two notes, neither blocking, both about the same class:

  1. The arm's name is doing the teaching now, and it should say what the mutant was. "this is the arm that fails if the band is ignored" is excellent; the comment above it already records the exact mutant and the commit it was measured on (8aaf864c2). That is the shape every self-test arm in this tree should have, and it is worth the two lines it costs.
  2. The same question applies to the tool's other arms, and I only checked one. compare(a, b) identical / compare(a, c) 10 % / the two cannot-tell cases — I mutated the band and nothing else. If you are in the file anyway, the cheap sweep is the same one that caught this: for each arm, break the line it claims to protect and see whether the count changes. I can say from this one that the habit is worth more than the arm that prompted it.

Nothing else in the diff: 8 insertions, no behaviour change in compare(), merge-tree origin/main rc 0.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 28300f1: READY, and I re-ran the exact mutant that found this — the new arm catches it. This is my #3199 finding coming back fixed, so I checked it the only way that counts: against the mutation, not against the diff.

shipped (this head)               npu_residual_diff self-test: 8 ok, 0 failed
same mutant (band ignored)        FAIL a large difference BELOW the band is not in the band verdict (this is the arm that fails if the band is ignored)
                                  npu_residual_diff self-test: 7 ok, 1 failed

Three things worth naming:

  • The mutant now fails exactly one arm and the message says why — "this is the arm that fails if the band is ignored" — so the next person who sees it red does not have to reconstruct the reasoning. That is the difference between an arm and a comment.
  • The old arm is kept, so the intersection property stays asserted alongside the band one (8 ok = the original 7 plus this). Good call: they are two properties, and the intersection one is what made the original arm look right.
  • The delta is 8 lines (+8/-1), which is the right size for "a merged self-test could not fail". A larger change would have been a rewrite of an arm that was only wrong about what it tested.

Nothing further from me on this one. The remaining consequence is in the issue thread, not the PR: #3196 still carries the note that the merged tool's green self-test was not evidence for the band until this lands, and once it merges that note is stale in the good direction — worth a line on the issue at merge time so a reader does not treat the older comment as current.

Not checked: nothing device-side — this row needs no device, and the whole verification above ran device-free in a scratch copy.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 28300f1 (28300f1920bcea5347034573b7addead4db56931): READY — the disarmed arm is real, I reproduced the exact experiment, and the replacement arm fails when the band is ignored.

Reproduced on main first, because the claim is about a shipped green

shipped (main 8aaf864c2)          npu_residual_diff self-test: 7 ok, 0 failed
band ignored (if True:)           npu_residual_diff self-test: 7 ok, 0 failed     <- identical

So the self-test's green on main was not evidence that the band does anything. The mechanism is the one the body names: common = sorted(set(a) & set(b)) drops a layer only one side carries before band is consulted, so the arm's fixture never reaches the branch it claims to pin.

And the fix bites

PR head (28300f1)                 npu_residual_diff self-test: 8 ok, 0 failed
same mutant at this head          npu_residual_diff self-test: 7 ok, 1 failed     rc 1
  FAIL a large difference BELOW the band is not in the band verdict (this is the arm that fails if the band is ignored)

The mutant is the production line (npu_residual_diff.py:100, the only code occurrence — the second textual match is the comment that documents this very experiment), so the arm is pinning the code path the tool runs, not a fixture helper. Keeping the old arm as well is right: the intersection property it actually tests is real, it was just named for a different one.

One detail worth keeping in the docstring: the arm is only load-bearing because the difference lands in a layer both sides carry — a fixture that adds a layer to one side re-enters the intersection trap. If a later edit makes the fixture one-sided, this arm goes quiet again with the same silence. That is a one-line comment, not a change request.

The uncomfortable part, recorded so it is not a surprise later

#3199 merged on a verdict from this lane that said "wired + self-testing (7/7, I ran it)" — and that was true: seven arms ran and passed. It was also insufficient, which is the whole point of this PR. "I ran the arms" and "the arms can fail" are different checks, and this is the second time this evening the second one was the one that mattered (the #3226 history replay, 3 of 60 commits). I would rather say that here than let the record imply the earlier verdict was careless: it answered the question it asked.

No live run needed — this is pure self-test logic, and both sides of the experiment are above.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Self-test logic flaw

The self-test previously had a logic flaw where a layer outside the defined band could pass the test even if the band was ignored. This occurred because the intersection of layers between the two sets was computed before consulting the band, causing the test to pass regardless of whether the band constraint was enforced. The fix introduces a second test arm that ensures the band constraint is properly validated by using a layer that exists in both sets and is below the band threshold.

# a layer outside the band does not decide the verdict. TWO arms, because the first one alone cannot fail:
# layer 40 exists only in `c`, so the intersection drops it before `band` is ever consulted and the arm passes
# with or without the band (`if band[0] <= l <= band[1]:` -> `if True:` left it green, measured on main
# 8aaf864c2). The difference has to land in a layer BOTH arms carry and that sits BELOW the band.
dump(c, 40, [x * 5 for x in base])
v3, _ = compare(a, c)
chk(v3 is not None and all(l <= 7 for l, _ in v3['over']), 'layers outside the band are not in the band verdict')
dump(c, 0, [x * 5 for x in base])
v4, _ = compare(a, c)
chk(v4 is not None and v4['over'] and 0 not in [l for l, _ in v4['over']],
    'a large difference BELOW the band is not in the band verdict (this is the arm that fails if the band is ignored)')

@bong-water-water-bong
bong-water-water-bong merged commit c831e76 into main Nov 21, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the npuperf/3199-selftest-band branch November 21, 2026 20:13
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