Skip to content

mem_admit: read bool arrays, so a GGUF's sliding_window_pattern counts (flint's KV grows with the context) - #1433

Merged
bong-water-water-bong merged 2 commits into
mainfrom
fix/1425-flint-swa
Nov 8, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
fix/1425-flint-swa

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #1425

Cause

model_need() already lets a sliding_window_pattern array in the GGUF decide which layers attend over the full context. But read_gguf_header() keeps only integer arrays (GGUF types 0-5, 10, 11). gguf-py writes add_sliding_window_pattern([kind == "sliding_attention" for kind in layer_types]) as a bool array (type 7), which the reader skipped.

flint is not in the per-architecture list, so every one of its 49 layers was priced as windowed, and the KV estimate stayed flat at every context. That matches the issue's observation: 24.07 GiB need at 4096, 8192 and 262144.

flint is not the only arch affected. At the engine's llama.cpp pin, most converters that write a pattern write bools: flint, command-r, exaone, mellum, zaya (hybrid_sliding) and others. For those, the "file wins" path never ran either.

Change

  • app/mem_admit.h: bool (7) reads as 0/1, like the other integer types (+1 token, +1 comment line). None of the scalar keys model_need() reads is a bool, so only the pattern arrays change.
    • flint's loader requires the array (ml.get_arr(LLM_KV_ATTENTION_SLIDING_WINDOW_PATTERN, ...), not optional), so flint always takes the file's pattern and needs no list entry.
  • docs/serve.md ("Will it fit?"): the file's pattern, integers or bools, wins over the list; flint always has one.
  • tests/mem_admit_test.cpp:
    • a bools() fixture writer, with the bytes laid out as gguf-py writes them;
    • a flint header row: 49 layers, 35 windowed / 14 full, window 4096, 4 KV heads x (128 + 128), f16;
    • a row checking that the estimate grows with the context.

Proof (strixhalo, CPU, g++ -std=c++26 -Wall -Wextra, under thermal-run)

Same test file, compiled against origin/main's app/mem_admit.h, then against this branch's:

main:   FAIL flint: 14 full layers at 262144 + 35 windowed at 4096 + 512: 441.0000 MiB (want 7483.0000)
        FAIL flint: the estimate grows with the context
        2 FAILED            (31 ok)
branch: ok   flint: 14 full layers at 262144 + 35 windowed at 4096 + 512: 7483.0000 MiB (want 7483.0000)
        ok   flint: the estimate grows with the context
        PASS                (33 ok, no warnings)

tools/copyright.py --check: exit 0 (no new files).

Not measured

  • There is no flint GGUF on the box. The fixture's window (4096), head counts and layer order are illustrative. Only the count of full layers (14 of 49, from the lemonade#45 row) matters to model_need().
  • The real flint figure needs the real header and will differ from 7,483 MiB.
  • I did not run the CMake mem_admit ctest or mem_admit_route.sh (which needs a full engine build); the unit test above is that ctest's source.

🤖 Generated with Claude Code

…s (flint's KV grows with the context) (#1425)

model_need() lets a sliding_window_pattern array in the file decide which layers attend over the
full context. The header reader kept only integer arrays (GGUF types 0-5, 10, 11), and gguf-py writes
a list of Python bools as a bool array (type 7). Most converters at the pin write the pattern that way
(flint, command-r, exaone, mellum, zaya, ...), so for them the file's pattern was skipped. For flint,
which is not in the per-architecture list, every layer was then priced as windowed: 441 MiB of KV at
any context, instead of 7,483 MiB at its own 262144.

Bool now reads as 0/1 like the other integer types. flint's loader requires the array, so flint always
takes the file's pattern; no list entry needed. Docs: docs/serve.md "Will it fit?".

tests/mem_admit_test.cpp: a bool-array fixture (bytes as gguf-py writes them) and a flint header
(49 layers, 35 windowed / 14 full, window 4096, 4 KV heads x 128+128):

  main:  FAIL flint: 14 full layers at 262144 + 35 windowed at 4096 + 512: 441.0000 MiB (want 7483.0000)
         FAIL flint: the estimate grows with the context          (31 ok, 2 FAILED)
  this:  ok   ... 7483.0000 MiB (want 7483.0000); ok grows with the context  (33 ok, PASS)

Fixes #1425

Co-authored-by: bong-water-water-bong <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

ready for review at 80b5eb6

@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 80b5eb63 — duplicate of #1430; one of the two must be closed, and they conflict.

Same one-token fix: is_int gains t == 7 because GGUF_TYPE_BOOL = 7 (gguf.h:61) and gguf_writer.py:816 is
add_sliding_window_pattern(self, value: int | Sequence[bool]), so a bool-array pattern was silently skipped and model_need() fell back to the
per-arch list. git merge-tree --write-tree df5ced44 80b5eb63 → 2 conflicts, so this is not a "land both, second rebases to nothing" case in
the practical sense: whichever goes second has to be reconciled by hand over the same is_int line.

What this PR has that #1430 does not, and should survive either way:

  • the flint fixture — a real 35-sliding / 14-full pattern over 49 layers, which pins the shape the fleet actually ships rather than a generic
    bool array (and 35 + 14 = 49 checks out, matching lemonade #45's "all 49 layers priced as windowed");
  • the docs/serve.md clause that flint's loader requires the array.

What #1430 has that this does not: the sentence that makes the severity legible — "a lower bound on an admission gate, which is the unsafe
direction (engine#1425, the #680 overrun class)". Under-pricing a KV estimate on an admission gate is a safety bug, not a tidiness bug, and that
is the line a future reader needs.

So: land one, fold the other's unique half in, close the second. My recommendation is #1430 as the base with your fixture and docs clause added —
but if this one is ahead in the queue, take that sentence across and land this. Either way the union is what should reach main, and it should be
one PR.

…s one (from #1430) (#1425)

Folds in #1430's one unique piece, so this PR is the union the two reviews asked for.

Co-authored-by: bong-water-water-bong <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Following both reviews ("land one, fold the other's unique half in"), this PR is now the union. 548c44be adds #1430's only unique piece, the sentence saying why this is a safety fix (a lower bound on an admission gate is the unsafe direction, the #680 class), to the is_int comment. The rest was already here: the 35-sliding / 14-full flint fixture and the docs/serve.md clause.

Re-run at 548c44be: g++ -std=c++26 -Wall -Wextra clean, mem_admit_test 33 ok / PASS, tools/copyright.py --check exit 0.

One fact for whoever chooses between the two branches: #1430's fixture loop for (int i = 0; i < 49; i += 7) flint_pattern[i] = false; marks 7 full layers, not the 14 its comment says. So landing #1430 as the base would pin the wrong shape for flint.

ready for review at 548c44b

@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 548c44be358422b5f7f66e5ebf0755a6bd3ea63a

This is the right fix for #1425 (I filed it), at the right layer: read_gguf_header now keeps bool (7) arrays as 0/1. That's exactly the gap. gguf-py's add_sliding_window_pattern(Sequence[bool]) writes ARRAY of BOOL, and the old is_int (t <= 5 || t == 10 || t == 11) sent it to f.ignore.

Checked independently, with a fixture this PR didn't write. A flint-shaped header made with the fork's own gguf-py GGUFWriter.add_sliding_window_pattern([...bools...]) (49 layers, window 4096, 4 KV heads × (128+128), 7 full layers), read through app/mem_admit.h:

origin/main:  pattern NOT PARSED   kv 0.383 / 0.431 / 0.431 GiB at ctx 4096 / 8192 / 262144   (flat: the #1425 symptom)
this head:    pattern PARSED       kv 0.383 / 0.479 / 3.869 GiB at ctx 4096 / 8192 / 262144   (grows with the context)

And the PR's own test (g++ -std=c++2c -Wall -Wextra -I app tests/mem_admit_test.cpp): no warnings, PASS, including flint: 14 full layers at 262144 + 35 windowed at 4096 + 512: 7483.0000 MiB and the estimate grows with the context. Its bools() fixture writes the bytes the way gguf-py does, which is what makes this row mean something.

Side effects: making bool scalars readable as ints changes nothing, because model_need() reads no bool-typed key. The command-r, exaone, mellum and zaya point is right too: their bool patterns start counting.

Coordination, not a change request: #1429 (another lane, same issue) is open against the same lines of mem_admit.h. Its INT32-only fixture missed the bool form, which I flagged there. Once one lands, the other needs a rebase, and #1429's kv_lower_bound flag would then fire only for a truly patternless, unlisted arch. That's still a useful message, but no longer for flint.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Heads-up, not a new verdict: #1429 (now READY at 4d94547) makes the same is_int change (t == 7), so the two heads conflict on that line under git merge-tree. #1429 is a superset: the bool reader, plus a kv_lower_bound flag and message for a truly patternless, unlisted arch, plus bool and int32 fixture rows. Suggest agreeing between the two lanes which lands first, so the other is rebased rather than conflict-resolved in the queue. If #1429 lands first, this PR is covered and can be closed.

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

@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 548c44be — and now that this head carries the "unsafe direction" sentence, my recommendation flips: land this one and close #1430.

The two PRs have converged: both make the identical one-token change (t <= 5 || t == 7 || t == 10 || t == 11) and both now say why — "an
unlisted arch priced every layer as windowed: a lower bound on an admission gate, which is the unsafe direction (engine #1425, the #680 overrun
class)". So #1430's only unique piece is inside this PR now, which leaves what is genuinely different:

#1430 this PR
the fix + the reason yes yes
test assertions one ("prices its full layers at 262144") two — "14 full layers at 262144 + 35 windowed at 4096 + 512" and "the estimate grows with the context"
docs/serve.md clause (flint's loader requires the array) no yes

One correction to the fixture's comment, because the converter says so plainly — conversion/flint.py:24-25:

self.gguf_writer.add_sliding_window_pattern([kind == "sliding_attention" for kind in self.hparams["layer_types"]])

so the bool array is derived from the model's own layer_types, not from a fixed rule: "35 sliding, 14 full of 49" is that specific flint
model's layer_types, not a property of the format. Worth saying in the comment ("the pattern is [k == "sliding_attention" for k in layer_types], so its split is per model — this fixture takes the shipped one") so nobody later writes a test that assumes 35/14 is the rule.
That also makes the pair of fixtures defensible in one line: #1430's 7-of-49 shape was synthetic, this one is the shipped shape, and neither is a
constant.

Land this, close #1430 (both open, merge-tree reports 2 conflicts over the same is_int line).

@bong-water-water-bong
bong-water-water-bong merged commit 3a799f8 into main Nov 8, 2026
8 of 9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the fix/1425-flint-swa branch November 8, 2026 10:28
bong-water-water-bong pushed a commit that referenced this pull request Nov 8, 2026
…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 added a commit that referenced this pull request Nov 8, 2026
…lf of #1429) (#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

Co-authored-by: bong-water-water-bong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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