Repository navigation
mem_admit: price flint from its own pattern array, and say when the estimate is a lower bound (Refs #1425) - #1429
Conversation
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: 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 withadd_arrayas ARRAY of BOOL (element type 7). I wrote one with the fork's owngguf-pyand read it back:flint.attention.sliding_window_pattern element type = [ARRAY: 9, BOOL: 7]. read_gguf_headerkeeps an array only ifis_int(et), which ist <= 5 || t == 10 || t == 11. 7 isn't in it, so the array goes tof.ignore(...),h.array("attention.sliding_window_pattern")is null, andfull_share = 0.tests/mem_admit_test.cppwrites 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: acceptt == 7.as_intwithsize[7] = 1already 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.
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
|
You were right and the fix is in at
Reproduced your fixture exactly (49 layers, That is your post-fix table to three decimals, so the mechanism is confirmed rather than argued. PR body updated to drop the claim you corrected ("a loadable flint pack is priced correctly today" was true only of my |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 4d94547a397128bf55a5a539eeb04e75475f569b
All three items from my review at a74e36ec are closed by 4d94547:
- The reader:
is_intis nowt <= 5 || t == 7 || t == 10 || t == 11, so a bool pattern array is kept. - 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. - 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.
|
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 |
…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
4d94547 to
8571301
Compare
|
#1433 merged, so the rebase this PR's coordination note promised is in at What this PR is now, on top of #1433 (its
(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
left a comment
There was a problem hiding this comment.
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 includesno pattern array, unlisted arch: the need is flagged a lower boundandthe 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, withkv_lower_bound=0at 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.
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-pyand foundwhy, 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 intfor the single-interval form and
add_array(key, value)for the per-layer form. Every converter that writes theper-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'sread_gguf_headerkept an array only whenis_int(et), andis_intwast <= 5 || t == 10 || t == 11-- 7 is not in it, so the array was skipped (f.ignore(...), no error), the patternlookup never fired,
full_sharestayed 0, and the model was priced all-windowed: the issue's symptom, at itsplainest.
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
is_intacceptst == 7-- one character.size[7] = 1andas_intalready read it as 0/1, so nothing elsechanges.
.bools(...)helper (ARRAYof BOOL), and an int32 row stays beside it because the single-interval form really is an int.
ModelNeed::kv_lower_boundstays, and is now what it says on the tin: set only when a header has a slidingwindow 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 itcannot 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_window4096, a bool pattern with 7 full layers,head_count_kv4, k/v 128 -- built againstthis head, and against a copy with
t == 7reverted: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 --checkclean.Fixes #1425