Repository navigation
mem_admit: a sliding-window pattern is a BOOL array, so read it like one (Fixes #1425) - #1430
bong-water-water-bong wants to merge 1 commit into
Conversation
…one (Fixes #1425) The issue reads as "flint is missing from model_need()'s per-arch list", but flint is not priced by a constant at all: llama.cpp's loader reads the pattern from the file (third_party/llama.cpp/src/models/flint.cpp:14, LLM_KV_ATTENTION_SLIDING_WINDOW_PATTERN) and the converter writes it as an array of Python bool (conversion/flint.py:24 -> gguf_writer.add_sliding_window_pattern -> add_array([...])), i.e. GGUF type 7. app/mem_admit.h's GGUF reader accepted t <= 5, 10, 11 as integers - so a bool array was skipped silently, for EVERY architecture that ships its pattern that way (flint, qwen, zaya, mellum, olmo...). The pattern lookup at :234 therefore never fired for them, the per-arch "one full layer in N" list was the only path that worked, and an arch not on that list fell to full_share = 0: a lower-bound KV estimate on an admission gate, which is the unsafe direction (#680's overrun class). The key prefix and the polarity were both already right (h.array() prefixes the arch; nonzero = windowed matches hparams.is_swa_impl). One-line fix: bool is an integer type for this reader. Red/green, same header both ways (49 layers, 35 windowed / 14 full shape, 4096 window, 262144 context, in tests/mem_admit_test.cpp): before: flint: the bool pattern prices its full layers at 262144 441.0000 MiB (want 3962.0000) FAIL flint: the estimate grows with the context FAIL after : flint: the bool pattern prices its full layers at 262144 3962.0000 MiB ok flint: the estimate grows with the context ok flint without a pattern: still the lower bound (every layer windowed) 441.0000 MiB ok So at 262144 the estimate was 9x low (441 vs 3962 MiB) for a flint-shaped header - ~3.4 GiB the admission gate would admit and then overrun with. The negative control keeps the documented behaviour for a header that genuinely has no pattern, so the fallback is unchanged; what changed is that a pattern the file does carry is no longer discarded. Verified: mem_admit_test PASS (whole file), and tools/copyright.py --check rc 0. Device-free.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at df5ced44 — but this is a duplicate of #1433 and the two conflict; exactly one should land.
The fix is correct and the claim is verifiable in the tree. GGUF_TYPE_BOOL = 7 (ggml/include/gguf.h:61), the integer types are 0..5,
10 (UINT64) and 11 (INT64), and gguf_writer.py:816 is literally def add_sliding_window_pattern(self, value: int | Sequence[bool]) — so a
pattern written as a list of Python bools arrives as type 7 and was dropped by the old is_int. Adding t == 7 is the whole fix.
Why it matters, in this PR's own words, is the part worth keeping: without it model_need() falls back to the per-arch "one full layer in N"
list, and for an arch that is not on it every layer is priced as windowed — a lower bound on an admission gate, which is the unsafe direction.
That ties it to the #680 overrun class, and it is cross-consistent with what lemonade #45 says about flint: 49 layers all priced as windowed,
which is why 24.07 GiB came back at every context size. Reading the file's real pattern (35 sliding / 14 full of 49, in #1433's fixture) would
price 14 layers as full and raise the estimate — correctly.
The duplicate: #1433 makes the identical one-token change to the same is_int in the same file, with a near-identical test helper
(Gguf& bools(...) writing type 9 of type 7). git merge-tree --write-tree df5ced44 80b5eb63 reports 2 conflicts, so they cannot both land.
My recommendation, if the choice is mine to make: keep this one and fold in #1433's two unique pieces —
- its concrete flint fixture (35 sliding / 14 full of 49), which pins the real shape rather than a generic bool array, and
- its one-clause
docs/serve.mdnote that flint's loader requires the array.
and close #1433. The reason I would keep this one as the base is the sentence above: "a lower bound on an admission gate, which is the unsafe
direction" is what a future reader needs in order to know why a missing type check is a safety bug rather than a tidiness one. If the other lands
first, take that sentence across instead — the union is what should merge, not either half alone.
…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]>
…s (flint's KV grows with the context) (#1433) * mem_admit: read bool arrays, so a GGUF's sliding_window_pattern counts (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]> * mem_admit: say why the bool type check is a safety fix, not a tidiness 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]> --------- Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
|
Closing as superseded: main already carries this fix, from #1433 ( For the record, since the two arrived independently and reach the same conclusion by the same route (bool arrays were dropped by the header
No merge from me; branch withdrawn. |
Fixes #1425. The issue reads as "flint is missing from
model_need()'s per-arch list", but flint is not priced by a constant at all —and the real defect is one type predicate, affecting every architecture that ships its pattern as bool.
The diagnosis, from the pin
third_party/llama.cpp/src/models/flint.cpp:14readsLLM_KV_ATTENTION_SLIDING_WINDOW_PATTERNfrom the file, andconversion/flint.py:24writes it as an array of Pythonbool(gguf_writer.add_sliding_window_pattern([kind == "sliding_attention" …])→
add_array([...])) — i.e. GGUF type 7.app/mem_admit.h's header reader acceptedt <= 5 || t == 10 || t == 11as integers, so a bool array was skipped silently (f.ignore(n)and no error). Consequences: the pattern lookup at
:234never fired for flint — or qwen, zaya, mellum, olmo, which write theirs the same way —the per-arch "one full layer in N" list was the only path that ever worked, and an architecture not on that list fell to
full_share = 0. That isa lower-bound KV estimate on an admission gate, which is the unsafe direction: it admits loads that then overrun (the #680 class the
refusal line cites).
The key prefix and the polarity were both already right, so neither is touched:
h.array()prefixes the arch (arch + "." + key, matching"%s.attention.sliding_window_pattern"), and "nonzero = windowed" matcheshparams.is_swa_impl(1= SWA,0= dense).Red/green on the same header (
tests/mem_admit_test.cpp)A flint-shaped header: 49 layers, 35 windowed / 14 full, window 4096, at the model's own 262144 context.
So at 262144 the estimate was 9x low (441 vs 3962 MiB) for a flint-shaped model — ~3.4 GiB the gate would admit and then overrun with, which
is the order the issue itself estimated for flint's 14 full layers. The negative control pins the documented fallback: a file that genuinely has
no pattern still prices every layer windowed; what changed is that a pattern the file does carry is no longer discarded.
Verification
mem_admit_test→ PASS (whole file, both arms above),tools/copyright.py --checkrc 0, built and run device-free under~/lb/thermal-run.sh. No behaviour change for any header whose pattern is an int array or absent.cc @pi-prs