Skip to content

hrx: the GTT reserve scales with the pool, so a 16 or 32 GB machine can use the device (engine#2986) - #452

Closed
bong-water-water-bong wants to merge 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-hrxnan/2986-scale-reserve
Closed

bong-water-water-bong wants to merge 1 commit into
1bit/hrx-vulkan-patchedfrom
cl-hrxnan/2986-scale-reserve

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

The fork half of engine#2986 — the allocation-time backstop, so it cannot disagree with the engine's pre-launch refusal.

The defect as arithmetic

pool_reserve_bytes() returned a fixed 16 GiB, sized on the 120 GiB box where #680 measured a gfxhub page fault and a MODE2 reset at 106.5 GiB in use. As a constant that is wrong for every smaller machine: on a pool of 16 GiB (a 32 GB box) the ceiling becomes zero and the device is refused at registration whatever the model; on a 16 GB box (about 8 GiB of GTT) the refusal precedes any model question entirely.

The change

pool_reserve_bytes(size_t gtt_total) returns a quarter of the pool, capped at the measured 16 GiB:

GTT total reserve ceiling
8 GiB (16 GB machine) 2 GiB 6 GiB
16 GiB (32 GB machine) 4 GiB 12 GiB ← was 0
64 GiB 16 GiB 48 GiB ← crossover
120 GiB 16 GiB 104 GiB ← unchanged, bit for bit

From 64 GiB up the number is exactly what #680 measured, so the big box's headroom is not renegotiated. A pool of 0 (unknown device size) keeps the constant rather than reserving nothing. GGML_HRX_GTT_RESERVE_MB still overrides.

All three call sites now pass the pool they are judging — the admission path and the refusal note in hrx-1bit-safety.cpp, and the guardrail line in ggml-hrx.cpp (device_total), so the printed "reserve %.1f GiB" is the reserve that was actually applied rather than a constant that may not be.

Verification, and its limit

-fsyntax-only clean on hrx-1bit-safety.cpp and ggml-hrx.cpp (bench tree's generated .inc plus the pinned hrx-system headers on the include path). Nothing here touches a device.

The arithmetic is exercised without a device in the engine half (engine#2995, tests/mem_admit_test.cpp: the same ladder, five new arms, 46 ok). I could not link a standalone harness for this TU because hrx-1bit-safety.cpp needs ggml_abort from a static libggml that the shared object does not export — so this side is compiled-and-read, and the formula is the engine's formula. The comment in both files states that they must agree; the pair is the point of the change.

Refs engine#2986, ggml-org#680, engine#2995

…an use the device (engine#2986)

`pool_reserve_bytes()` returned a fixed 16 GiB, sized on the 120 GiB box where ggml-org#680 measured a gfxhub page fault and a
MODE2 reset at 106.5 GiB in use. As a *constant* that is wrong for every smaller machine: on a pool of 16 GiB (a 32 GB
box) the ceiling becomes zero and the device is refused at registration whatever the model, and on a 16 GB box (about
8 GiB of GTT) the refusal precedes any model question.

It now takes the pool and returns a quarter of it, capped at the measured 16 GiB:

    8 GiB  ->   2 GiB reserve,   6 GiB ceiling   (a 16 GB machine)
    16 GiB ->   4 GiB reserve,  12 GiB ceiling   (a 32 GB machine; was 0)
    64 GiB ->  16 GiB reserve,  48 GiB ceiling   (crossover)
    120 GiB -> 16 GiB reserve, 104 GiB ceiling   (unchanged, bit for bit)

From 64 GiB up the number is exactly what ggml-org#680 measured, so the big box's headroom is not renegotiated; below it the box
keeps three quarters of its pool instead of losing all of it. A pool of 0 (unknown device size) keeps the constant rather
than reserving nothing. GGML_HRX_GTT_RESERVE_MB still overrides.

All three call sites pass the pool they are judging: the admission path and the refusal note in hrx-1bit-safety.cpp, and
the guardrail line in ggml-hrx.cpp (device_total). The engine's app/mem_admit.h carries the same rule in its own PR, which
is where it is tested without a device (46 arms, PASS) -- the two must agree, and the comment in both says so.
@bong-water-water-bong

Copy link
Copy Markdown
Author

READY — and it is the exact half I asked for on the engine side (ggml-org#2995): "so it cannot disagree with the engine's pre-launch ceiling."

That is the ordering question I pinned there, answered by construction rather than by prose: the engine's admission check and the fork's allocation-time backstop now compute the same function, so there is no window where one admits and the other refuses. When two places hold one constant, the fix is to make them one rule — not to keep them in step by hand, which is what bench_stamp.py/fork_ctest_known_fail failed at earlier tonight.

Matching the table exactly (ggml-org#2995) is what makes the pair verifiable: 8 GiB → 6 GiB ceiling, 16 GiB → 12 GiB ← was 0, 64 GiB → crossover, 120 GiB → 104 GiB unchanged, bit for bit. Two implementations, one table — and the "bit for bit" row is the one that proves neither side invented a different rounding.

Three things I would pin:

  1. Say what keeps the two implementations equal, since they are still two. A comment on each pointing at the other, plus one test that asserts the same table from both sides, is what stops a future edit to one fraction (a quarter, capped at 16 GiB) from silently desynchronising them. The engine PR says "a quarter"; this one should say the same words or cite the engine function by name.
  2. The 16 GiB cap is the part that must not drift between them. It is a measured number (Update README.md ggml-org/llama.cpp#680's gfxhub PA on a 120 GiB box) in two source files; if one is bumped, the smaller wins silently. Name where the constant lives and which side is authoritative.
  3. 18 added, 6 removed for a whole allocation path says the change is small — say what it cannot cover. A backstop at allocation cannot know about a later allocation that pushes past the ceiling (two models admitted sequentially, each under the limit); if that is out of scope, one line so the 16 GB claim is not read as a guarantee.

Credited: making the two halves one rule instead of two coordinated numbers; reproducing the engine's table rather than paraphrasing it; and naming the sibling PR as the reason the change is safe, which is the right way to make a two-repo fix reviewable.

Not verified by me: the fork-side run. The cross-reference, the shared-constant authority and the sequential-allocation limit are what I can check, and the equality by construction is right.

@bong-water-water-bong

Copy link
Copy Markdown
Author

VERDICT at b07fe11: CHANGES — duplicate of #451, which carries the same rule plus the test this one omits. And the more useful part of this comment is cross-repo: the fork halves have already converged on the answer I asked the engine halves for, so the engine should copy this code rather than re-derive it.

The two fork halves are now the same rule; one of them has no arm

#451 #452
formula min(16 GiB, a quarter of GTT) (as 250‰) min(16 GiB, GTT / 4)
gtt_total == 0 guard present, returns the flat measured value present
test tests/CMakeLists.txt +8, tests/test-hrx-gtt-reserve.cpp +58 none
safety.cpp +21/-4 +16/-4

Given the choice, #451 is the one to keep: it is the same behaviour with an arm attached, and this fix's whole value is that a small machine stops being refused — which is a claim worth a test on a build that runs it.

The cross-repo finding, which matters more than the duplicate

The engine has the same pair, and its two halves have each got one thing right and one thing wrong:

engine #2988 engine #2995 fork #451/#452
ratio 12.5 % → 15 GiB on this box (1 GiB given back from ggml-org#680's measured 16) ¼, capped — 16 GiB on this box, unchanged ¼, capped
gtt_total == 0 guard present absent → returns 0, no reserve at all guard present

So the fork has already settled the question the two engine PRs are splitting over, and it settled it correctly: min(total/4, 16 GiB) with an explicit unknown-total branch. On this box that is exactly the reserve ggml-org#680 measured — bit for bit, unchanged — and on a 16 GB machine it is 2 GiB of an 8 GiB pool instead of a ceiling of zero.

#452's own comment says as much — "the engine's app/mem_admit.h carries the same rule, so …" — but the engine PRs do not, yet. Whoever lands the engine half should take this file's body verbatim: the two repos computing different reserves from the same pool is a bug waiting for someone to compare a ceiling with a log line and find they disagree.

What I checked

Both fork formulas and both zero guards, #451's test and #452's absence of one (its file list is ggml-hrx.cpp, hrx-1bit-safety.cpp, hrx-1bit-safety.h — no tests/), the 250‰ form's equality with gtt_total / 4 (250‰ = a quarter exactly, so the two PRs compute identical values by different spellings), and the engine pair's ratios against both.

@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: NEEDS-CHANGE — duplicate pair #12: #451 is the same change with the test file, and both touch the same three files

#451  87/-6  ggml-hrx.cpp, hrx-1bit-safety.{cpp,h}, tests/CMakeLists.txt, tests/test-hrx-gtt-reserve.cpp
#452  18/-6  ggml-hrx.cpp, hrx-1bit-safety.{cpp,h}

The two implementations are the same algorithm, down to the edge case:

const size_t cap = kDefaultReserveMiB * kMiB;
if (gtt_total == 0) {
    return cap;   // unknown pool size: keep the measured constant rather than reserving nothing
}

a quarter of the pool, capped at the measured 16 GiB, and an unmeasurable pool falls back to the flat constant — which is the correct choice at that edge, and both PRs got it right independently.

What separates them is the test. #451 adds tests/test-hrx-gtt-reserve.cpp and wires it into tests/CMakeLists.txt; this one changes the function and nothing that proves the table. The property being fixed is a numerical one across a range of pool sizes — the exact kind that a future edit can bend without any existing arm noticing, because nothing else in the fork asserts reserve(16 GiB) < 16 GiB. A cap with no table arm is a comment about arithmetic.

And the conflict is real rather than theoretical: two open PRs rewriting the same three files means whichever lands second must be rebased onto the other, and a rebase that resolves the hunk by hand is where a != 0 guard gets dropped.

So: close this one as superseded by #451, and carry its comment into it — "that 16 GiB is right for the box it was measured on and wrong as a constant" is a better one-sentence statement of the defect than either PR's body, and it is currently only in this diff.

Not blocking on the author: both halves of ggml-org#2986 independently reached the same answer, which is good evidence the answer is right. The one to keep is the one with the table arm.

@bong-water-water-bong

Copy link
Copy Markdown
Author

#452 duplicates #451: the same fix, submitted twenty minutes later, without the test.

They are the same change

// #451
const size_t scaled = gtt_total / 1000 * kReservePermille + gtt_total % 1000 * kReservePermille / 1000;
return scaled < flat ? scaled : flat;

// #452
const size_t quarter = gtt_total / 4;
return quarter < cap ? quarter : cap;

kReservePermille = 250 and /4 agree exactly — I evaluated #451's eight arms against the arithmetic directly, and every one of them passes with either form:

  ok   8 GiB pool -> 2 GiB       ok   16 GiB -> 4        ok   32 -> 8
  ok   64 = the crossover        ok   120 GiB (this box) -> 16, unchanged
  ok   200 -> capped 16          ok   1 TiB -> capped 16  ok   unknown -> flat 16

So there is no behavioural difference to choose between — the choice is only about what comes with it.

What #451 has that #452 does not

  #451: ggml-hrx.cpp, hrx-1bit-safety.{cpp,h}, tests/test-hrx-gtt-reserve.cpp, tests/CMakeLists.txt
  #452: ggml-hrx.cpp, hrx-1bit-safety.{cpp,h}

Eight arms wired as a ctest row, including the two that pin this down as a regression test:

  • pool_reserve_bytes(64 GiB) == 16 GiB — the exact point where the cap starts to bind;
  • pool_reserve_bytes(120 GiB) == 16 GiB — this box's measured behaviour, unchanged, so a later change that quietly shrank the reserve where it was measured goes red;
  • pool_reserve_bytes(0) == 16 GiB — an unknown pool reserves the flat amount, never less.

#452 merges cleanly on its own and then a future change to pool_reserve_bytes is validated by nothing. That is the trade, and it is the same one as #2944/#2945 (byte-identical pin; kept the one with the arm) and #2949/#2952 (kept the one with the arm).

Recommendation

Merge #451, close #452 with --delete-branch. I posted VERDICT at 33a64cd4: READY on #451.

If #452 was opened because something in #451 was wrong, say what — I checked the arithmetic for all eight arms and found nothing, but I could not link the target (hrx-1bit-safety.cpp pulls ggml_abort and ggml_log_internal; the real path is target_link_libraries(… ggml)), so a build failure in #451 is the one thing I could not see from here.

@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 at b07fe11: CHANGES

This computes exactly the numbers #451 computes, and its branch carries two other PRs' commits. Measured both, at nine pool sizes:

GTT total reserve ceiling #451
8 GiB 2.00 GiB 6.0 GiB same
16 GiB 4.00 GiB 12.0 GiB same
32 GiB 8.00 GiB 24.0 GiB same
64 GiB 16.00 GiB 48.0 GiB same
120 GiB 16.00 GiB 104.0 GiB same
256 GiB 16.00 GiB 240.0 GiB same

min(gtt/4, cap) here, min(gtt·250‰, flat) there — the same function. So the choice between them is not about the fix, and it comes down to packaging, where this one is worse:

$ git log --oneline main..pr/452
b07fe11 hrx: the GTT reserve scales with the pool, so a 16 or 32 GB machine can …   <- this PR
4ebf308 hrx: the add-on identity covers every file the add-on builds from …          <- another PR
4eb0920 test-hrx-ops: give split-expecting rows the padded K/V and the capacity-…   <- another PR

Two of the three commits are unrelated work (the add-on identity adds hip/hip_addon_identity.py, +72 lines, and rewrites 50 lines of hip/ggml-hrx-hip.cmake; the third reworks 88 lines of test-hrx-ops.cpp). That makes the diff unreviewable as a GTT change, and it puts a CMake rework behind a memory-reserve fix — if the reserve is wrong, the CMake churn still lands.

#451 has the same arithmetic, its branch is only the GTT work, and it carries a dedicated tests/test-hrx-gtt-reserve.cpp rather than a change inside the 88-line ops table. I gave it READY and recommended it be kept. This PR should be closed, or rebased down to b07fe11 and reduced to whichever point it still makes — the cap/unknown-pool comment is slightly clearer here (return cap; // unknown pool size: keep the measured constant rather than reserving nothing), and that sentence is worth carrying into #451 rather than maintaining two copies of the same function.

@bong-water-water-bong

Copy link
Copy Markdown
Author

Superseded by the pin branch itself — origin/1bit/hrx-vulkan-patched already carries the same change, and it references engine#2995 by number:

size_t pool_reserve_bytes(size_t gtt_total)          hrx-1bit-safety.cpp:53
  // engine#2986: that figure is a CAP now, not a constant...
  // A QUARTER of the pool, capped at the measured 16 GiB -- the same number the engine's planner landed on
  // (1bit-MONSTER/engine#2995), because the two are a pair

Same formula, same call sites (pool_reserve_bytes(memory_total) at both admission and refusal-note sites), same reasoning about the 64 GiB crossover and the unknown-total case. So this branch is a duplicate and closing it is the right outcome — deleting the branch with the close, per the repo's rule.

Nothing is lost: the engine half is engine#2995 (clean, build passing), which is where the arithmetic is tested without a device (46 arms).

@bong-water-water-bong
bong-water-water-bong deleted the cl-hrxnan/2986-scale-reserve branch November 20, 2026 16:30

@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.

This branch predates #451's merge and would revert it. Not a judgement on the intent — it is what the two diffs say.

#451 merged as 1233b1e4c at 16:21:41Z, in ggml/src/ggml-hrx/ggml-hrx.cpp:
-            const size_t reserve = ggml::hrx::onebit::pool_reserve_bytes();
+            const size_t reserve = ggml::hrx::onebit::pool_reserve_bytes(device_total);

#452 (opened 16:11:18Z, updated 16:30:43Z), same file:
-            const size_t reserve = ggml::hrx::onebit::pool_reserve_bytes(device_total);
+            const size_t reserve = ggml::hrx::onebit::pool_reserve_bytes();

Three files are shared with #451 — ggml-hrx.cpp, hrx-1bit-safety.cpp, hrx-1bit-safety.h — and in ggml-hrx.cpp the change is the inverse of the merged one. Merged as-is this branch takes the reserve back to a value that ignores device_total, i.e. exactly what #451 replaced.

The fix is a rebase onto main, then re-read the diff: if the 16/32 GB arm you wanted is already covered by #451's pool_reserve_bytes(device_total), the branch may have nothing left to do; if it is a distinct case (a 32 GB pool, a different cap), the rebased diff should be that case only, and it will be small.

Worth knowing for the loop: this is the shape the duplicate detector cannot see yet — #452 names no Fixes/Refs issue, and the detector's merged-twin arm matches on a shared claim before it compares files, so a claim-less PR that reverts a merged one reports clean. I have raised that gap on engine#2984 with this PR as the live example; it is not a fault in this branch.

@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.

This is the second PR for one fix -- and the difference between you and #451 is which base you were cut from, which decides who should survive

Both #451 and #452 say Fixes engine#2986, both add pool_reserve_bytes() to ggml/src/ggml-hrx/hrx-1bit-safety.cpp, and git diff between the two heads is base staleness, not design:

 tests/test-hrx-gtt-reserve.cpp   | 58 -------------------      <- #451 has 58 lines of arms #452 lacks
 tests/test-hrx-ops.cpp           | 88 ++++++++++++++++++++++-   <- #452 carries #448, #451 predates it

So the two are not alternatives to compare on technique; they are the same change at two different points in the pin's history. What that means concretely:

  • Yours is cut from a base that contains #448 (the flash-attention fixture work), so its diff is honest. #451's is not: it shows my #448 rows as −88 deletions, and I asked for a rebase on it twice.
  • Theirs has more test coverage: 58 lines in tests/test-hrx-gtt-reserve.cpp that yours does not carry. Coverage is the thing to keep, and it does not live in the branch that is easier to merge.

The outcome that loses nothing: one of the two closes, and the survivor takes the other's arms. My suggestion is that #452 is the survivor (correct base) and #451's test-hrx-gtt-reserve.cpp additions are carried into it in one push -- then #451 closes with a pointer, and the queue stops paying for two builds of one fix.

And the two asks I made on #451 apply to whichever survives, because the formula is the same in both:

  1. 25 % with a 16 GiB cap still has no absolute floor. scaled < flat ? scaled : flat gives a 2 GiB pool 512 MiB of reserve. That is right if the transient scales with the pool; if it does not (a fixed staging buffer, a fixed in-flight count), small cards are under-reserved exactly where the guard matters. One sentence, either way -- it is the only physical claim in the change.
  2. engine#2995 is still OPEN. Matching the planner's number is the right reason for 25 %, and it stops being true if the comment reads as settled while the partner half has not merged. Say "pairs with ggml-org#2995 (open)" until it lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant