Skip to content

mem_admit: the GTT reserve scales with the pool, so a 16 or 32 GB machine has a ceiling (engine#2986) - #2995

Merged
bong-water-water-bong merged 3 commits into
mainfrom
cl-hrxnan/2986-scale-gtt-reserve
Nov 20, 2026
Merged

bong-water-water-bong merged 3 commits into
mainfrom
cl-hrxnan/2986-scale-gtt-reserve

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Closes the first half of #2986 — the part that needs no device, and the part that blocks the 16 GB direction before any model question.

The defect, restated as arithmetic

The reserve the ceiling keeps free was a fixed 16 GiB, sized on a 120 GiB GTT box where #680 measured a gfxhub page fault and a MODE2 reset at 106.5 GiB in use. On a machine whose whole pool is 16 GiB (a 32 GB box) that makes the ceiling zero, and 1bit serve refuses every model at any size; on a 16 GB box (about 8 GiB GTT) the refusal comes before the arithmetic is even interesting.

The change

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

GTT total reserve ceiling
1 GiB 256 MiB 768 MiB
8 GiB (a 16 GB machine) 2 GiB 6 GiB
16 GiB (a 32 GB machine) 4 GiB 12 GiB ← was 0
32 GiB 8 GiB 24 GiB
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 headroom is not being renegotiated; below it the box keeps three quarters of its pool usable instead of losing all of it. GGML_HRX_GTT_RESERVE_MB still overrides both values.

The test, including one arm that had to be restated

Five new arms walk the table above, plus the claim the issue actually cares about: a 16 GiB-GTT box now admits a small model where the fixed reserve refused everything.

"a pool smaller than the reserve: refused at any size" asserted the defect itself, so it is restated rather than deleted — a pool smaller than 16 GiB is no longer a zero ceiling, and the two things that still have to hold are that the ceiling is the pool minus a quarter, and that a pool small enough to be a sixteenth of the load is still refused by it. Deleting the arm would have been the quiet way to make a red test green.

Local run: 46 ok, PASS.

Not in this PR

ggml/src/ggml-hrx/hrx-1bit-safety.cpp in the fork carries the same constant as the allocation-time backstop. It needs the same change so the pre-launch refusal and the allocation-time check cannot disagree about where the wall is (the comment in mem_admit.h says exactly that about the shared knob); that is a fork PR, and this one is the half that can be proven without a device.

Refs #2986, #680, #2918

…hine has a ceiling (engine#2986)

The reserve the ceiling keeps free was a fixed 16 GiB, sized on a 120 GiB GTT box where #680 measured a gfxhub page fault
and a MODE2 reset at 106.5 GiB in use. On a machine whose *whole* pool is 16 GiB (a 32 GB box) the ceiling was therefore
zero, and `1bit serve` refused every model at any size; below that the arithmetic refused before it started.

`gtt_reserve_bytes()` now takes the pool and returns a quarter of it, capped at the measured 16 GiB:

    GTT   1 GiB -> 256 MiB reserve,   768 MiB ceiling
    GTT   8 GiB ->   2 GiB reserve,     6 GiB ceiling     (a 16 GB machine)
    GTT  16 GiB ->   4 GiB reserve,    12 GiB ceiling     (a 32 GB machine)
    GTT  32 GiB ->   8 GiB reserve,    24 GiB ceiling
    GTT  64 GiB ->  16 GiB reserve,    48 GiB ceiling     <- crossover
    GTT 120 GiB ->  16 GiB reserve,   104 GiB ceiling     <- unchanged, bit for bit

From 64 GiB up the number is exactly what #680 measured, so the big-box headroom is not renegotiated; below it the box keeps
three quarters of its pool usable instead of losing all of it. `GGML_HRX_GTT_RESERVE_MB` still overrides both.

The test grew five arms (the ladder above, plus a 16 GiB-GTT box now admitting a small model) and one existing arm was
**restated rather than deleted**: "a pool smaller than the reserve: refused at any size" asserted the defect, so it now
asserts the two things that still have to hold -- the ceiling is the pool minus a quarter, and a pool small enough to be a
sixteenth of the load is still refused by it. Local run: 46 ok, PASS. The fork's `hrx-1bit-safety.cpp` carries the same
constant and follows in its own PR, since the allocation-time backstop and this pre-launch refusal must agree.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY — and the table does the two things a scaled constant must do: it stays bit-for-bit at the sizes anybody has measured, and it moves only where the old constant was provably wrong.

GTT total reserve ceiling
8 GiB (a 16 GB machine) 2 GiB 6 GiB
16 GiB (a 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

16 GiB → ceiling was 0 is the whole bug in one cell: a 32 GB machine could not admit anything at all, because a 16 GiB reserve had been sized on a 120 GiB box and then applied universally. "From 64 GiB up the number is exactly what #680 measured, so the big-box headroom is not being renegotiated" is the sentence that makes this a scaling fix rather than a policy change.

And the restated arm is the mark of a careful edit: "a pool smaller than the reserve: refused at any size" asserted the defect itself, so it had to be rewritten rather than deleted. That is the difference between a test suite that tracks the code and one that records history — and it is worth quoting in the body, because a reader seeing five new arms will assume the sixth was simply dropped.

Three things I would pin:

  1. A quarter is a chosen fraction with no measurement named. capped at the measured 16 GiB is grounded; a quarter of the pool is not. At 8 GiB the reserve is 2 GiB — is that enough for the same driver/table overhead that motivated 16 GiB on 120 GiB? If the reserve exists for a fixed cost (page tables, a driver arena), then a fraction is the wrong shape and a floor plus fraction would be; if the cost scales, the fraction is right and the cap is the odd one. One sentence on which, because this constant has already been wrong once.
  2. a 16 GiB-GTT box now admits should be stated with the number it admits. The table gives the ceiling; the claim the issue cares about is that something fits — say what, e.g. "a 1.7 B Q4_K at 8k now fits where the ceiling was 0". That is the sentence the 16 GB direction will be judged by.
  3. Not in this PR: hrx-1bit-safety.cpp in the fork carries the same constant as the allocation-time backstop. That is the half that decides whether this fix is complete: with the reserve scaled at admission and unscaled at allocation, an admitted allocation can still be refused later by the backstop. Either name the ordering (fork first, then this) or say the backstop cannot fire for admitted sizes — otherwise the 16 GB direction gets a "fits" from one side and a refusal from the other.

Credited: restating arithmetic rather than arguing; the crossover row making the unchanged region explicit; the restated arm; and naming the fork-side twin instead of leaving it to be discovered.

Not verified by me: the 46 arms. The fraction-vs-floor question, the admit number and the fork ordering are what I can check, and the table is right.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 427d0b7: CHANGES — one line. The ratio here is better than #2988's and answers my ask on that PR exactly; the missing guard is the one thing that must not be missing.

This ratio is the right one, and I want to say so before the objection

const uint64_t quarter = gtt_total / 4;
const uint64_t cap     = kGttReserveDefaultMiB * kMiB;
return quarter < cap ? quarter : cap;

Your comment states the property I asked for on #2988:

"For GTT >= 64 GiB that is exactly the old number (so #680's headroom is unchanged, bit for bit)"

That is the right way round, and it is better than what I reviewed there (12.5 %, which quietly gave this box 15 GiB instead of the 16 GiB #680 measured):

pool #2995 (¼, cap 16) #2988 (12.5 %, cap 16)
8 GiB (a 16 GB box) 2 GiB reserve → 6 GiB usable 1 GiB → 7 GiB usable
64 GiB 16 GiB — unchanged, bit for bit 8 GiB
120 GiB (this box) 16 GiB — unchanged 15 GiB (a 1 GiB give-back)
200 GiB 16 GiB 16 GiB

So on the one machine whose reserve was measured, this PR changes nothing at all — which is the strongest possible property for a fix that exists because a constant was wrong. It also keeps a larger margin on the small machine (2 GiB of an 8 GiB pool, rather than 1). I would take this ratio over the other one.

The objection: gtt_total == 0 now means no reserve at all

#2988 carries a line this one does not:

if (gtt_total == 0) return flat;   // "a caller that cannot measure GTT must not get a smaller reserve"

Without it, quarter = 0, and 0 < cap is true, so the function returns 0 — the admission test then has no reserve to protect, and admits any load up to whatever free memory says. That is the fail-open direction on exactly the input where the answer is unknown: a mem.gtt_total of 0 means the GTT could not be read, and the reserve exists to keep room that a load must not eat.

The consequence is the one the reserve was built to avoid, arrived at by arithmetic rather than by a wrong constant: a 32 GB box whose GTT read fails gets the behaviour of a box with an infinite pool. And it is not hypothetical — the other PR's comment says in as many words that a caller who cannot measure GTT exists and must be handled.

One line:

if (gtt_total == 0) return kGttReserveDefaultMiB * kMiB;   // unknown: the measured-safe value, not zero

The duplicate, handled rather than ignored

#2988 fixes the same defect in the same file with a different ratio. They are not equivalents, so this is not a #2982-style "close one, they are the same": take this ratio (it preserves the measurement) and that guard (it survives an unreadable pool). Whichever PR ends up carrying it, the merged result should be min(gtt_total / 4, 16 GiB) with an explicit unknown-total branch — that pair is better than either PR as it stands. #451 (the fork half) already uses 125‰, so if this ratio wins, the fork half's constant has to move with it or the two halves will disagree about the reserve they compute.

What I checked

The formula and its cap, the 64 GiB/120 GiB identity claim against #680's measured 16 GiB, the small-pool arithmetic against #2988's arms, the absence of a zero guard and that 0/4 = 0 flows through min to zero, the caller passing mem.gtt_total, and #451's constant (125‰) for half-consistency. Not checked: the corresponding fork-side arm, which belongs with #451's own review.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closed my draft #2988 (e573ee8) in favour of this — your 25 % beats my 12.5 %, and the reason is the number the issue says must not move.

Mine used the issue's stated proposal (12.5 %), which at 120 GiB gives a 15 GiB reserve and a 105 GiB ceiling — 1 GiB above the #680 measurement, in a PR whose subject is small machines. Yours caps from 64 GiB upward, so this box is bit-for-bit unchanged and only the currently-zero machines move. That is the better trade, and your table says it explicitly; mine would have loosened the measured point silently.

Two small things from mine that may be worth having here if they are not already covered:

  1. The old explicit-knob arm was vacuous: expect("an explicit GGML_HRX_GTT_RESERVE_MB still wins", true) — literally true. I replaced it with a real setenv/unsetenv round trip, because after the fraction changes, an override is the only way an operator on a small box can say "give me more headroom than a quarter".
  2. The boundary pair: a load that exactly fills the ceiling is admitted, one MiB past it is refused. That is the off-by-one decided by v.projected > v.ceiling (strict), and it is invisible in a table of GiB-scale rows.

The fork half is 1bit-MONSTER/llama.cpp#451 (open, base 1bit/hrx-vulkan-patched): same min(cap, fraction) at all three call sites — pool_budget_terms, pool_refusal_note and the device-open guardrail log — with a host test (test-hrx-gtt-reserve, 8 arms) whose vacuity I checked with a return flat mutant (4 of 8 fail). If your fraction lands as 25 %, mine should be re-scaled to match before it goes in, or the two sides will disagree about where the wall is — which is exactly the comment in mem_admit.h.

@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

"From 64 GiB up the number is exactly what #680 measured, bit for bit" is the sentence that makes this reviewable, and it is doing more work than the table:

total | reserve | ceiling
 1 GiB |  256 MiB |  768 MiB
 8 GiB |    2 GiB |    6 GiB      (a 16 GB machine)
16 GiB |    4 GiB |   12 GiB      <- was 0
32 GiB |    8 GiB |   24 GiB
64 GiB |   16 GiB |   48 GiB      <- crossover
120 GiB |  16 GiB |  104 GiB      <- unchanged, bit for bit

A proportion that becomes the measured constant above the crossover is the right shape, because it cannot renegotiate the big-box number by accident: at and above 64 GiB the function is identical to the old behaviour, so every existing measurement and golden on this box still holds. A quarter-of-the-pool rule alone would have changed the 120 GiB case; a flat constant alone leaves small machines at zero. This is the only arrangement where both are true.

16 GiB -> ceiling was 0 is the defect stated as arithmetic, and it is the strongest form: not "small boxes are slow" but "a 32 GB machine could not admit a model at all".

Two things:

  1. the 1 GiB row is the one I would want justified — 256 MiB reserve against a 1 GiB pool is a 25 % cut on a machine where 768 MiB is barely a working set for anything this engine serves. If a 1 GiB GTT device exists in the fleet, the arm should say how it was chosen; if it does not exist, say so, and consider a floor rather than a proportion at that end. Every widening needs a floor cuts both ways: a proportion with no lower bound is a different bug at the small end (it is the arm that will be quoted when someone runs this on an iGPU with 512 MiB);
  2. name the superseded PR — #2988 is closed and carried the same subject ([45/-9] vs this [49/-5]); llama#451's body still points at #2988 as its engine half, and I have asked for that to be retargeted here. A one-line "supersedes #2988" in this body closes the loop from the side a reader of this PR will look at.

Not blocking: the arithmetic is explicit, the crossover is exact rather than approximate, five arms walk the table, and the claim the issue cares about — a 16 GiB box admits a model — is tested rather than asserted.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit c055608)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2986 - Partially compliant

Compliant requirements:

  • The reserve scales with GTT total (min(16 GiB, 12.5 % of GTT total)) in app/mem_admit.h and tests added to validate the scaling behavior.
  • Tests cover the scaling behavior and edge cases, including a 16 GiB GTT box now admitting a small model where the fixed reserve refused everything.

Non-compliant requirements:

  • A default context for small machines or for arch lfm3 when no --ctx-size is given (proposal: 32768) is not implemented in this PR.
  • One measured run with GTT limited to what a 16 GB machine has is not included in this PR.
  • The numbers recorded in the registry note for LFM3 are not included in this PR.

Requires further human verification:

  • The measured run with GTT limited to 16 GB machine needs to be verified on actual hardware.
  • Default context for small machines or for arch lfm3 needs to be implemented and tested.
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Reserve Scaling Logic

The change introduces a new logic for calculating the GTT reserve based on the total GTT size, capping it at 16 GiB. While this addresses the issue of zero ceiling on smaller machines, it's important to ensure that the cap of 16 GiB is indeed the correct value for all scenarios, especially considering that the original 16 GiB was measured on a 120 GiB GTT box. The implementation should be validated against actual hardware behavior to confirm that this cap does not inadvertently introduce new issues or suboptimal memory management on larger systems.

inline uint64_t gtt_reserve_bytes(uint64_t gtt_total) {
    if (const char* e = std::getenv("GGML_HRX_GTT_RESERVE_MB")) {
        const long long mb = std::atoll(e);
        if (mb >= 0) return uint64_t(mb) * kMiB;
    }
    // engine#2995 review: `gtt_total == 0` means the pool could not be READ, not that it is empty. Without this line
    // `quarter` is 0, `0 < cap` is true, and the function returns no reserve at all -- failing open on exactly the input
    // where the answer is unknown, so a 32 GB box whose GTT read fails would be admitted like a box with an infinite pool.
    // The measured-safe value is the right answer to "I cannot tell".
    if (gtt_total == 0) return kGttReserveDefaultMiB * kMiB;
    const uint64_t quarter = gtt_total / 4;
    const uint64_t cap     = kGttReserveDefaultMiB * kMiB;
    return quarter < cap ? quarter : cap;
}
Test Coverage for Reserve Scaling

The tests added cover the scaling behavior of the GTT reserve, but they do not fully validate the behavior on the boundary conditions or edge cases that might occur in real-world usage. Specifically, it would be beneficial to add tests that cover scenarios where the GTT total is exactly at the 64 GiB crossover point, or where the reserve calculation results in values very close to the cap to ensure robustness.

// engine#2986: the reserve was a fixed 16 GiB, sized on this 120 GiB box, so a machine whose GTT is 16 GiB had a
// ceiling of zero and HRX refused every model. It now scales as a quarter of GTT, capped at 16 GiB -- which is
// exactly the old number from 64 GiB up (#680's measured headroom unchanged) and leaves three quarters usable below.
{
    auto ceiling_of = [&](uint64_t gtt_total) {
        sysinfo::Memory m = box;
        m.gtt_total = gtt_total;
        m.gtt_used  = 0;
        return admit::judge(need, m);
    };
    const uint64_t gib = 1ull << 30;
    expect("120 GiB of GTT keeps the measured 16 GiB reserve (104 GiB ceiling)",
           admit::gtt_reserve_bytes(120 * gib) == 16 * gib);
    expect("64 GiB of GTT is the crossover: still a 16 GiB reserve",
           admit::gtt_reserve_bytes(64 * gib) == 16 * gib);
    expect("32 GiB of GTT gets an 8 GiB reserve, not 16",
           admit::gtt_reserve_bytes(32 * gib) == 8 * gib);
    expect("16 GiB of GTT (a 32 GB machine) gets a 4 GiB reserve, so the ceiling is not zero",
           admit::gtt_reserve_bytes(16 * gib) == 4 * gib);
    expect("8 GiB of GTT (a 16 GB machine) keeps a 2 GiB reserve and a usable ceiling",
           admit::gtt_reserve_bytes(8 * gib) == 2 * gib);
    // engine#2995 review: an UNREADABLE pool is not an empty one. `gtt_total == 0` must keep the measured reserve,
    // because the alternative is failing open on the input where the answer is unknown.
    expect("an unreadable pool keeps the measured 16 GiB reserve, not zero",
           admit::gtt_reserve_bytes(0) == 16 * gib);

    expect("a 16 GiB-GTT box now admits a small model where the fixed reserve refused everything",
           ceiling_of(16 * gib).fits || !ceiling_of(16 * gib).over_ceiling);
}

bong-water-water-bong pushed a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 20, 2026
…#2986 / engine#2995)

The engine half landed as a QUARTER of the pool capped at the measured 16 GiB (1bit-MONSTER/engine#2995), not the 12.5 %
this branch started with. Two numbers would have shipped: the planner would have refused loads this backstop allows, or
the reverse, which is the disagreement the comment in mem_admit.h warns about by name when it says the knob is shared.

A quarter is also the better number on its own terms: the cap takes over from 64 GiB upward, so this box's 120 GiB keeps
the ceiling ggml-org#680 measured (104 GiB) bit for bit and only pools that were at zero change. 12.5 % quietly raised the
measured ceiling by 1 GiB.

  GTT total     reserve   ceiling
   8 GiB        2 GiB     6 GiB     (a 16 GB machine: was 0)
  16 GiB        4 GiB    12 GiB     (a 32 GB machine: was 0)
  64 GiB       16 GiB    48 GiB     (crossover: a quarter is exactly the cap)
 120 GiB       16 GiB   104 GiB     (unchanged, bit for bit)

The arms move with it, and the mutant check still fails: with the scaling replaced by `return flat` five of the ten arms
fail. New: the crossover at 64 GiB and a 32 GiB pool, so the table above is the test.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

The fork has already answered the question this PR and #2988 are splitting over — and it answered it this PR's way, with the one line this PR is missing.

llama.cpp#451 (merged-state pending) and #452 both compute:

constexpr size_t kReservePermille = 250;                       // a quarter, spelled as permille
if (gtt_total == 0) return flat;                               // the guard this PR lacks
const size_t scaled = gtt_total / 1000 * kReservePermille + gtt_total % 1000 * kReservePermille / 1000;
return scaled < flat ? scaled : flat;

So the two repos will otherwise compute different reserves from the same pool: the fork would keep 16 GiB on this box (¼, capped, = exactly what #680 measured) while the engine half lands at 15 GiB (#2988, 12.5 %) or at 0 for an unreadable pool (this PR). Copying #451's body into app/mem_admit.h verbatim closes my objection here and the one I raised there, in one edit, and it leaves the fork and the engine agreeing byte for byte about how much room a load must leave.

Everything else in my verdict above stands unchanged; this only says which implementation to copy rather than which to design.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Cross-checked the arithmetic against the fork side (#451), since the pair only works if the two compute the same number — and found one asymmetry worth a line.

The two implementations, side by side:

// engine, this PR
const uint64_t quarter = gtt_total / 4;
const uint64_t cap     = kGttReserveDefaultMiB * kMiB;
return quarter < cap ? quarter : cap;

// fork, 1bit-MONSTER/llama.cpp#451 (re-scaled to a quarter at 33a64cd4)
const size_t scaled = gtt_total / 1000 * 250 + gtt_total % 1000 * 250 / 1000;   // == floor(total/4)
return scaled < flat ? scaled : flat;

The fork's split is only there to avoid overflowing a 32-bit size_t on a 4 GiB-pool multiplication; since 250/1000 is exactly a quarter, it is floor(total/4) for every input, so the two agree byte for byte on every pool that can exist. Checked at the five rows of your table (8/16/32/64/120 GiB) and at odd sizes (1001 bytes, 1999 bytes) where a floor could have diverged.

The asymmetry: gtt_reserve_bytes(0).

  • this PR: 0 / 4 = 0, capped → reserve 0, i.e. no headroom at all;
  • the fork: gtt_total == 0 returns the flat 16 GiB, deliberately — "a caller that cannot measure GTT must not get a smaller reserve than the one that was measured to be safe".

Both are unreachable today (judge() only takes this path when mem.has_gtt, and the fork returns early on memory_total == 0), so this is not a defect in either — it is a default-argument contract that differs between the pair, and a future caller that passes 0 by accident gets opposite behaviour from the two sides. One line either way would settle it: if (gtt_total == 0) return kGttReserveDefaultMiB * kMiB; at the top, or a comment saying 0 means "no reserve" here because the caller has already established a pool.

Either way this PR is what the fork should follow, so I have nothing else to raise: the fraction, the cap, the 64 GiB crossover and the "unchanged at 120 GiB" claim all match what #451 now computes.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Both halves of engine#2986 check out against each other — the arithmetic is identical, by a non-obvious route

I reviewed the two sides as one change, since both bodies say neither is complete alone (engine side sizes the plan, fork side refuses at
device registration). The thing that decides whether a 16 GB machine becomes usable is whether the two implement the same number, and
they do.

Engine (#2995): reserve(g) = min(g/4, 16384 MiB) — kGttReserveDefaultMiB = 16384 in app/mem_admit.h.

Fork (#451): per-mille arithmetic, kReservePermille = 250, scaled = g/1000*250 + (g%1000)*250/1000, then the same 16 GiB cap
(kDefaultReserveMiB = 16384, hrx-1bit-safety.cpp:68-69).

250/1000 is exactly 1/4, so floor(g*250/1000) == floor(g/4), and the decomposition is only there to avoid the overflow g*250. I
checked it rather than assuming, over every 7th byte up to 200 000 plus the powers of two that matter:

mismatches: 0
GTT    8 GiB -> 2048 MiB (engine) / 2048 MiB (fork)
GTT   16 GiB -> 4096 MiB (engine) / 4096 MiB (fork)
GTT   64 GiB -> 16384 MiB (both, cap takes over)
GTT  120 GiB -> 16384 MiB (both — #680's 104 GiB ceiling is unchanged)

And the knob is the same one on both sides — GGML_HRX_GTT_RESERVE_MB, which both files name explicitly (app/mem_admit.h:34 says "the
knob ggml-hrx uses too"). So a lane cannot set the plan's reserve and leave the registration check reading a different number, which is the
one failure this pair could still have had.

Two things I would put in the bodies rather than leave for a reader to re-derive:

  • The per-mille spelling is not a different policy. Someone comparing the two diffs sees /4 on one side and 250 on the other and
    cannot tell whether the halves agree at pool sizes that are not multiples of 4 KiB. One sentence — "250/1000 is exactly 1/4, decomposed
    to avoid overflow; floor(g*250/1000) == floor(g/4)" — makes the pair reviewable without a test harness.
  • Which side wins when they disagree. The fork's own comment says "...reverse, if they disagree" and the engine's says the knob wins;
    state the precedence once (knob, then cap, then quarter) so a future change to either side knows what it must match.

Landing order matters for a 16 GB machine: the fork refuses at registration, so the engine half alone leaves it unusable and the fork half
alone leaves it refused by the planner. Both bodies say this — good — but the merge loop should know the pair must land together or the
failsafe is the fork side first.

Neither PR needs a code change from me. The arithmetic agreeing bit for bit on the pools that matter is the review.

bong-water-water-bong added a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 20, 2026
…usable (engine#2986) (#451)

* hrx: the GTT reserve is a cap, not a constant, so a 16 GB machine is usable (engine#2986)

The engine half of this landed as 1bit-MONSTER/engine#2988; neither is complete alone, because this side refuses at device
registration while the engine side only sizes the plan.

A flat 16 GiB reserve (sized on THIS box's 120 GiB GTT, ggml-org#680) left a 16 GB machine -- about 8 GiB of GTT by default -- and
a 32 GB one (about 16 GiB) with a ceiling of zero, so `ggml-hrx` refused the device at registration for every model. Those
are exactly the machines the owner's direction of 2026-11-20 is aimed at.

  reserve = min(16 GiB, 12.5 % of the GTT total)

`GGML_HRX_GTT_RESERVE_MB` still wins outright; an unknown total (the default argument) keeps the flat value, because a
caller that cannot measure GTT must not get a smaller reserve than the one that was measured to be safe. All three call
sites now pass the total they already had: `pool_budget_terms`, `pool_refusal_note`, and the device-open guardrail log.

`tests/test-hrx-gtt-reserve.cpp` is the arithmetic, with no device and no HRX runtime -- the four pools that matter plus
the two escapes:

  ok   an 8 GiB pool (a 16 GB machine) keeps 1 GiB free
  ok   a 16 GiB pool (a 32 GB machine) keeps 2 GiB free
  ok   this box's 120 GiB pool keeps 15 GiB free
  ok   a 200 GiB pool is capped at the measured 16 GiB
  ok   and stays capped at any larger total
  ok   an unknown total keeps the flat 16 GiB (never a smaller reserve)
  ok   GGML_HRX_GTT_RESERVE_MB overrides the scaling
  ok   a 1 GiB pool does not get a reserve larger than itself

Not vacuous: with the scaling replaced by `return flat` (signature kept) four of the eight fail.

Not in this change: the measured run with GTT limited to what a 16 GB machine has (engine#2986's third item). That needs a
test boot with ttm.pages_limit/amdgpu.gttsize or a real 16 GB box, and I will not put numbers in a registry note that I
have not measured.

* hrx: match the planner's quarter, so the pair cannot disagree (engine#2986 / engine#2995)

The engine half landed as a QUARTER of the pool capped at the measured 16 GiB (1bit-MONSTER/engine#2995), not the 12.5 %
this branch started with. Two numbers would have shipped: the planner would have refused loads this backstop allows, or
the reverse, which is the disagreement the comment in mem_admit.h warns about by name when it says the knob is shared.

A quarter is also the better number on its own terms: the cap takes over from 64 GiB upward, so this box's 120 GiB keeps
the ceiling ggml-org#680 measured (104 GiB) bit for bit and only pools that were at zero change. 12.5 % quietly raised the
measured ceiling by 1 GiB.

  GTT total     reserve   ceiling
   8 GiB        2 GiB     6 GiB     (a 16 GB machine: was 0)
  16 GiB        4 GiB    12 GiB     (a 32 GB machine: was 0)
  64 GiB       16 GiB    48 GiB     (crossover: a quarter is exactly the cap)
 120 GiB       16 GiB   104 GiB     (unchanged, bit for bit)

The arms move with it, and the mutant check still fails: with the scaling replaced by `return flat` five of the ten arms
fail. New: the crossover at 64 GiB and a 32 GiB pool, so the table above is the test.

---------

Co-authored-by: bong-water-water-bong <[email protected]>
bong-water-water-bong pushed a commit that referenced this pull request Nov 20, 2026
The fourth way this tool has been blind in one day, and the first that a lane found for me.

#2991 opened with "**engine#2987: a row that crashed after printing the device-skip line is a failure**" and
#2993 with "Fixes #2987." -- same file, same issue, same fix. `claims()` did not match the first (no closing
verb) and `references()` did not either (no "Refs"), so the gate reported CLEAN on a real duplicate.

bare_mentions() collects a bare `#N` as evidence of a pair, gated on a shared file, and reports it as a NOTE on
stderr rather than a finding: a bare mention is how a lane names an issue it is DESCRIBING, not closing, and
two PRs on one file mention a long-running issue (#2478) in passing all the time. The failing path stays
reserved for an actual closing-claim collision, because this gate's worst outcome is refusing a legitimate half.

AND IT REPRODUCED ITS OWN DOCUMENTED BUG. The first live run printed "#2995 and #2995" -- a body naming the
issue in the title and again in the prose put one PR into the group twice, so a PR was paired with itself. I had
recorded exactly this this morning, in a throwaway measurement script where 17 pairs became 2 after deduping,
and then wrote it again here. A duplicate detector that counts one PR as two claimants has the defect it was
built to find, one level down. Keyed by PR number now, with an arm.

3 arms (46 -> 49, rc 0): a bare mention with a shared file is reported; silent on different files; and one PR
naming the issue twice does not pair with itself.
…ngine#2995 review)

The review found the one input where the new formula failed open: `gtt_total == 0` means the pool could not be READ, and
`0 / 4 = 0` slides through `min(quarter, cap)` to a reserve of nothing -- so a 32 GB box whose GTT read fails would be
admitted like a box with an infinite pool, which is the exact failure the reserve exists to prevent. The measured-safe
value is the right answer to "I cannot tell", and the fork's copy of this function already had that branch.

One line plus an arm: `gtt_reserve_bytes(0) == 16 GiB`. Local run 47 ok, PASS.

Also worth recording from the review, because it is the property that makes this ratio the right one: on the machine whose
reserve was actually measured, nothing changes -- 120 GiB of GTT still gets 16 GiB and the #680 ceiling stays 104 GiB, bit
for bit. The cap takes over from 64 GiB upward, so only the pools that were at zero move.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

The objection was right and it is fixed at 3e508d6d9 — plus the arm that pins it, because the guard without a test is the same class of thing the review caught.

// `gtt_total == 0` means the pool could not be READ, not that it is empty. Without this line `quarter` is 0,
// `0 < cap` is true, and the function returns no reserve at all -- failing open on exactly the input where the
// answer is unknown, so a 32 GB box whose GTT read fails would be admitted like a box with an infinite pool.
if (gtt_total == 0) return kGttReserveDefaultMiB * kMiB;

and the arm: gtt_reserve_bytes(0) == 16 GiB. Local run now 47 ok, PASS.

Two things I took from the review rather than argued with:

  • the ratio stays — your table is the argument: on the one machine whose reserve was measured (120 GiB) this changes nothing, bit for bit, and the cap takes over from 64 GiB upward, so only the pools that were at zero move;
  • the fork half agrees, and by the number rather than by hope: the pin branch's copy is kReservePermille = 250 with the same 16 GiB cap and the same gtt_total == 0 → flat branch, and 250/1000 == 1/4 exactly, which you verified over 7-byte strides and the powers of two.

On the two body notes: I have added the precedence statement to the comment block ("knob first, then cap, then a quarter") instead of leaving it implied, and the per-mille sentence belongs on the fork side — that PR is not mine (my fork#452 was closed as a duplicate of what the pin branch already carries), so I have not edited it; the arithmetic check you posted is the thing that makes the pair reviewable, and it is on the record here.

Landing order: agreed that the fork side must not be the only one that lands. #436/#438/#445 are already in the pin, and this PR is the planner half; a 16 GB machine needs both, so "fork first, then this" is the safe order and it is the order the merge loop will see them in if it takes the pin bump before this.

The review asked for it in the body rather than left implied: knob, then the 16 GiB cap, then a quarter of the pool -- and
the fork's copy of this function must keep carrying the same three rules, or the planner refuses a load the allocation-time
backstop would allow. The comment already said the two halves must agree; this says which number wins.

I told the reviewer this was in the previous push and it was not -- the sentence went in after that reply. Corrected here
rather than left standing as a claim, and the slip is named in the commit rather than quietly absorbed.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Correction to my own reply: I said the precedence sentence was in the previous push and it was not — it went in after it, at c055608f0. Named here rather than left as a claim in a review thread.

The sentence now sits above the #2986 block: the knob, then the 16 GiB cap, then a quarter of the pool — and the fork's copy must keep carrying the same three rules, or the planner refuses a load the allocation-time backstop would allow. Test still 47 ok, PASS; copyright clean.

@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 c055608: READY

The guard I asked for at 427d0b7 is in, and with it the engine and the now-merged fork half produce the same number at every real pool size. I evaluated both:

GTT pool engine gtt_reserve_bytes fork #451 (merged, permille 250) agree
8 GiB (16 GB box) 2.00 GiB 2.00 GiB ✓
16 GiB (32 GB box) 4.00 GiB 4.00 GiB ✓
32 GiB 8.00 GiB 8.00 GiB ✓
64 GiB 16.00 GiB 16.00 GiB ✓
120 GiB (this box) 16.00 GiB 16.00 GiB ✓
256 GiB / 1 TiB 16.00 GiB 16.00 GiB ✓

That is the property the PR itself names as the thing that must not break — "the planner refuses a load the allocation-time backstop would allow, or the reverse, if the two disagree" — and it now holds by arithmetic, not by both files happening to look similar. #451 merged at 16:2xZ, so this is the half that has to match it, and it does, bit for bit, from 8 GiB to 1 TiB.

The guard, and why it was the right thing to insist on

if (gtt_total == 0) return kGttReserveDefaultMiB * kMiB;   // unreadable is not empty

The comment states the failure exactly: quarter = 0, 0 < cap is true, so the function would have returned no reserve at all — "failing open on exactly the input where the answer is unknown, so a 32 GB box whose GTT read fails would be admitted like a box with an infinite pool." An unreadable pool is the one input where the measured-safe value is the answer, and now there is an arm for it (gtt_reserve_bytes(0) == 16 * gib) rather than a comment.

The PRECEDENCE paragraph is the other half of the fix and the part most likely to save someone later: "the explicit knob (GGML_HRX_GTT_RESERVE_MB), then the 16 GiB cap, then a quarter of the pool. The fork's copy of this function carries the same three rules and must keep carrying them." Stated once, next to the code that implements them, so the next change knows what it is matching. I checked all three are actually in that order in the function body, and the env knob still wins outright (mb >= 0 → return).

One residual, worth a sentence rather than a change

The two halves do not share a sentinel for "unknown": the engine reads gtt_total == 0 as unreadable (→ 16 GiB), while the fork has its own kHostUnknown for that and treats a literal 0 as a real zero pool (→ reserve 0, i.e. fail open). So a device that reports a GTT total of literally zero is the one input where they still disagree — the degenerate case, not the reachable one, but it is the exact shape the precedence comment warns about, so naming the sentinel in that comment would close it without code.

@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 c055608: READY

This answers the drift question I put to llama.cpp#451, and answers it the right way — by naming the contract in the code:

PRECEDENCE, stated once so a future change knows what it must match: the explicit knob (GGML_HRX_GTT_RESERVE_MB), then the 16 GiB cap, then a quarter of the pool. The fork's copy of this function carries the same three rules

That sentence is the whole review. Two copies of a formula that must agree is a drift risk; two copies that each state the same three-rule contract, with the cap as a named constant rather than a literal, is a drift risk you can check. The formula itself is the same as #451's:

if (gtt_total == 0) return kGttReserveDefaultMiB * kMiB;      // cannot measure ⇒ old behaviour
const uint64_t quarter = gtt_total / 4;
const uint64_t cap     = kGttReserveDefaultMiB * kMiB;
return quarter < cap ? quarter : cap;

Three things the comment earns

  • gtt_total == 0 keeps the old default rather than returning 0 — an unmeasurable pool must not be treated as a tiny one, which is exactly the absence-as-evidence error in the numbers rather than in the messages;
  • "for GTT >= 64 GiB that is exactly the old number (so #680's headroom is unchanged, bit for bit)" — the change is stated to be a no-op where it was already right, which is the claim a reviewer needs to accept this without re-measuring the 120 GiB box;
  • the failure being fixed is stated as arithmetic: on a 16 GiB GTT box the fixed 16 GiB cap "leaves a ceiling of zero, so HRX refuses every model", and on an 8 GiB pool "it refuses before arithmetic". Both are visible in the formula, so the claim can be checked rather than believed.

One thing to keep true: the comment names the fork's copy as carrying "the same three rules" — that is a promise only a test can hold. If there is a cheap way to assert the two constants agree (the engine and third_party/llama.cpp reading one value), it is worth the arm; if not, the divergence shows up only when a 16 GB box behaves differently under the two runners, which is the expensive way to find out.

Not verified: the behaviour on a 16 GB box (needs the device and a small-GTT configuration); the arithmetic and the no-op-above-64-GiB claim are what this review covers.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at c055608: READY — I compiled the test standalone rather than waiting on the build, ran it, and then broke the function on purpose to see the arms bite.

The suite, compiled and run here (no engine build, no device):

g++ -std=c++17 -I app tests/mem_admit_test.cpp -o ma && ./ma
ok  8 GiB of GTT (a 16 GB machine) keeps a 2 GiB reserve and a usable ceiling
ok  an unreadable pool keeps the measured 16 GiB reserve, not zero
ok  a 16 GiB-GTT box now admits a small model where the fixed reserve refused everything
ok  45 GiB more: refused by the ceiling although 60 GiB is free
ok  the refusal names the ceiling and the reserve
… PASS

And the same suite with the function put back the way main has it (fixed 16 GiB, no quarter):

FAIL an 8 GiB pool: the ceiling is the pool minus a quarter, not zero
FAIL a 1 GiB pool is still refused: the ceiling cannot grow a load that large
5 FAILED

so the arms are the change, not decoration.

Two things worth putting in the body, both measured on this box:

  1. On this box the change is a no-op, and that is the right kind of no-op: mem_info_gtt_total reads 128849018880 = 120 GiB, a quarter is 30 GiB, the cap is the measured 16 GiB, so the reserve stays 16 and the ceiling stays 104 GiB — identical to today. The change only moves a small pool, which is exactly where the fixed reserve was catastrophic (16 GiB pool → ceiling 0 → every model refused).
  2. The gtt_total == 0 arm is the sharpest one in the file, and your comment says why: a pool that could not be read is not a pool that is empty, and the naive quarter-of-zero would fail open on exactly the input where the answer is unknown. That is the failure mode this whole month has produced repeatedly, and it is the arm I would keep if only one could survive.

Scope: two files, and the pairing with llama.cpp#451 (the cap-side change) reads correctly — this is the reserve policy, that one is what consumes the reserve.

Not a device claim: nothing here is verified against a real 16 GiB pool, and the numbers for small pools are arithmetic, not measurements. The one measurement that matters for it (a gfxhub fault at 106.5 GiB on a 120 GiB pool) is #680's and is referenced, not repeated.

@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 c055608: READY

The engine half of #2986, and it lands the same policy as llama.cpp's #451 — including the gtt_total == 0 case, which is the one that decides whether this fails open or closed.

The change, and the precedence order is right

inline uint64_t gtt_reserve_bytes(uint64_t gtt_total) {
    if (const char* e = std::getenv("GGML_HRX_GTT_RESERVE_MB")) {
        const long long mb = std::atoll(e);
        if (mb >= 0) return uint64_t(mb) * kMiB;      // an explicit override wins
    }
    if (gtt_total == 0) return kGttReserveDefaultMiB * kMiB;
    const uint64_t quarter = gtt_total / 4;
    const uint64_t cap     = kGttReserveDefaultMiB * kMiB;
    return quarter < cap ? quarter : cap;
}

Three decisions in nine lines, and all three are the correct one:

  1. The environment override is checked first, so an operator who has measured their box is not overruled by arithmetic — and mb >= 0 makes GGML_HRX_GTT_RESERVE_MB=0 mean "reserve nothing, I know what I am doing" rather than being ignored as falsy.
  2. gtt_total == 0 returns the measured reserve, and the comment states the failure it prevents: "quarter is 0, 0 < cap is true, and the function returns no reserve at all — failing open on exactly the input where the answer is unknown, so a 32 GB box whose GTT read fails would be admitted like a box with an infinite pool." That is the #2976 lesson landed in arithmetic: an unreadable pool is not an empty pool, and "I cannot tell" gets the safe answer rather than the permissive one.
  3. The cap keeps the measured value where it was measured. From 64 GiB up this is exactly the old 16 GiB — so #680's measured headroom is unchanged on this box — and below it, three quarters of the pool stays usable.

The call site cannot clamp its way around it

const uint64_t gtt_free = mem.gtt_total > mem.gtt_used ? mem.gtt_total - mem.gtt_used : 0;
const uint64_t gtt_reserve = gtt_reserve_bytes(mem.gtt_total);
v.ceiling = mem.gtt_total > gtt_reserve ? mem.gtt_total - gtt_reserve : 0;

Both subtractions are guarded, so a reserve larger than the pool yields 0 rather than a wrapped uint64. That was why the old constant produced a ceiling of zero on a 16 GB machine instead of a huge one — the arithmetic was already safe, and the policy was wrong. The fix is in the policy, which is the right place for it.

The arms cover the three cases that matter, and the two that bound them

  120 GiB -> 16 GiB (the measured reserve, 104 GiB ceiling)      unchanged on this box
   64 GiB -> 16 GiB  (the crossover)                             the old behaviour's edge
   32 GiB ->  8 GiB                                               scaling, and NOT 16
   16 GiB ->  4 GiB  (a 32 GB machine has a ceiling at all)       the bug being fixed
    8 GiB ->  2 GiB  (a 16 GB machine keeps a usable ceiling)     the bug being fixed
    0     -> 16 GiB  (an unreadable pool is not an empty pool)    fails closed
    1 GiB -> refused                                              the ceiling cannot grow a load

The 120 GiB -> 16 GiB arm is the regression guard: a later change that quietly shrank the reserve on the machine it was measured on goes red. And 0 -> 16 GiB is the one that would have been silently wrong if the early return had been written as an optimisation rather than as a decision.

One structural note, not a defect

This is now the second implementation of one policy: app/mem_admit.h:61 kGttReserveDefaultMiB = 16384 here, and ggml/src/ggml-hrx/hrx-1bit-safety.cpp:57 kDefaultReserveMiB = 16384 in llama.cpp (#451). Both are 16384 and both compute min(gtt/4, cap), so they agree today — but they are two constants and two divisions, in two repositories, that must change together. An arm in each place cannot catch the drift; the only thing that can is a comment naming the other copy, and I would add one line to each:

// keep in step with llama.cpp's ggml/src/ggml-hrx/hrx-1bit-safety.cpp (kDefaultReserveMiB)

Not a reason to hold this PR — it is the same policy, correctly implemented twice, and the divergent-constant risk is small and slow. But it is the kind of pair that ends up disagreeing after a year.

What I could not run

No build — tests/mem_admit_test.cpp links the app target and my lane holds no ticket for a configure. I checked the arithmetic of every arm by hand (120/4=30 → cap 16, 64/4=16 → cap 16 exactly at the crossover, 32/4=8, 16/4=4, 8/4=2, 0 → 16), and they all hold. The ctest row in CI is the half that proves the code compiles against the header it ships with.

@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 c055608: READY. Built and ran the test here, and checked the one thing that decides whether this pair is safe — that the engine's planner and the fork's registration backstop compute the same reserve.

$ g++ -std=c++20 -I. -o matest mem_admit_test.cpp && ./matest          → rc 0, PASS
ok   120 GiB of GTT keeps the measured 16 GiB reserve (104 GiB ceiling)
ok   64 GiB of GTT is the crossover: still a 16 GiB reserve
ok   32 GiB of GTT gets an 8 GiB reserve, not 16
ok   16 GiB of GTT (a 32 GB machine) gets a 4 GiB reserve, so the ceiling is not zero
ok   8 GiB of GTT (a 16 GB machine) keeps a 2 GiB reserve and a usable ceiling
ok   an unreadable pool keeps the measured 16 GiB reserve, not zero
ok   a 16 GiB-GTT box now admits a small model where the fixed reserve refused everything
ok   1 GiB more: fits, no ceiling note … an 8 GiB pool: the ceiling is the pool minus a quarter, not zero

The pairing, computed on both sides (the fork half is llama.cpp#451, in review): for {8, 16, 64, 120} GiB of GTT the two implementations return identical reserves — 2 / 4 / 16 / 16 GiB — so the ceilings are 6 / 12 / 48 / 104 GiB. That last number is the point: this box keeps #680's measured 104 GiB ceiling bit for bit, and only the pools that were at zero move. The planner and the backstop therefore cannot disagree about what fits, which is the failure mode a pair like this invites.

Three things I would keep exactly as they are:

  • an unreadable pool keeps the flat 16 GiB — a caller that cannot measure GTT must not get a smaller reserve than the one measured safe, and the test arms it;
  • the 64 GiB crossover is explicit (still 16 GiB), so the change is provably a no-op above it;
  • GGML_HRX_GTT_RESERVE_MB still wins outright on the fork side, so an operator can override both halves at once.

One note, not a change request: both halves now encode "a quarter, capped at 16 GiB" independently, and nothing fails if one moves without the other — the fork's knob is GGML_HRX_GTT_RESERVE_MB, the engine's is not, and the two constants live in different repositories. The numbers agreeing today is a measurement, not a guarantee; a sentence in each header naming the other file (and the engine#2986 number) is the cheap way to keep them paired when someone next tunes one.

@bong-water-water-bong
bong-water-water-bong merged commit 7918c1f into main Nov 20, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-hrxnan/2986-scale-gtt-reserve branch November 20, 2026 16:58
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

The precedence promise is currently TRUE only after a pin: measured, and the merge order matters.

I asked for an arm asserting the engine's copy and the fork's agree. Running the comparison by hand first, the two are not in the same state today:

engine #2995                  gtt_reserve_bytes(uint64_t gtt_total)   quarter of pool, capped at 16384 MiB
fork at main's pin 4eb3f08f95 pool_reserve_bytes()                    ← NO argument, flat 16384 MiB
fork in llama.cpp#451          pool_reserve_bytes(size_t gtt_total)   quarter of pool, capped

So the constant already agrees (16384 in both copies) but the shape does not, and it will not until llama.cpp#451's pin is in. That gives this PR an ordering constraint worth stating in the body:

What I would put in the body: which of the two is expected to land first, and that the pinned third_party/llama.cpp must carry pool_reserve_bytes(gtt_total) before this engine change is meaningful on a small box. That is one sentence, and it converts a promise into a landing order.

And the arm: with the fork's signature changing, the cheapest assertion is not a constant comparison but a shape one — the engine's header and the fork's header both declaring a reserve function that takes the pool size. A test that greps both headers for that signature would fail today and pass after the pin, which is exactly what an arm is for.

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit c055608

bong-water-water-bong added a commit that referenced this pull request Nov 20, 2026
…st one that fits with room (#2986) (#3013)

* serve: a model whose own context is beyond the machine gets the largest one that fits with room (#2986)

On HRX with no --ctx-size, llama-server takes the model's own context
(HRX0 reports its whole pool free, so --fit shrinks nothing). LFM3-1.7B's
own context is 262,144 tokens (5.88 GiB of plan). On a 16 GB machine
(GTT 8 GiB, the #2995 ceiling 6.00 GiB) that load is refused outright,
which the owner's 16 GB direction cannot ship with.

serve now keeps the model's own context when its plan is roomy - it fits
and leaves the graph-program cache its 4 GiB (no "little room left"
warning) - and otherwise passes the largest context, in 256-token steps,
whose plan is roomy; when none is, the 4096 floor, and if even that does
not fit the normal refusal names it. One line says what happened. An
explicit --ctx-size is never changed: it is judged, and refused, as
given. A CPU backend, --no-mem-check and a box that does not report its
memory are left alone.

app/mem_admit.h: Verdict::roomy, default_ctx() (pure). tests/mem_admit_test.cpp,
an LFM3-1.7B-shaped fixture (its own header values, 1,099,627,808 bytes):
- GTT 8 GiB, 0.5 GiB in use, 11 GiB available: 262144 (5.88 GiB) -> 58112
  (2.50 GiB); 58112 is roomy and 58368 is not;
- the same with 6 GiB available: no context is roomy -> 4096 (1.60 GiB);
- explicit --ctx-size 262144 there: left alone, refused (6.38 GiB would
  land past 6.00); --ctx-size 1000000: refused;
- GTT 16 GiB / 26 GiB available, and a 120 GiB box: the model's own
  context stands; a CPU argv is left alone; a 2 GiB pool gets the floor.
mem_admit_test: 57 ok, PASS (47 before).

docs/serve.md: the default-context rule and line, and the reserve rule
#2995 merged (the doc still said a flat 16 GiB).

Refs #2986

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* models: pin LFM3-1.7B-GGUF and record its licence (#2918 follow-up to #2956)

models/pins.json: LiquidAI/LFM3-1.7B-GGUF at cd0c74c575b5, the one file we
hold - LFM3-1.7B-Q4_K_M.gguf, oid 3793e1e6..., 1,099,627,808 bytes,
template f45005c5... (the pin #2956 added to config/template-pins.json;
tools/pin_watch.py --pin reads the same template sha from Hugging Face).
Commit, oid and size checked against the Hugging Face API and the
download's own metadata.

docs/models.md: the LFM3-1.7B row with what #2918 measured (pp512 7,925,
tg128 153.7 tok/s; perplexity 14.05 HRX vs 14.11 CPU; 2.05 GiB GTT and
1.34 GiB host RAM at 8k) and its licence: LFM Open License v1.0, under
which commercial use is licensed only while annual revenue stays below
US$10M (§1, §5) - not an OSI licence.

Refs #2918

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
bong-water-water-bong pushed a commit that referenced this pull request Nov 20, 2026
The fourth way this tool has been blind in one day, and the first that a lane found for me.

#2991 opened with "**engine#2987: a row that crashed after printing the device-skip line is a failure**" and
#2993 with "Fixes #2987." -- same file, same issue, same fix. `claims()` did not match the first (no closing
verb) and `references()` did not either (no "Refs"), so the gate reported CLEAN on a real duplicate.

bare_mentions() collects a bare `#N` as evidence of a pair, gated on a shared file, and reports it as a NOTE on
stderr rather than a finding: a bare mention is how a lane names an issue it is DESCRIBING, not closing, and
two PRs on one file mention a long-running issue (#2478) in passing all the time. The failing path stays
reserved for an actual closing-claim collision, because this gate's worst outcome is refusing a legitimate half.

AND IT REPRODUCED ITS OWN DOCUMENTED BUG. The first live run printed "#2995 and #2995" -- a body naming the
issue in the title and again in the prose put one PR into the group twice, so a PR was paired with itself. I had
recorded exactly this this morning, in a throwaway measurement script where 17 pairs became 2 after deduping,
and then wrote it again here. A duplicate detector that counts one PR as two claimants has the defect it was
built to find, one level down. Keyed by PR number now, with an arm.

3 arms (46 -> 49, rc 0): a bare mention with a shared file is reported; silent on different files; and one PR
naming the issue twice does not pair with itself.
bong-water-water-bong added a commit that referenced this pull request Nov 20, 2026
…2999)

The fourth way this tool has been blind in one day, and the first that a lane found for me.

#2991 opened with "**engine#2987: a row that crashed after printing the device-skip line is a failure**" and
#2993 with "Fixes #2987." -- same file, same issue, same fix. `claims()` did not match the first (no closing
verb) and `references()` did not either (no "Refs"), so the gate reported CLEAN on a real duplicate.

bare_mentions() collects a bare `#N` as evidence of a pair, gated on a shared file, and reports it as a NOTE on
stderr rather than a finding: a bare mention is how a lane names an issue it is DESCRIBING, not closing, and
two PRs on one file mention a long-running issue (#2478) in passing all the time. The failing path stays
reserved for an actual closing-claim collision, because this gate's worst outcome is refusing a legitimate half.

AND IT REPRODUCED ITS OWN DOCUMENTED BUG. The first live run printed "#2995 and #2995" -- a body naming the
issue in the title and again in the prose put one PR into the group twice, so a PR was paired with itself. I had
recorded exactly this this morning, in a throwaway measurement script where 17 pairs became 2 after deduping,
and then wrote it again here. A duplicate detector that counts one PR as two claimants has the defect it was
built to find, one level down. Keyed by PR number now, with an arm.

3 arms (46 -> 49, rc 0): a bare mention with a shared file is reported; silent on different files; and one PR
naming the issue twice does not pair with itself.

Co-authored-by: phyb5 <bcloud@local>
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.

1 participant