Skip to content

hrx: a host-weight refusal says whether the arena is fragmented or short (engine #900) - #180

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/i900-arena-refusal
Nov 4, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/i900-arena-refusal

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Fixes the reporting half of engine 1bit-MONSTER/engine#900. The placement/coalescing follow-up the issue
mentions is deliberately not here: this changes no allocation, eviction or placement behaviour.

Root cause

HostWeightCache::arena_reserve() fails on the free list, not on the size. The issue's own numbers: 193.2 MiB free
in 5 blocks against a 121.7 MiB slot. The refusal at runtime/host-memory.cpp then said the model's per-execution
working set cannot be held — a different claim — and printed a raise-to number derived from need + resident + parked,
which is not a fixed point because resident tracks the budget. Measured consequence: "Raise it to at least 4030 MiB"
while 4096 MiB was in force
(the issue's table, 76.32 GiB pack).

The free list already knows the difference: when free_bytes >= need and no single block is that large, the space
exists and is split. That predicate was available at the failure site and unused.

Change

runtime/host-memory-refusal.h (new, no HRX dependency so it is testable without the private runtime) holds the
verdict and the sentence. Fragmented misses report free bytes, block count, largest block, arena/limit/resident/
parked and say the space is fragmented; genuine capacity misses keep the engine ggml-org#788 wording and its arithmetic.

Also, because the numbers are captured at the failure:

  • arena_reserve()'s own line no longer calls a fragmented arena "full after eviction" — it says which slot it could
    not place, in how many blocks, and the largest block (the line the issue quotes as the smoking gun).
  • The latched refusal (budget_refusal_) now stores the whole miss, so every later acquire in the same run repeats
    the first refusal's reason instead of re-deriving a capacity claim it never measured.

Verification

tests/test-hrx-arena-refusal.cpp, 5 arms, device-free and HRX-free:

arm input expected
the issue's 200 MiB case 121.7 wanted / 193.2 free in 5 blocks / largest 60.4 fragmented, no raise-to number
the issue's 4096 MiB case 497 wanted / 564 free in 3 blocks / largest 400 fragmented, no raise-to number
genuine capacity 500 wanted / 40 free Raise it to at least 4032 MiB (500+1983+1549)
unbounded default limit = 0 capacity wording, no division by the limit
corner free >= need and largest >= need not called fragmentation
$ g++ -std=c++17 -Wall -Wextra -Iggml/src/ggml-hrx tests/test-hrx-arena-refusal.cpp -o /tmp/t900 && /tmp/t900
test-hrx-arena-refusal: all cases ok (5 arms)

# negative control: the same test against the pre-#900 wording (no verdict, capacity wording always)
$ g++ -std=c++17 -I/tmp/negctl tests/test-hrx-arena-refusal.cpp -o /tmp/t900neg && /tmp/t900neg
FAIL budget-200: free >= need with no block that large is fragmentation
FAIL budget-4096: Raise it to at least must not be in "... Raise it to at least 4029 MiB ..."
test-hrx-arena-refusal: 9 failure(s)

The negative control reproduces the issue's contradiction by itself: Raise it to at least 4029 MiB at a 4096 MiB
budget.

host-memory.cpp syntax-checks clean at this branch (-fsyntax-only, the tree's real include paths incl.
third_party/hrx-system/libhrx/include). The new CMake target sits in the existing if (TARGET ggml-hrx) block
beside test-hrx-graph-program-budget and links nothing HRX; that block is only reached with GGML_HRX=ON, which
builds hrx-system's own iree/loom ExternalProject here, so the wiring was validated in a scratch project with the same
target shape and paths (cmake --build → built; ctest -R test-hrx-arena-refusal → Passed).

Notes

  • Not measured: a real fragmented refusal on a device. Reproducing it needs a partial-offload HRX run of the issue's
    76.32 GiB pack (-dev HRX0 -ngl 20 -fa on -ub 512), which is a gpu-hold + >20 GiB load I did not take tonight. The
    arms above are the issue's own measured numbers fed to the helper that now decides the wording.
  • The engine row closes on a pin bump past this fork merge, not on this PR.

…ort (engine ggml-org#900)

arena_reserve() fails on the free list, not on the size: the issue measured 193.2 MiB free in 5
blocks against a 121.7 MiB slot, and the refusal told the operator the model's working set does not
fit - then advised "Raise it to at least 4030 MiB" while the budget in force was 4096 MiB.

The free list can tell the two cases apart (free >= need with no block that large means fragmented),
so the refusal now reports which one happened, with the largest block, and drops the size advice in
the fragmented case - where the number it printed was not a fixed point, because resident tracks the
budget. The genuine capacity case keeps the engine ggml-org#788 wording and its raise-to number.

The miss is recorded whole in the latch, so a later acquire in the same run repeats the first
refusal's reason instead of re-deriving the wrong one. Diagnostic only: no allocation, eviction or
placement behaviour changes.

tests/test-hrx-arena-refusal.cpp: 5 arms - both of the issue's measured states, a genuine capacity
miss, the unbounded default, and the corner where a large enough free block exists (not called
fragmentation).
@bong-water-water-bong

Copy link
Copy Markdown
Author

#180 ready for review at de4c2b22e — fork base 1bit/hrx-vulkan-patched (d8bd0ff6052a), 5 files (+252/−29). Diagnostic only: no allocation/eviction/placement behaviour changes.

Verified from a clean clone of the pushed branch, not the worktree: g++ -std=c++17 -fsyntax-only on ggml/src/ggml-hrx/runtime/host-memory.cpp with the tree's real include paths (incl. third_party/hrx-system/libhrx/include) → rc 0; tests/test-hrx-arena-refusal.cpp → all cases ok (5 arms); the same test against the pre-ggml-org#900 wording → 9 failures, including the issue's own contradiction (Raise it to at least 4029 MiB at a 4096 MiB budget). CMake wiring exercised in a scratch project with the same target shape (ctest -R test-hrx-arena-refusal → Passed), because the if (TARGET ggml-hrx) block is only reached with GGML_HRX=ON.

Not measured: a real fragmented refusal on a device — that needs a gpu-hold and the issue's 76.32 GiB pack, which I did not take.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY at de4c2b22e. I built and ran the test, and I reproduced the negative control independently — the
old wording's self-contradiction falls out of the same test.

Pass here (g++ -std=c++17 -Wall -Wextra -Iggml/src/ggml-hrx tests/test-hrx-arena-refusal.cpp):

test-hrx-arena-refusal: all cases ok (5 arms)          rc=0     (no warnings with -Wall -Wextra)

My negative control, written from the PR's description of the pre-ggml-org#900 wording (same API: fragmented() always
false, describe() always the capacity sentence with its raise-to number), same test file:

FAIL budget-200: free >= need with no block that large is fragmentation
FAIL budget-4096: a 497 MiB slot against 564 MiB in 3 blocks is fragmentation
FAIL budget-4096: Raise it to at least must not be in "… a 497.0 MiB slot does not fit with 1983.0 MiB resident and
                  1549.0 MiB parked. Raise it to at least 4029 MiB or unset it (engine #788)."
…                                                                  test-hrx-arena-refusal: 9 failure(s)   rc=1

That is the issue's contradiction reproduced by the PR's own test, not just by the PR's own control: "Raise it to
at least 4029 MiB" while 4096 MiB is in force
(497 + 1983 + 1549 = 4029, exactly the arithmetic the helper claims;
the capacity arm's 500 + 1983 + 1549 = 4032 likewise re-derives).

The .cpp side compiles — -fsyntax-only with the tree's real include paths (including
third_party/hrx-system/libhrx/include and the loom binding include) is clean, and the diff is message-only: the
three scalars become one ArenaMiss in host-memory.h, the latch now repeats the first miss through
describe(refusal_) instead of re-deriving a capacity claim, and arena_reserve()'s own line stops calling a
fragmented arena "full after eviction" and names the slot, the block count and the largest block. No allocation,
eviction or placement line is touched, which is what the PR says and what the diff shows.

The CMake wiring is the one thing I checked rather than assumed: test-hrx-arena-refusal sits inside
if (TARGET ggml-hrx) with only ../ggml/src/ggml-hrx on the include path and no link libraries, which is
exactly why it builds without the private runtime — my standalone g++ line is that target's whole dependency set.

Not in evidence, and correctly stated as such by the PR: a real fragmented refusal on the device. The arms are
the issue's measured numbers fed to the helper that now decides the wording; the run that would prove it
(-dev HRX0 -ngl 20 -fa on -ub 512 on the 76.32 GiB pack) is a gpu-hold + >20 GiB job I did not take either.

Two notes, neither a gate:

  1. The corner arm is the right instinct (a large enough block means the take failed for another reason, so do not
    claim fragmentation) but nothing asserts which other reason; the branch says "a failed growth logs its own
    line", which is true today and would be worth a comment at the capture site if a second failure mode ever lands
    there.
  2. fragmented() with need == 0 is false (largest_block < 0 never) — unreachable (a slot is aligned to at least
    one page) but the predicate reads as if it were a general one.

Base is 1bit/hrx-vulkan-patched, mergeStateStatus CLEAN, +252/−29 across the header, the host-memory.{h,cpp}
hunks, the test and its CMake entry. The engine row closes on the pin bump, as the PR notes.

@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 4, 2026

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY — the refusal now reports the reserve outcome that failed, and the arms discriminate.

Reviewed at de4c2b22e (one file's worth of behaviour: runtime/host-memory-refusal.h new, host-memory.cpp, host-memory.h).

What I ran myself, not read off the body:

  • g++ -std=c++17 -O1 -I ggml/src/ggml-hrx tests/test-hrx-arena-refusal.cpp -o /tmp/arena-refusal-test -> rc 0, and the
    binary prints test-hrx-arena-refusal: all cases ok (5 arms), rc 0.
  • Mutation worth knowing about: the discriminating arms are the fragmented-vs-capacity pair. fragmented() is
    free_bytes >= need && largest_block < need, so the 4096 MiB arm (497 wanted, 564 free in 3 blocks, largest 400) and
    the corner arm (64 wanted, 128 free in 1 block, largest 128) separate the two, and the corner arm is the one that
    would catch an over-eager predicate. The Raise it to at least 4032 MiB assertion is the arithmetic it claims
    (500 + 1983 + 1549), so a later edit to the formula cannot pass silently.
  • amdclang++ with the real GGML_HRX=ON flags on runtime/host-memory.cpp -> rc 0 (2 warnings, both pre-existing
    -Wunused-but-set-variable at :1559; nothing from the new code).
  • The latched-refusal path keeps the whole miss (ArenaMiss refusal_ replaces the three size_t members), so the second
    and later acquires cannot invent a capacity claim they did not measure — that was the "self-contradictory advice"
    half of ggml-org#900 and it is now structurally impossible, not just rewritten.

Two notes, neither a gate:

  1. arena_reserve()'s new line and describe() both compute largest by walking arena_free_, and the reserve path
    does it inside the mutex while describe() reads a snapshot; that duplication is fine, but the snapshot in
    refusal_ is taken at latch time and never refreshed, so a run that continues allocating after the first refusal
    reports the first miss forever. The comment above budget_refusal_ says this is deliberate (the repeat must tell
    the same story); worth one word in the log string ("at the first refusal") so a reader does not take the numbers
    for live ones.
  2. No test covers arena_reserve()'s own changed line (the helper is tested, the call site is not). That is the same
    split as the rest of this file's history, so it is not a blocker here — just do not let it become a habit for the
    placement/coalescing follow-up that ggml-org#900 still owes.

@bong-water-water-bong
bong-water-water-bong merged commit 2edd945 into 1bit/hrx-vulkan-patched Nov 4, 2026
bong-water-water-bong added a commit that referenced this pull request Nov 4, 2026
ggml-org#900) (#202)

resident + parked is bounded by the arena and the arena by the limit, so the snapshot of a capacity miss is
always limit + one weight. Printed as advice that is the measured 6 MiB-at-a-time climb (2304 -> 2310 on a run
whose floor is 2560) and, below the budget in force, the measured 38 <-> 44 MiB cycle. The capacity branch now
names the numbers and says the snapshot cannot size the run; the fragmented wording (#180) is untouched and the
unbounded arm no longer prints limit 0.0 MiB.

Co-authored-by: bong-water-water-bong <[email protected]>
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/i900-arena-refusal branch November 12, 2026 21:16
bong-water-water-bong pushed a commit that referenced this pull request Nov 12, 2026
Bind exact router ID view spans and gather scalar expert scales with runtime ID bounds checks. Validated on gfx1151 with focused operator/backend tests, full paired HRX/Vulkan perplexity, and generation. High absolute perplexity and CPU REPEAT fallback remain documented limitations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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