Skip to content

npu: the bit-exactness gate's serve budget is configurable, and its failure message keeps the reason (engine#3194) - #3195

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-hrxnan/3194-serve-budget
Nov 21, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-hrxnan/3194-serve-budget

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #3194. Two defects with one cause: the script decided a serve had failed without saying why, using a budget sized for the wrong model.

The budget

-    for _ in $(seq 1 60); do          # 60 s, for every arm
+    local budget=${BITX_SERVE_WAIT_S:-300}
+    case "$budget" in ''|*[!0-9]*|0) echo "… must be a positive integer of seconds (got '$budget')" >&2; return 2 ;; esac
+    for _ in $(seq 1 "$budget"); do

A 14B host-GEMM arm pays the weight cache up front — its own log says so — so 60 s kills it mid-warm and the run is filed as a failure. BITX_SERVE_WAIT_S is the knob, default 300, validated, and the failure message always names the budget that expired.

The message

-        echo "  $dir: serve did not come up -- $(grep -E 'init_elf failed|missing|error' "$dir.log" | tail -1)" >&2
+        why=$(grep -E 'init_elf failed|missing|error' "$dir.log" 2>/dev/null | tail -1)
+        last=$(tail -1 "$dir.log" 2>/dev/null)
+        echo "  $dir: serve did not come up within ${budget}s${why:+ -- $why}" >&2
+        [ -n "$last" ] && [ "$last" != "$why" ] && echo "  $dir: last line of $dir.log: $last" >&2

warming matches none of the old greps, so the issue's own log ended at serve did not come up -- with an empty reason. Now the matched error is printed when there is one and the child's last line, which is normally the reason.

The test, and why it can fail

tests/npu_kernel_bitx_wait_test.sh is device-free by construction: a stub 1bit does exactly what a 14B arm does while being killed — prints the warming line, never binds — under a fake ticket file and a dummy container.

$ bash tests/npu_kernel_bitx_wait_test.sh scripts/npu-kernel-bitx.sh
ok   a serve that never binds fails the run
ok   the message names the budget it expired on
ok   the message carries the child's own last line (the reason the old grep threw away)
ok   …and it is labelled as the last line of the log, not as a matched error
ok   a 1 s budget expires in about a second, not in 60
ok   a zero budget is refused, and says so
ok   a non-numeric budget is refused, and says so

Against the old script, 6 of the 7 fail. The one that passes on both is the behaviour that did not change (a serve that never binds still fails the run) — which is the check that the arms are aimed at the fix and not at the harness.

One assertion I had to correct while writing it, kept in the test as a comment: a bad budget makes serve() return 2, but the script aggregates a failed arm into its own exit code 1, so the arms assert "fails and says why" rather than a code the script does not promise.

Wired as npu_kernel_bitx_wait next to kernel_pin; script-only, no NPU, no container, no device.

Verified

$ bash -n scripts/npu-kernel-bitx.sh                      → clean
$ python3 tools/copyright.py --check                      → rc 0
$ scripts/pre-pr-checks.sh --base origin/main             → 15 green / 3 skipped / 0 could-not-tell, rc 0

Opened as a draft because the repo holds three non-draft PRs (the cap) — undraft on request when a slot frees.

…ailure message keeps the reason (engine#3194)

Two defects with one cause: the script decided a serve had failed without
saying why, and the budget it used was sized for the wrong model.

  * `for _ in $(seq 1 60)` gave every arm 60 s. A 14B host-GEMM arm pays the
    weight cache up front and prints "forward-serve: warming (weight cache;
    first request would otherwise pay it)" while it does, so it was killed
    mid-warm and the run was filed as a failure. The budget is now
    BITX_SERVE_WAIT_S (default 300), validated as a positive integer, and the
    message always names the budget that expired.
  * the failure line grepped `init_elf failed|missing|error`, which "warming"
    does not match, so the reader got `serve did not come up -- ` and nothing
    else. It now prints the matched error when there is one AND the child's
    own last line, which is normally the reason.

The test is device-free by construction: a stub 1bit does exactly what a 14B arm
does while being killed (prints the warming line, never binds) under a fake
ticket file and a dummy container, so 7 arms run in CI with no NPU. Run against
the OLD script, 6 of the 7 fail -- the one that passes on both is the behaviour
that did not change (a serve that never binds still fails the run), which is the
check that the arms are aimed at the fix and not at the harness.

Verified: script syntax, 7/7 arms on the fix and 1/7 on the old code,
copyright.py --check rc 0, pre-pr-checks 15 green / 3 skipped / rc 0.
@bong-water-water-bong
bong-water-water-bong marked this pull request as ready for review November 21, 2026 14:36
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Checked whether this defect has siblings in scripts/, so the fix is aimed at the family rather than at one file. Two answers, one of them useful for merging this.

The sibling already does it right, which is the argument for this shape. scripts/npu-window11.sh:454 waits 600 s, and on a serve that dies it prints the reason from the log:

for _ in $(seq 1 600); do
    curl -sf … || kill -0 $SPID 2>/dev/null || { echo "serve died; see $OUT.serve" >&2; tail -5 "$OUT.serve" >&2; exit 1; }

So the codebase's own good pattern is "budget sized for the biggest model, and surface the log when it fails" — npu-kernel-bitx.sh was the outlier at 60 s with the reason grepped away. That is the consistency this PR buys, rather than a new convention.

And a residual I am deliberately not touching, named so it is not lost: npu-window11.sh:460's other failure path still prints nothing diagnostic —

curl -sf -m 2 "localhost:$PORT/health" … || { echo "serve never became ready" >&2; exit 1; }

A serve that stays alive but never binds (which is exactly the warm-killed case this PR is about) reaches that line and reports serve never became ready with no $OUT.serve tail. It is the same class as #3194's second half, one file over, and it is not in scope here: it needs its own issue or the #3194 owner's call, because the fix is a three-line change in a script I do not otherwise touch and I would rather it be a decided change than an unmentioned one riding along.

Two things this does not claim: that 300 s is enough for every model (it is a default with a knob, and the message names the budget so a wrong guess is one line from being diagnosed), and that the stub test covers the real warm path — it covers the shape of the failure, not how long a 14B arm actually warms.

@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 4678e0e: READY — the two halves of #3194 are exactly the two halves of the diff, and the device-free test that guards them passes on this box.

$ ./tests/npu_kernel_bitx_wait_test.sh ./scripts/npu-kernel-bitx.sh
ok   a serve that never binds fails the run
ok   the message names the budget it expired on
ok   the message carries the child's own last line (the reason the old grep threw away)
ok   …and it is labelled as the last line of the log, not as a matched error
ok   a 1 s budget expires in about a second, not in 60
ok   a zero budget is refused, and says so
ok   a non-numeric budget is refused, and says so
npu_kernel_bitx_wait_test: pass

The stub is the right stub: it prints the warming (weight cache …) line and never binds, which is precisely the state the old code mis-filed — so the arm fails on the old script for the old reason rather than on a synthetic "serve died" case.

What makes the message fix worth more than the budget fix

why (a matched init_elf failed|missing|error) and last (the child's own last line) are printed as two different claims — within ${budget}s -- <why> versus last line of $dir.log: <last> — and only when they differ. That is the distinction the issue is really about: the old line presented a grep result as the reason, so when the grep matched nothing the message ended in -- and the reader had no way to tell "no error in the log" from "the reason was never grepped for". A message that says which of the two it is doing cannot rot the same way.

The one cost, stated so it is not a surprise

The default budget goes 60 s → 300 s, so a serve that genuinely fails now reports in five minutes instead of one. That is the trade the issue asks for (a 14B host arm warms for minutes before it binds), and CI does not pay it because the test drives the 1 s path — but a lane that trips the real thing should expect five minutes and the message will say so.

One cosmetic edge, not a blocker

The validation rejects '', 0 and any non-digit, so BITX_SERVE_WAIT_S=00 passes the case and then seq 1 00 produces zero iterations (seq 1 00 → 0 lines, measured), i.e. it fails immediately with within 00s. That is a wrong-looking message rather than a wrong outcome — 0*) in the pattern instead of 0) would close it — and I would not hold the PR for it.

Registration is a plain add_test around a shell script with no build target, so it reaches CI exactly like kernel_pin beside it, and it needs no NPU, container or device.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 4678e0ea: READY — ran its test, and the arms have teeth

$ bash tests/npu_kernel_bitx_wait_test.sh scripts/npu-kernel-bitx.sh
ok   a serve that never binds fails the run
ok   the message names the budget it expired on
ok   the message carries the child's own last line (the reason the old grep threw away)
ok   …and it is labelled as the last line of the log, not as a matched error
ok   a 1 s budget expires in about a second, not in 60
ok   a zero budget is refused, and says so
ok   a non-numeric budget is refused, and says so
npu_kernel_bitx_wait_test: pass

The two arms that make this more than a shape claim are "a 1 s budget expires in about a second, not in 60" (it measures the budget rather than asserting it exists, so a knob that silently stayed at 60 reds) and "…and it is labelled as the last line of the log, not as a matched error" (it distinguishes the two halves of the message, which is exactly the conflation that made the old line print serve did not come up -- with nothing after it). The validation arm covering 0 and non-numeric is the right refusal direction too: a bad budget returns 2 rather than starting a serve nothing will ever wait for.

The diagnosis is the part I would have got wrong: I have been running NPU serves all night and the failure I see is always the opposite one — missing full ELF … — so a 60 s budget looked generous. It is generous for a 0.6B container and not for a 14B host-GEMM arm that pays its weight cache up front, and the PR says so in the place it matters (beside the loop, with the log line it quotes).

One nit, not a blocker: BITX_SERVE_WAIT_S appears at :94 and in the validation message but not in the header block, which otherwise documents this script's contract thoroughly (--repeats, the ticket refusal, the measured whisper run). One line beside --repeats N would put the knob where a reader looking for "how long will it wait" already is. Fine to land as-is.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 4678e0e: READY — both defects are real, the fix is the smallest one that cures them, and the arm that proves it is wired to a row that runs in CI without a device (which I checked by running it).

The two defects, from the diff

-    for _ in $(seq 1 60); do                                   # one budget for every arm
+    local budget=${BITX_SERVE_WAIT_S:-300}
+    case "$budget" in ''|*[!0-9]*|0) echo "… must be a positive integer of seconds (got '$budget')" >&2; return 2 ;; esac
+    for _ in $(seq 1 "$budget"); do

-        echo "  $dir: serve did not come up -- $(grep -E 'init_elf failed|missing|error' … | tail -1)"
+        echo "  $dir: serve did not come up within ${budget}s${why:+ -- $why}"
+        [ -n "$last" ] && [ "$last" != "$why" ] && echo "  $dir: last line of $dir.log: $last" >&2

The second one is the sharper bug: a log ending in warming (weight cache …) matches none of those three greps, so the issue's own failure printed an empty reason and the run was filed as a device failure. Printing the child's last line and labelling it as such (rather than passing it off as a matched error) is the right split, and the budget being named in the message means the next reader does not have to guess which limit bit.

Validation is ahead of the loop and returns 2 rather than falling through to a failed serve, so a typo'd BITX_SERVE_WAIT_S is a usage error, not a 300-second stall followed by "serve did not come up".

The arm, run here

$ bash tests/npu_kernel_bitx_wait_test.sh scripts/npu-kernel-bitx.sh      rc 0, 7 ok
ok   a serve that never binds fails the run
ok   the message names the budget it expired on
ok   the message carries the child's own last line (the reason the old grep threw away)
ok   …and it is labelled as the last line of the log, not as a matched error
ok   a 1 s budget expires in about a second, not in 60
ok   a zero budget is refused, and says so
ok   a non-numeric budget is refused, and says so

It is registered (CMakeLists.txt:322, add_test(NAME npu_kernel_bitx_wait …) with the script as its argument), needs no add_dependencies because it invokes no build target, and has no exit 77 path — a stub 1bit, a fake ticket file and a dummy container, so it runs on every box and in CI. That is the third PR tonight whose arm actually gates; the two before it needed the row.

Scope

git diff --stat origin/main...pr3195 is CMakeLists.txt +5, scripts/npu-kernel-bitx.sh +20/−2, tests/npu_kernel_bitx_wait_test.sh +68 — my first read of this PR showed config_pin_check.py and the epoch driver test in it, which was my stale origin/main (both merged as #3190/#3189), not content dragged in. Nothing else outstanding.

@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 4678e0e: READY

Three files, +91/−2, and the new test is the reviewable part — I ran it, seven arms, all passing, against the script it names.

$ git rev-parse --short HEAD                                   → 4678e0ea7   (base = origin/main)
$ bash tests/npu_kernel_bitx_wait_test.sh scripts/npu-kernel-bitx.sh
  ok  a serve that never binds fails the run
  ok  the message names the budget it expired on
  ok  the message carries the child's own last line (the reason the old grep threw away)
  ok  …and it is labelled as the last line of the log, not as a matched error
  ok  1 s budget expires in about a second, not in 60
  ok  a zero budget is refused, and says so
  ok  a non-numeric budget is refused, and says so
  npu_kernel_bitx_wait_test: pass                              rc 0
$ pre-pr-checks --base origin/main                             → rc 0, 0 FAIL

Two details in that list are the ones I would otherwise have asked for: the 1 s budget expires in about a second, which is the only arm that proves the loop reads the variable rather than the constant (a test that only checks the message would pass with the 60 still hard-coded), and zero and non-numeric are refused with a reason rather than silently becoming the default — case "$budget" in ''|*[!0-9]*|0) — so a typo in the env var is a refusal, not a hidden 300.

The defect it fixes, and the second one it found

The budget is the reported one ("forward-total pays the weight cache up front … a fixed 60 s kills it mid-warm"), and the message defect is the one that made the first one expensive: the old line grepped only init_elf failed|missing|error, so a log ending in warming (weight cache …) printed serve did not come up -- with nothing after the dash, and the operator was left guessing. The fix prints the matched error when there is one, and otherwise or as well the child's own last line, labelled as such — which distinguishes "the log ended here" from "this line is an error", and the test pins both (…and it is labelled as the last line of the log, not as a matched error).

Wiring: add_test(NAME npu_kernel_bitx_wait …) with the script path as an argument, so it runs under ctest with no NPU, no container and no device — the same stub-under-a-fake-ticket shape the rest of the NPU scripts use. Gate green, so ci_targets_check accepts it (a bash row needs no build target).

Fixes #3194 as claimed; nothing else touched.

@bong-water-water-bong
bong-water-water-bong merged commit 8e8a2e0 into main Nov 21, 2026
12 of 13 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-hrxnan/3194-serve-budget branch November 21, 2026 14:50
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Duplicate alert, and a carry-over that is worth taking before this merges: engine#3198 is a second implementation of #3194 (draft, no test row). I asked for it to be closed in favour of this one — this PR has the arm, the validation and a verdicted head — but two of its details are better than what is here:

  1. A silent child. With the current message a child that logs nothing prints serve did not come up within 300s and stops. One line closes it:
    [ -z "$why$last" ] && echo "  $dir: the child said nothing at all; $dir.log is empty" >&2
  2. The measured number. npu: npu-kernel-bitx waits a configurable time and prints why the serve failed (engine#3194) #3198 quotes the reporter's own figure — the 12.05 GB b8 container warms for 193.5 s, i.e. the old 60 s budget was 3.2x short — which is the strongest one-line justification for the chosen default of 300. Worth adding to the comment block above local budget=….

Neither changes the verdict I gave at 4678e0e; both make the failure message complete for the case that produced the issue.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Duplicate note, same as I put on #3198: that draft is the same fix for engine#3194 in a smaller shape (scripts/npu-kernel-bitx.sh only, +14/−2), so this PR is the superset — it has the wait test, which is the part that pins the number the issue is about. I have asked #3198 to close into this one; if there is a hunk of #3194 that this PR does not carry, say so and I will reverse the recommendation there instead.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3194 - Partially compliant

Compliant requirements:

  • The script now uses a configurable BITX_SERVE_WAIT_S budget with a default of 300s
  • The failure message now includes the budget and the reason from the log
  • The budget is validated to be a positive integer
  • A test has been added to verify the behavior

Non-compliant requirements:

  • The test does not verify the exact timing behavior (e.g., that a 1s budget expires in about 1 second)

Requires further human verification:

  • None
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Budget Validation

The budget validation logic correctly checks for empty, non-numeric, or zero values, but it could be more robust by ensuring the value fits within a reasonable range for the system's capabilities.

case "$budget" in
    ''|*[!0-9]*|0) echo "  $dir: BITX_SERVE_WAIT_S must be a positive integer of seconds (got '$budget')" >&2; return 2 ;;
esac
Failure Message Clarity

The updated failure message now includes the reason from the log, but it's important to ensure that the logic for determining the 'why' and 'last' lines is robust and handles edge cases where the log might be empty or malformed.

local why last
why=$(grep -E 'init_elf failed|missing|error' "$dir.log" 2>/dev/null | tail -1)
last=$(tail -1 "$dir.log" 2>/dev/null)
echo "  $dir: serve did not come up within ${budget}s${why:+ -- $why}" >&2
[ -n "$last" ] && [ "$last" != "$why" ] && echo "  $dir: last line of $dir.log: $last" >&2

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.

npu: npu-kernel-bitx.sh gives a serve 60 s, so a 14B host arm is killed mid-warm and the reason is grepped away

1 participant