Repository navigation
mem_admit: read bool arrays, so a GGUF's sliding_window_pattern counts (flint's KV grows with the context) - #1433
Conversation
…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]>
|
ready for review at 80b5eb6 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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.mdclause 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]>
|
Following both reviews ("land one, fold the other's unique half in"), this PR is now the union. Re-run at One fact for whoever chooses between the two branches: #1430's fixture loop ready for review at 548c44b |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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.
|
Heads-up, not a new verdict: #1429 (now READY at |
|
Coordination, because #1433 and this PR fix the same defect and collide on one line (
So the union is small, and I have pre-built it rather than promising it: Plan, either way:
Neither needs a merger decision on content — the duplicate is |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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).
…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
…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]>
Fixes #1425
Cause
model_need()already lets asliding_window_patternarray in the GGUF decide which layers attend over the full context. Butread_gguf_header()keeps only integer arrays (GGUF types 0-5, 10, 11). gguf-py writesadd_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 keysmodel_need()reads is a bool, so only the pattern arrays change.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:bools()fixture writer, with the bytes laid out as gguf-py writes them;Proof (strixhalo, CPU,
g++ -std=c++26 -Wall -Wextra, under thermal-run)Same test file, compiled against
origin/main'sapp/mem_admit.h, then against this branch's:tools/copyright.py --check: exit 0 (no new files).Not measured
model_need().mem_admitctest ormem_admit_route.sh(which needs a full engine build); the unit test above is that ctest's source.🤖 Generated with Claude Code