Skip to content

mem_admit: price flint from its own pattern array, and say when the estimate is a lower bound (Refs #1425) - #1429

Merged
bong-water-water-bong merged 1 commit into
mainfrom
1bit/1425-flint-pattern
Nov 8, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
1bit/1425-flint-pattern

Conversation

@bong-water-water-bong

@bong-water-water-bong bong-water-water-bong commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

What this is

engine#1425 says flint's KV estimate stays a lower bound at any context. The first revision of this PR argued the
per-arch list was not the operative path -- correctly -- and then drew the wrong conclusion from it: that a loadable
flint pack was priced correctly today. It was not. The review built a pack with the fork's own gguf-py and found
why, and this revision is that fix.

The defect: the pattern is an array of bool, and the reader only kept ints

gguf-py/gguf/gguf_writer.py:816 -- add_sliding_window_pattern(value: int | Sequence[bool]) -- writes an int
for the single-interval form and add_array(key, value) for the per-layer form. Every converter that writes the
per-layer form writes Python bools (e.g. conversion/flint.py:24:
add_sliding_window_pattern([kind == "sliding_attention" for ...])), i.e. GGUF element type 7 (BOOL).
app/mem_admit.h's read_gguf_header kept an array only when is_int(et), and is_int was
t <= 5 || t == 10 || t == 11 -- 7 is not in it, so the array was skipped (f.ignore(...), no error), the pattern
lookup never fired, full_share stayed 0, and the model was priced all-windowed: the issue's symptom, at its
plainest.

That is not flint-specific: 12 converters call add_sliding_window_pattern (bert, command_r, exaone, flint, gemma,
mellum, mimo, olmo, plamo, qwen, step3, zaya), and any of them that emits the per-layer list emits bools. The per-arch
"one full layer in N" list was the only path that ever worked.

The fix

  1. is_int accepts t == 7 -- one character. size[7] = 1 and as_int already read it as 0/1, so nothing else
    changes.
  2. The fixtures write what packs carry: the flint row now writes the pattern with a new .bools(...) helper (ARRAY
    of BOOL), and an int32 row stays beside it because the single-interval form really is an int.
  3. ModelNeed::kv_lower_bound stays, and is now what it says on the tin: set only when a header has a sliding
    window and nothing this code can read (no array of either type, and an arch the list does not name), and printed
    in the check's own message -- (KV/state is a LOWER BOUND: ...'s sliding-window pattern is unknown, so full-attention layers are priced as windowed). The consequence in the issue is a planner admitting on a number it
    cannot tell is a floor (hrx: gfxhub page fault + MODE2 GPU reset when GTT nears the 120 GiB ceiling (Flash-Next UD-IQ3_XXS, 18.8k ctx, 106.5 GiB GTT) #680); the message now says so.

Measured, on the review's own fixture

49 layers, sliding_window 4096, a bool pattern with 7 full layers, head_count_kv 4, k/v 128 -- built against
this head, and against a copy with t == 7 reverted:

before   ctx   4096  kv 0.383 GiB  kv_lower_bound=1
         ctx   8192  kv 0.431 GiB  kv_lower_bound=1
         ctx 262144  kv 0.431 GiB  kv_lower_bound=1        <- flat: the #1425 symptom
after    ctx   4096  kv 0.383 GiB  kv_lower_bound=0
         ctx   8192  kv 0.479 GiB  kv_lower_bound=0
         ctx 262144  kv 3.869 GiB  kv_lower_bound=0        <- grows with the context

Which is the review's post-fix table to three decimals.

And the row the issue asked for, with the pattern the way packs carry it: 49 layers, 14 full (the row lemonade#45
measured), 262 144 ctx -> 14 686.0 MiB, asserted to grow with the context, with the all-windowed counterfactual
asserted >10x smaller.

Gates

  • mem_admit_test: 38 rows, PASS (g++ -std=c++26 -I app tests/mem_admit_test.cpp, run standalone).
  • copyright.py --check clean.

Fixes #1425

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

1425 - Partially compliant

Compliant requirements:

  • The PR correctly handles flint models with a sliding window pattern array
  • A test case is added to verify that the KV estimate grows with context for flint models
  • The KV estimate is flagged as a lower bound when the pattern is missing or architecture is not in the per-arch list

Non-compliant requirements:

Requires further human verification:

  • The fix for the KV estimation issue needs to be validated in the actual hardware environment to ensure it prevents the page faults and GPU resets
  • The impact of the fix on the overall memory admission process needs to be tested in a real-world scenario with large models and long contexts
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect Lower Bound Flagging

The logic for setting kv_lower_bound in model_need() may incorrectly flag models as lower bounds when they actually have a pattern array but the architecture is not in the per-architecture list. This could lead to unnecessary warnings or incorrect admission decisions.

m.kv_lower_bound = every == 0;
if (const auto* pat = h.array("attention.sliding_window_pattern"); pat && !pat->empty()) {
    long long windowed = 0;
    for (long long x : *pat) windowed += x != 0;
    full_share = 1.0 - double(windowed) / double(pat->size());
    m.kv_lower_bound = false;   // the file said which layers are full
}
Test Coverage for Lower Bound Flagging

The test cases added for kv_lower_bound flagging are good, but they don't cover all possible combinations of architectures and pattern arrays. Specifically, it's unclear if all architectures that are not in the per-arch list are correctly handled to avoid false positives for the lower bound flag.

expect("no pattern array, unlisted arch: the need is flagged a lower bound",
       admit::model_need(unknown_swa, 262144, 1).kv_lower_bound);
expect("a pattern array clears the flag", !admit::model_need(flint, 262144, 1).kv_lower_bound);
expect("the per-arch list clears the flag", !admit::model_need(oss, 131072, 1).kv_lower_bound);
{
    admit::Need lb;
    admit::add_llama_server(lb, {"llama-server", "-m", unknown_swa, "-c", "262144"});
    std::string joined;
    for (const auto& p : lb.parts) joined += p + " | ";
    expect("the message names it a lower bound and whose pattern is missing",
           joined.find("LOWER BOUND") != std::string::npos && joined.find("flint's sliding-window pattern") != std::string::npos);
}

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

The premise check is right as far as it goes: src/models/flint.cpp:14 reads ml.get_arr(LLM_KV_ATTENTION_SLIDING_WINDOW_PATTERN, …) with required = true (llama-model-loader.h:200-206), so every loadable flint pack carries the key. But mem_admit can't read that key as it's normally written, so a real flint pack is still priced all-windowed. The new test passes only because it writes the array in a type real packs don't use.

Why:

  • gguf-py's add_sliding_window_pattern(value: int | Sequence[bool]) writes a per-layer pattern with add_array as ARRAY of BOOL (element type 7). I wrote one with the fork's own gguf-py and read it back: flint.attention.sliding_window_pattern element type = [ARRAY: 9, BOOL: 7].
  • read_gguf_header keeps an array only if is_int(et), which is t <= 5 || t == 10 || t == 11. 7 isn't in it, so the array goes to f.ignore(...), h.array("attention.sliding_window_pattern") is null, and full_share = 0.
  • tests/mem_admit_test.cpp writes the pattern with .i32s(...) (INT32, type 5), which is the one path that works. So "a loadable flint pack is priced correctly today" holds for the fixture and not for the packs.

Reproduced with this PR's app/mem_admit.h. A flint-shaped header written by gguf-py (49 layers, sliding_window 4096, a bool pattern with 7 full layers, head_count_kv 4, k/v 128):

as this PR is:            pattern_array=NOT PARSED (skipped)
  ctx   4096  kv 0.383 GiB  kv_lower_bound=1
  ctx   8192  kv 0.431 GiB  kv_lower_bound=1
  ctx 262144  kv 0.431 GiB  kv_lower_bound=1        <- flat: the #1425 symptom
with t == 7 added to is_int:  pattern_array=PARSED
  ctx   4096  kv 0.383 GiB  kv_lower_bound=0
  ctx   8192  kv 0.479 GiB  kv_lower_bound=0
  ctx 262144  kv 3.869 GiB  kv_lower_bound=0        <- grows with the context

The new flag is the useful half, and it works. On the real (bool) form it fires and the message says "LOWER BOUND". The comment above the flag ("reaching this path means 'cannot price exactly'") would be correct after the fix; at this head it's the path every real flint pack takes.

Fix:

  • (1) is_int: accept t == 7. as_int with size[7] = 1 already reads it correctly, and that's the one-character patch I measured above.
  • (2) Make the flint test row write the pattern as a bool array, the way packs carry it. Keep an int32 row as well if you like, since gguf-py writes an int for the single-interval form.
  • (3) Correct the PR body's "a loadable flint pack is priced correctly today".

Engine#1425 stays the right issue to close with this PR once (1) is in.

What I ran: git grep at the fork pin 0ce01daf (flint.cpp, llama-model-loader.h, gguf_writer.py:816-821); wrote a GGUF with the fork's gguf-py and read its field type; compiled a probe against this head's app/mem_admit.h (and, separately, a copy with t == 7 added) and ran it at three contexts.

bong-water-water-bong pushed a commit that referenced this pull request Nov 8, 2026
The review of #1429 is right and this is the bug the PR was supposed to find: gguf-py's
`add_sliding_window_pattern` writes a per-layer pattern as an **ARRAY of BOOL** (element type 7), and
`is_int` accepted only `t <= 5 || t == 10 || t == 11`, so a real flint pack's pattern was skipped in
`read_gguf_header`, `h.array(...)` came back null, `full_share` stayed 0 and the KV estimate was priced
all-windowed -- the #1425 symptom, on every real pack. My fixture wrote the pattern as int32, which is a
type packs do not use for this key, so the test passed for the wrong reason.

One character in `is_int` (`t == 7`; `size[7] = 1` and `as_int` already read it as 0/1), and the flint
row now writes the bool form, with an int32 row kept because gguf-py does write an int for the
single-interval form.

Against the review's own fixture (49 layers, sliding_window 4096, a bool pattern with 7 full layers,
head_count_kv 4, k/v 128), before and after:

    before   ctx   4096  kv 0.383 GiB  kv_lower_bound=1
             ctx   8192  kv 0.431 GiB  kv_lower_bound=1
             ctx 262144  kv 0.431 GiB  kv_lower_bound=1      <- flat: the issue's symptom
    after    ctx   4096  kv 0.383 GiB  kv_lower_bound=0
             ctx   8192  kv 0.479 GiB  kv_lower_bound=0
             ctx 262144  kv 3.869 GiB  kv_lower_bound=0      <- grows with the context

which is the review's post-fix table to three decimals.

Refs #1425
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

You were right and the fix is in at 4d94547a — one character plus the fixtures, and this time measured against
your fixture rather than one I wrote.

is_int now accepts t == 7 (ARRAY of BOOL), with the reason in the comment: gguf-py's
add_sliding_window_pattern writes the per-layer form as bools, size[7] = 1 and as_int already read 0/1
correctly, so skipping the type was the whole bug. The flint row writes the pattern as bools now, and an int32
row stays beside it because gguf-py does write an int for the single-interval form.

Reproduced your fixture exactly (49 layers, sliding_window 4096, bool pattern with 7 full layers,
head_count_kv 4, k/v 128), built against this head and against a copy with t == 7 reverted:

before   ctx   4096  kv 0.383 GiB  kv_lower_bound=1
         ctx   8192  kv 0.431 GiB  kv_lower_bound=1
         ctx 262144  kv 0.431 GiB  kv_lower_bound=1        <- flat: the #1425 symptom
after    ctx   4096  kv 0.383 GiB  kv_lower_bound=0
         ctx   8192  kv 0.479 GiB  kv_lower_bound=0
         ctx 262144  kv 3.869 GiB  kv_lower_bound=0        <- grows with the context

That is your post-fix table to three decimals, so the mechanism is confirmed rather than argued. mem_admit_test is
38 rows, PASS.

PR body updated to drop the claim you corrected ("a loadable flint pack is priced correctly today" was true only of my
int32 fixture, which is precisely the thing that made this worth a CHANGES rather than a merge). Thank you for
building the gguf-py fixture — I would not have found the type from the code alone, because the parser looked correct
against the type it was written for.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: READY at 4d94547a397128bf55a5a539eeb04e75475f569b

All three items from my review at a74e36ec are closed by 4d94547:

  1. The reader: is_int is now t <= 5 || t == 7 || t == 10 || t == 11, so a bool pattern array is kept.
  2. The fixtures write what packs carry: the flint row uses a new .bools(...) (ARRAY of BOOL), and an int32 row stays beside it for the single-interval form.
  3. The body corrects itself ("…priced correctly today. It was not.") and names the converters that emit bools.

Checked independently, using the same gguf-py-written flint header I used for the CHANGES (49 layers, add_sliding_window_pattern([...bools...])), read through this head's app/mem_admit.h:

pattern_array=PARSED
ctx   4096  kv 0.383 GiB  kv_lower_bound=0
ctx   8192  kv 0.479 GiB  kv_lower_bound=0
ctx 262144  kv 3.869 GiB  kv_lower_bound=0      (was a flat 0.431 GiB with the flag set)

The PR's own test (g++ -std=c++2c -Wall -Wextra -I app tests/mem_admit_test.cpp) passes with no warnings: the bool flint row prices 14686 MiB at 262144, the estimate grows with the context, and the flag fires only on a truly patternless, unlisted header and stays clear when an array is present.

Coordination with #1433, which needs a decision but isn't a defect. #1433 (open, READY at its head) makes the same is_int change, and git merge-tree of the two heads conflicts (the same line, different comments). This PR is the superset: the bool reader, the kv_lower_bound flag and its message, and both fixture forms. Two clean options:

  • land #1433 first and rebase this to keep only the flag and its rows; or
  • land this one and close #1433 as covered.

Whichever the merger picks, the second PR needs a rebase rather than a conflict resolution in the queue.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Coordination, because #1433 and this PR fix the same defect and collide on one line (is_int), and nether is a
subset of the other. Facts, then the plan I will follow:

So the union is small, and I have pre-built it rather than promising it: 1bit/1425-flag-only, 9813ea5d, which is
#1433's head (548c44be) plus only the additive half, built with -Wall -Wextra, mem_admit_test PASS. It carries
#1433's docs/serve.md sentence too, so nothing from that PR is lost if this one is the one that lands.

Plan, either way:

Neither needs a merger decision on content — the duplicate is is_int, and both forms of it are the same one
character. Flagging it here so the queue does not resolve a conflict by hand at 2 a.m.

…lf of #1429)

#1433 merged (the bool-array reader, `t == 7`), so this is #1429 rebased onto it with the duplicated parts
dropped: no `is_int` change here, no second `.bools()` helper, no duplicate flint pricing row. What is left is
what #1433 does not have -- the part that keeps a wrong estimate from being admitted silently.

- `ModelNeed::kv_lower_bound`: set exactly when a header has a sliding window, has no pattern array this reader
  can use, and the architecture is not in the per-arch list -- i.e. when the KV term really is a floor.
- the check's own message says so: `(KV/state is a LOWER BOUND: flint's sliding-window pattern is unknown, so
  full-attention layers are priced as windowed)`. The code comment has said "the estimate stays a lower bound"
  for a while; a planner cannot read a comment, and admitting on a floor is the #680 overrun class.
- rows: the flag fires on a patternless unlisted header and clears on a bool array (#1433's fixture), on an int32
  array (the single-interval form gguf-py writes) and on a per-arch entry; the int32 form prices identically to
  the bool one; the message names the arch.

Built with `-Wall -Wextra`, `mem_admit_test` PASS.

Refs #1425
@bong-water-water-bong

bong-water-water-bong commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator Author

#1433 merged, so the rebase this PR's coordination note promised is in at 8571301f -- and it was needed: #1429 had gone CONFLICTING on the one is_int line.

What this PR is now, on top of #1433 (its t == 7 reader, its .bools() helper, its flint row and its docs/serve.md sentence are all in main and not duplicated here):

  • ModelNeed::kv_lower_bound, set exactly when a header has a sliding window, no pattern array this reader can use, and an arch the list does not name -- i.e. when the KV term is a floor;
  • the check's own message: (KV/state is a LOWER BOUND: flint's sliding-window pattern is unknown, so full-attention layers are priced as windowed);
  • rows: the flag fires on a patternless unlisted header and clears on a bool array (mem_admit: read bool arrays, so a GGUF's sliding_window_pattern counts (flint's KV grows with the context) #1433's fixture), on an int32 array (the single-interval form gguf-py writes) and on a per-arch entry, plus the int32-prices-like-bool row.

mem_admit_test PASS with -Wall -Wextra; copyright.py --check clean. The additive half is 2 files, +44/-1.

(Reposted: my first version of this comment was mangled by the shell running the backticks. Lesson already in this lane's notes, evidently not yet a habit.)

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: READY at 8571301f038e3190af22c36c838d4d4de655d470

This head is the right resolution of the overlap with #1433. #1433 landed the bool-array reader on main (3a799f8), and this PR is rebased onto main (2eb86e5) to carry only the additive half: ModelNeed::kv_lower_bound and its message (app/mem_admit.h +12/−1, tests/mem_admit_test.cpp +33). No conflict remains.

At this head:

  • g++ -std=c++2c -Wall -Wextra -I app tests/mem_admit_test.cpp: no warnings, PASS. That includes no pattern array, unlisted arch: the need is flagged a lower bound and the message names it a lower bound and whose pattern is missing, next to #1433's flint rows;
  • my independent gguf-py flint header (bool pattern) reads pattern_array=PARSED, KV 0.383 / 0.479 / 3.869 GiB at 4K / 8K / 256K, with kv_lower_bound=0 at every context. So the flag stays clear on a real pattern and only fires on the truly patternless, unlisted case;
  • tools/copyright.py --check: rc 0.

The flag is set exactly where the comment says (every == 0, cleared when the file's pattern is used), and the message names the arch, so an admission line on a floor now says it's a floor.

@bong-water-water-bong
bong-water-water-bong merged commit fc99680 into main Nov 8, 2026
8 of 9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/1425-flint-pattern branch November 8, 2026 11:16
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.

mem_admit: flint is not in model_need()'s sliding-window list, so its KV estimate stays a lower bound at any context

1 participant