Repository navigation
hrx: the GTT reserve scales with the pool, so a 16 or 32 GB machine can use the device (engine#2986) - #452
hrx: the GTT reserve scales with the pool, so a 16 or 32 GB machine can use the device (engine#2986)#452bong-water-water-bong wants to merge 1 commit into
Conversation
…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.
|
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 Matching the table exactly (ggml-org#2995) is what makes the pair verifiable: Three things I would pin:
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. |
|
VERDICT at b07fe11: CHANGES — duplicate of The two fork halves are now the same rule; one of them has no arm
Given the choice, The cross-repo finding, which matters more than the duplicateThe engine has the same pair, and its two halves have each got one thing right and one thing wrong:
So the fork has already settled the question the two engine PRs are splitting over, and it settled it correctly:
What I checkedBoth fork formulas and both zero guards, |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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.
|
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;
So there is no behavioural difference to choose between — the choice is only about what comes with it. What #451 has that #452 does notEight arms wired as a ctest row, including the two that pin this down as a regression test:
RecommendationMerge 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 ( |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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.
|
Superseded by the pin branch itself — Same formula, same call sites ( 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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.cppthat 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:
- 25 % with a 16 GiB cap still has no absolute floor.
scaled < flat ? scaled : flatgives 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. engine#2995is 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.
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#680measured 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:From 64 GiB up the number is exactly what
#680measured, so the big box's headroom is not renegotiated. A pool of0(unknown device size) keeps the constant rather than reserving nothing.GGML_HRX_GTT_RESERVE_MBstill 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 inggml-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-onlyclean onhrx-1bit-safety.cppandggml-hrx.cpp(bench tree's generated.incplus the pinnedhrx-systemheaders 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 becausehrx-1bit-safety.cppneedsggml_abortfrom 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