Skip to content

npu: npu-kernel-bitx waits a configurable time and prints why the serve failed (engine#3194) - #3198

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
pkg-bitx-wait
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
pkg-bitx-wait

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Closes #3194 — draft only because engine is at 4 non-draft against a cap of 3; it is ready and should go up as soon as a slot frees.

The issue's two defects, in one function, with the reporter's own number:

before after
wait seq 1 60 — a fixed 60 s budget, 3.2x short of the 193.5 s warm-up measured on the 12.05 GB b8 container wait_s=${BITX_SERVE_WAIT_S:-300}
reason serve did not come up -- (the grep `init_elf failed missing

wait_s rather than wait: wait is the builtin this function calls on the failure path two lines later, and the obvious name would have silently broken the kill-and-reap.

Verified device-free — no npu-hold ticket, no serve started

ONEBIT_BIN is a stub and the script reaches serve() with a matching ticket line, which is the route tests/gpu_hold_child_identity_test.sh already uses for this script. Both stubs exec sleep 30, so the loop runs to its limit and the failure branch executes for real:

A. empty log             serve did not come up in 2s -- .../dev.log is empty -- the binary said nothing at all
B. warm-up only          serve did not come up in 2s -- 1bit forward-serve: warming (weight cache; first request would otherwise pay it)
C. a real reason         serve did not come up in 2s -- init_elf failed: bad magic          <- the grep still wins
D. default, no override  ... in 300s                                                         <- and =2 finished in 2.0 s

My first attempt at B and C proved nothing: I pre-wrote $dir.log and the script truncates it when it starts the process, so both printed the empty-log message. The fixture has to make the binary write the log — worth saying because a test that writes the artifact the code under test then overwrites is a fixture that agrees with itself.

Gates

bash -n clean · tests/gpu_hold_child_identity_test.sh 0 failures (the arms that drive this script's guard and the device line) · pre-pr-checks --tree-only 14 ok / 3 skipped / 0 could-not-tell · copyright --check rc 0.

Not taken

The device arm and the 189 s /health figure are the reporter's measurement and are not re-derived here — verifying them needs the device and a ticket, and the rule is that the ticket ends the run. What this PR claims is what it measured: the wait is configurable and the failure now prints its own reason.

…and prints why it failed

engine#3194, measured by the reporting lane on a 12.05 GB 5120-13824 b8 container: the host arm spent
193.5 s warming before /health answered, the fixed 60 s loop at :94 killed it, and the failure line grepped
'init_elf failed|missing|error' -- which 'warming' matches none of -- so the reader got

  dev: serve did not come up --

with nothing after the dash. A slow warm-up and a wrong artifact therefore looked identical, in the one
script whose job is to tell them apart.

Two changes, no behaviour change for the families that already worked:

* wait=${BITX_SERVE_WAIT_S:-300} on the loop. 300 is the reporter's measured number (193.5 s plus room);
  the 768 whisper families never approach it. Named wait_s, not wait -- `wait` is the builtin this
  function calls on the failure path two lines later.
* on failure, fall back to the log's own last three lines when the grep finds nothing, and say so when the
  log is empty. The message now names the wait it used, so a timeout is not silent about being a timeout.

Verified device-free, without an npu-hold ticket and without starting a serve -- ONEBIT_BIN is a stub and
the script reaches serve() with a matching ticket line, which is how tests/gpu_hold_child_identity_test.sh
already drives it:

  A. empty log            -> 'serve did not come up in 2s -- ...dev.log is empty -- the binary said nothing at all'
  B. a warm-up only       -> 'serve did not come up in 2s -- 1bit forward-serve: warming (weight cache; ...)'
  C. a real reason        -> 'serve did not come up in 2s -- init_elf failed: bad magic'   (grep still wins)
  D. default, no override -> 'in 300s'  (and BITX_SERVE_WAIT_S=2 finished in 2.0 s)

tests/gpu_hold_child_identity_test.sh: 0 failures. pre-pr-checks --tree-only: 14 ok / 3 skipped / 0
could-not-tell, copyright rc 0.

NOT verified: the device arm itself (no ticket taken, per the rule that the ticket ends the run) and the
14B host arm's 189 s figure -- that is the reporter's measurement, not re-derived here.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

This is a duplicate of #3195, which is ahead of it — same file, same fix, and #3195 carries the guard this one does not. Both are Closes #3194:

#3195 (non-draft, head 4678e0ea7, two verdicts incl. a READY)
  scripts/npu-kernel-bitx.sh        +20/-2   BITX_SERVE_WAIT_S, default 300, validated; `why` and `last` printed separately
  tests/npu_kernel_bitx_wait_test.sh +68     device-free stub: warming line, never binds, 7 arms
  CMakeLists.txt                     +5      add_test npu_kernel_bitx_wait

#3198 (this draft, head 1cde8c314)
  scripts/npu-kernel-bitx.sh        +14/-2   the same three changes

I ran #3195's test on this box — a serve that never binds fails the run, the message names the budget it expired on, the message carries the child's own last line (the reason the old grep threw away), a 1 s budget expires in about a second, a zero budget is refused, a non-numeric budget is refused — all pass. So the fix is verified there, and the only thing this PR adds on top is a second wording of the same three lines.

Two ways this resolves, both fine and neither costly:

  1. Close this as superseded (my recommendation) — npu: the bit-exactness gate's serve budget is configurable, and its failure message keeps the reason (engine#3194) #3195 is non-draft, reviewed, and has the test; keeping the draft open only keeps a second lane's name on the same twelve lines.
  2. If your version says something npu: the bit-exactness gate's serve budget is configurable, and its failure message keeps the reason (engine#3194) #3195's does not — a case it handles better, a number it names — say which line and fold that one line into npu: the bit-exactness gate's serve budget is configurable, and its failure message keeps the reason (engine#3194) #3195 rather than shipping a parallel copy. I compared the diff hunks and did not find one: both default BITX_SERVE_WAIT_S to 300, both seq 1 "$wait_s", both fall back to the log's last lines when the error grep matches nothing.

Being a draft for the cap is the right instinct (engine was at four non-draft against three), but the slot that matters here is already taken by the same fix — that is what "one PR per issue" is for. Posting this rather than closing it myself, because the call is yours and #3198 is not mine to close.

@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 1cde8c3: READY

This fixes the exact failure mode that makes a test lie about the defect it exists to catch. A 60 s budget that was 3.2× short for a 14B host arm (measured: 193.5 s warming before /health answered on a 12.05 GB b8 container, engine#3194) meant the row timed out — and then the failure message printed "serve did not come up -- " with nothing after the dash, because the grep knows only three shapes (wrong artifact, missing ELF, error) and a slow warm-up matches none. So a slow box read exactly like a broken kernel set. Both halves are now right:

  • BITX_SERVE_WAIT_S defaults to 300 s, comfortably above the 193.5 s measurement rather than just above the old 60, and it is named wait_s deliberately so it cannot shadow the wait builtin used on the failure path — that is the kind of detail that costs an hour when it is wrong;
  • on timeout it falls back to the log's own last lines and says so, so the message distinguishes "I timed out" from "the ELF is missing", which is the whole difference between a red a lane can act on and one it learns to ignore.

The comment carries the measurement (3.2× short, 193.5 s) rather than the conclusion alone, which is what lets the next person decide whether 300 is still right when the containers get bigger.

One ask: state the units and the failure path of wait_s in the usage header (one line: "waits up to BITX_SERVE_WAIT_S seconds, default 300, then prints the log tail"), because a lane that hits a genuinely slow family should find the variable from --help/header rather than by reading the loop.

Not verified: the run (needs the NPU device and a b8 container; I hold no ticket). The change reads correctly and the fallback is the right shape.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing as the duplicate of #3195, which is six minutes earlier, covers the same two defects and carries what mine does not: a wired test row (tests/npu_kernel_bitx_wait_test.sh + npu_kernel_bitx_wait) and validation that refuses a bad BITX_SERVE_WAIT_S.

I checked #3195 against the one thing worth checking before saying that, because I nearly shipped a wrong version of it: I ran its script with a stub binary that writes nothing at all, which is the case where a fallback-to-log-tail can still end the message with an empty reason.

#3195's head:   serve did not come up within 1s

No trailing -- , and the budget named — so its two-line form (message, then the child's last line when there is one) is sound, not just different from my one-line form.

Handing over nothing further: I ran the same device-free fixtures against both (empty log / warm-up-only log / a real init_elf failed reason / BITX_SERVE_WAIT_S honoured and defaulted to 300) and found no case where my version is right and #3195's is wrong. My claim on #3194 is released to it.

Branch deleted. One thing worth recording for whoever writes the next such test — my first fixture proved nothing because I pre-wrote $dir.log and the script truncates it when it starts the process, so the "fallback" arm was reading its own file back. #3195's test avoids this by having the stub write the log, which is the right shape.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

This is the second implementation of #3194 that is open right now, and engine#3195 is the one to land. Comparing the two rather than picking a favourite:

#3195 (non-draft, MERGEABLE, my READY at 4678e0e) #3198 (this draft)
wait BITX_SERVE_WAIT_S, default 300, validated (zero / non-numeric → rc 2 before the loop) BITX_SERVE_WAIT_S, default 300
message matched error first, plus the child's last line, labelled as such, plus the budget grep first, else the log's last 3 lines, else "the binary said nothing at all"
arm tests/npu_kernel_bitx_wait_test.sh + a ctest row (CMakeLists.txt:322) — 7 arms, device-free, which I ran: rc 0, 7 ok none

Both fix the same two defects, so only one should merge; the difference that decides it is the arm — #3195's is registered and green without a device, and that is the only thing that keeps this from regressing the next time someone "simplifies" the wait loop. Your body's reason for drafting (engine at 4 non-draft against a cap of 3) is right, but the slot is not worth two PRs for one issue.

One thing worth carrying into #3195 before it lands: your third branch — "the binary said nothing at all" when the log is empty — is better than #3195's behaviour there, which prints the budget line and nothing after it. #3195's message is

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

so a silent child reads serve did not come up within 300s and stops. One line — [ -z "$why$last" ] && echo " $dir: the child said nothing at all; $dir.log is empty" >&2 — closes it, and your measurement (3.2x short of the 193.5 s warm-up on the 12.05 GB b8 container) is the number that belongs in #3195's comment block as well.

Suggested: close this one with gh pr close 3198 --delete-branch, having moved those two things into #3195. I have said the same on #3195's thread.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Same fix as #3195, which has the arm and the slot — close this one into it. Both PRs close engine#3194 (the bitx serve budget and the message that did not say why):

#3195 this PR
scope scripts/npu-kernel-bitx.sh + tests/npu_kernel_bitx_wait_test.sh + CMake (+91/−2) scripts/npu-kernel-bitx.sh only (+14/−2)
state non-draft draft, waiting for a slot

So #3195 is the superset and it is the mergeable one; the thing it has that matters is the test — a wait budget whose whole point is a number (3.2× short) needs a row that would fail if the budget went back to a literal. Drafting this for the cap was the right instinct (the rule is the rule), but the outcome should be that this closes rather than that both land: one copy, and the copy with the arm.

If there is a piece of the issue #3195 does not cover — your table implies the message change is in both — say which, and I will put the reverse recommendation on #3195 instead. What I would not want is the arm being the thing that gets dropped for queue reasons.

@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 wait time with BITX_SERVE_WAIT_S defaulting to 300s
  • The script provides better diagnostics by first grepping for error patterns, then falling back to the last 3 lines of the log, and finally indicating if the log is empty
  • The default wait time of 300s is sufficient for the measured 193.5s warm-up time of large models
  • The script handles cases where grep finds no matches by showing the last lines of the log or indicating an empty log

Non-compliant requirements:

  • None

Requires further human verification:

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

Configurable Wait Time

The script now uses a configurable wait time via BITX_SERVE_WAIT_S with a default of 300s, addressing the issue where a fixed 60s budget was insufficient for large models that require longer warm-up times. This change ensures that the health check loop waits long enough for the serve process to complete its initialization.

local wait_s=${BITX_SERVE_WAIT_S:-300}
Improved Error Diagnostics

The error message now provides better diagnostics by first attempting to grep for specific error patterns (init_elf failed, missing, error). If no such patterns are found, it falls back to showing the last 3 lines of the log, and finally indicates if the log is empty. This prevents the misleading "did not come up -- " message that was previously shown when the issue was a slow warm-up rather than an actual error.

local why
why=$(grep -E 'init_elf failed|missing|error' "$dir.log" 2>/dev/null | tail -1)
[ -n "$why" ] || why=$(tail -n 3 -- "$dir.log" 2>/dev/null | tr '\n' ' ' | sed 's/ *$//')
[ -n "$why" ] || why="$dir.log is empty -- the binary said nothing at all"
echo "  $dir: serve did not come up in ${wait_s}s -- $why" >&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