Skip to content

serve: refuse a load that would land past the GTT ceiling (engine #680) - #764

Merged
bong-water-water-bong merged 3 commits into
mainfrom
1bit/i680-gtt-guardrail-engine
Nov 1, 2026
Merged

bong-water-water-bong merged 3 commits into
mainfrom
1bit/i680-gtt-guardrail-engine

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Engine-side half of #680. The fork half (ggml-hrx charging its own allocations against the same ceiling) is 1bit-MONSTER/llama.cpp#166.

The finding in #680 is not "memory ran out". The device faulted and reset (gfxhub fault + MODE2 reset) at GTT 106.5 GiB of 120, twice: 13.5 GiB of headroom was not enough once the runtime's own allocations landed. serve only refused loads that did not fit in free memory, so a load could be admitted into that zone whenever the box looked free at launch time.

The rule now:

ceiling  = GTT total - reserve        reserve = 16 GiB, GGML_HRX_GTT_RESERVE_MB   -> 104 GiB of 120
refuse   when GTT used now + the estimate > ceiling      (exit 3, before any backend starts)

Same reserve knob ggml-hrx charges against (fork #166), so the pre-launch refusal and the allocation-time backstop cannot disagree about where the wall is. The refusal reuses the existing path Lemonade already handles: one line with both sets of numbers, exit 3.

Measured on strixhalo (120 GiB pool, 52 GiB of GTT in use by another serve, MemAvailable 57.9 GiB), Qwen3-4B-Q4_K_M --device hrx:

arm result
default reserve (16 GiB) fits: need 8.45 GiB … free 57.96 GiB (GTT 67.8 of 120.0 GiB free, MemAvailable 58.0 GiB) — lands at 60.5 GiB
GGML_HRX_GTT_RESERVE_MB=61440 (ceiling 60 GiB) refused, exit 3: does not fit: need 8.45 GiB … free 57.89 GiB; GTT after this load would reach 60.6 GiB of the 60.0 GiB ceiling (120.0 GiB total, 60.0 GiB reserve, GGML_HRX_GTT_RESERVE_MB), where engine #680 faulted; free GTT or raise the reserve; free memory, lower --ctx-size, or pass --no-mem-check

The second row is the point: the box had 57.9 GiB free and the load still refused, because the landing crossed the ceiling. That is the "refuse before it faults" behaviour.

ctest mem_admit extended (tests/mem_admit_test.cpp): 120 − 16 = 104 GiB; a 105 GiB landing refused while 60 GiB is still free; a pool smaller than the reserve refused at any size; a RAM-only refusal stays a RAM-only refusal. Full local run: mem_admit, mem_admit_route, smoke_serve, think_split, gguf_meta all pass; tools/copyright.py --check and tools/check_pins.py origin/main pass.

Two consequences documented in docs/serve.md ("Will it fit?" -> new "The GTT ceiling: refused, not faulted"): with a 120 GiB pool and the default reserve at most 104 GiB is ever planned, so #315's >= 95 GiB warning now only covers the 95-104 GiB band, and the graph-program-cache warning only fires when MemAvailable is the binding limit. --no-mem-check / ONEBIT_MEM_CHECK=0 still skips all of it.

Built and tested on the rebuilt strixhalo (Ubuntu 26.04.1, kernel 7.3.0-rc4-1bit-perfopt+, CMake -j4 under thermal-run). PR-READY.

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit ba763bb)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

680 - Partially compliant

Compliant requirements:

  • Implemented GTT ceiling guardrail to refuse loads that would land past the GTT ceiling
  • Used the same reserve knob (GGML_HRX_GTT_RESERVE_MB) as ggml-hrx for consistency
  • Updated documentation to reflect the new behavior and the GTT ceiling

Non-compliant requirements:

  • None

Requires further human verification:

  • Verification that the fix actually prevents the page faults and GPU resets in real-world scenarios
  • Confirmation that the measured values in the PR description match actual hardware behavior
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Ceiling Calculation Logic

The ceiling calculation logic in mem_admit.h may not correctly handle cases where mem.gtt_total is less than or equal to gtt_reserve_bytes(). In such cases, v.ceiling becomes 0, which could lead to incorrect refusal decisions. The code should ensure that v.ceiling is properly set to 0 when the GTT pool is smaller than the reserve, but it should also be clear that this results in a refusal for any load attempt.

v.ceiling = mem.gtt_total > gtt_reserve ? mem.gtt_total - gtt_reserve : 0;
Reserve Value Handling

The gtt_reserve_bytes() function uses std::atoll() to convert the environment variable GGML_HRX_GTT_RESERVE_MB. If the conversion fails or results in a negative value, it defaults to the default reserve. This could lead to unexpected behavior if the environment variable is set to an invalid value. Consider adding validation to ensure the reserve value is non-negative and reasonable.

    const long long mb = std::atoll(e);
    if (mb >= 0) return uint64_t(mb) * kMiB;
}

@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

At f36606d7 — first review, build green. app/mem_admit.h, app/serve.cpp, docs/serve.md, tests/mem_admit_test.cpp.

Ran the test, and it exercises exactly the new rule:

$ g++-16 -std=c++17 -O1 -I app tests/mem_admit_test.cpp -lgtest -lgtest_main && ./a.out
ok   45 GiB more: refused by the ceiling although 60 GiB is free
ok   the refusal names the ceiling and the reserve
ok   1 GiB more: fits, no ceiling note
ok   a pool smaller than the reserve: refused at any size
PASS

That first row is the whole point: refused although 60 GiB is free. The old rule was "refuse only when the need exceeds what is free", which could never catch #680 — a gfxhub page fault plus MODE2 reset at 106.5 GiB of 120 with 13.5 GiB of headroom still showing, because the runtime's own allocations land after the admission check. Refusing on a ceiling (GTT total minus a 16 GiB reserve) is the right invariant, since it bounds where the load will end up rather than what is currently free.

Two details that make it safe rather than merely stricter:

  • the reserve reads GGML_HRX_GTT_RESERVE_MB, the same knob ggml-hrx reads (fork PR #166), so "the pre-launch refusal and the allocation-time backstop cannot disagree about where the wall is" — that is the property that stops this becoming two walls with a gap between them;
  • the graph-program cache and #315's 95 GiB zone still only warn inside the ceiling, because they grow after load — so the change refuses the case that kills the machine and leaves the advisory cases advisory.

The refusal message names the ceiling and the reserve, which is what makes a refused load diagnosable instead of mysterious.

Not verified: a real load near the ceiling on the box (needs the GPU and a model that reaches ~100 GiB of GTT). The arithmetic is unit-tested; the physical claim behind the 16 GiB reserve is #680's.

tprs-ready applied.

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 1, 2026
Free memory was the only wall serve checked, and it is not the wall that hurts: #680 is a gfxhub
page fault plus a MODE2 reset at GTT 106.5 GiB of 120, twice, i.e. 13.5 GiB of headroom was not
enough once the runtime's own allocations landed.

The admission verdict now also carries an absolute ceiling - GTT total minus a 16 GiB reserve - and
refuses a load whose landing (GTT in use now + the estimate) would cross it, even when the free
memory test alone would admit it. Same reserve knob ggml-hrx charges its own allocations against
(GGML_HRX_GTT_RESERVE_MB, fork PR #166), so the pre-launch refusal and the allocation-time backstop
cannot disagree. The refusal prints one line with both sets of numbers and exits 3, the same code
Lemonade already reads as a failed load, so nothing downstream changes.

Measured on strixhalo (120 GiB pool, 52 GiB of GTT in use by another serve, MemAvailable 57.9 GiB),
Qwen3-4B-Q4_K_M --device hrx:

  default reserve (16 GiB): fits - need 8.45 GiB, free 57.96 GiB, ceiling 104 GiB, lands at 60.5 GiB
  GGML_HRX_GTT_RESERVE_MB=61440 (ceiling 60 GiB): refused, exit 3 -
  'GTT after this load would reach 60.6 GiB of the 60.0 GiB ceiling (120.0 GiB total, 60.0 GiB
   reserve, GGML_HRX_GTT_RESERVE_MB), where engine #680 faulted'

i.e. a load the box had plenty of free memory for is refused on the ceiling alone, which is the
behaviour #680 asked for.

ctest mem_admit covers the arithmetic (120 - 16 = 104; a 105 GiB landing refused while 60 GiB is
free; a pool smaller than the reserve refused at any size; RAM-only refusals still RAM-only), and
docs/serve.md 'Will it fit?' documents the rule, the knob and the two consequences (the >= 95 GiB
warning now only covers the 95-104 GiB band, and the program-cache warning only fires when
MemAvailable is the binding limit).
@bong-water-water-bong
bong-water-water-bong force-pushed the 1bit/i680-gtt-guardrail-engine branch from f36606d to 0fdd4ef Compare November 1, 2026 14:58
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 0fdd4ef

@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

At 0fdd4ef9 — re-confirmed after the waiter moved the head: build green, and I re-ran the gate at this content rather than assuming the rebase was inert.

tests/mem_admit_test.cpp → PASS, including "45 GiB more: refused by the ceiling although 60 GiB is free" — the row that proves a ceiling rule catches #680 where a free-memory rule structurally cannot. The reserve still reads GGML_HRX_GTT_RESERVE_MB, the same knob fork #166 reads (verified across both PRs), so the pre-launch refusal and the allocation-time backstop cannot disagree.

tprs-ready stands.

@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

At 70dd3c94 — build green, and I re-ran the gate at this content rather than assuming the rebase was inert.

tests/mem_admit_test.cpp → PASS, including "45 GiB more: refused by the ceiling although 60 GiB is free" — the row that proves a ceiling rule catches #680 where a free-memory rule structurally cannot. The reserve still reads GGML_HRX_GTT_RESERVE_MB, the same knob fork #166 reads (verified across both PRs).

tprs-ready stands.

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit ba763bb

@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

Confirmation at ba763bbc, not a re-derivation: the tip is a Merge branch 'main' into 1bit/i680-gtt-guardrail-engine
with the author commit unchanged (0fdd4ef, same sha I reviewed), origin/main an ancestor, own diff still the
same 4 files (+129 −16).

Re-ran the gate at the tip anyway, because the tree it compiles against has moved (main is 5f8045e):

$ g++-16 -std=c++26 -O1 -Iapp tests/mem_admit_test.cpp -o /var/tmp/mem_admit_764 && /var/tmp/mem_admit_764
ok   Qwen3-0.6B KV at 4096: 448.0000 MiB (want 448.0000)      … 31 rows …
ok   45 GiB more: refused by the ceiling although 60 GiB is free
ok   the refusal names the ceiling and the reserve
PASS

The row that matters is still the one that distinguishes this rule from a free-memory rule: 45 GiB more is refused by
the ceiling with 60 GiB free. tprs-ready stays; no GPU was used (nothing here needs one).

@bong-water-water-bong
bong-water-water-bong merged commit d3d2667 into main Nov 1, 2026
8 of 9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/i680-gtt-guardrail-engine branch November 1, 2026 16:12
bong-water-water-bong added a commit that referenced this pull request Nov 1, 2026
…ing does not cover it) (#773)

* hyperloom custom: refuse the drafter at long context until #764 lands

The drafter at long context is the arm that faulted the HRX graph on this box
(27B, 18.8k ctx, the 2026-11-01 11:13 MODE2 reset), so the box rule forbids it
until engine#764's GTT admission guardrail is merged. A candidate that asks for
HL_DFLASH with HL_LONGCTX>0 now exits before loading anything, so the tuner
scores it zero with the reason instead of measuring a shape nobody may measure.
The short-prompt drafter arm is untouched: it is the +13.8% winner.

* hyperloom custom: refuse the long-context drafter before anything resolves

The guard ran after the model and binary checks, so a refused candidate still failed later than it
had to. It is now the first statement in main(), which is where a box rule belongs.

Refusal proof (CPU-only, nothing loaded):
  HL_LONGCTX=18800 HL_DFLASH=1 python3 tools/hyperloom/custom/benchmark.py
  -> refusing HL_DFLASH with HL_LONGCTX>0: ...

---------

Co-authored-by: bong-water-water-bong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review effort 4/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant