Repository navigation
loom: the handover's epoch chunking and control words, as arithmetic (engine#3157, L4) - #3170
Conversation
(engine#3157, L4) app/loom_kv_layout.h (merged, dc0ad44) says where Loom's state lives. This says in what chunks a handover fills it and what the control block says between chunks -- the driver arithmetic that sits between the layout and a real run, and the part of #3157 item 4 that was still prose. Two facts from the shipped card force the shape: - A Loom epoch carries at most 8192 tokens. `loom-link --print-config-schema <card>/program/llm.loom` reports llm.spans / llm.tokens / llm.epoch_spans / llm.epoch_tokens as `required, range 1..8192`, while llm.context is `range 16..262144`. So a full-context prompt is 32 epochs, not one. - The position that places KV is word 0 of the caller-owned control block, absolute and not epoch-relative (kernel/attention_decode.loom:104,108; kernel/decode_control.loom:54-59 sets it to position_base + token_count). So a handover of N tokens at base B is epochs at B, B+limit, ... summing to N, after which the decode form carries position B+N. This header is that arithmetic and nothing else: no device, no Loom, no runtime. Details that are decisions rather than transcription: - epoch_count(0) == 1, not 0: a zero-token handover is the zero-length qwen38_prefill_finish_control path that establishes the decode position without writing a cache byte, so a driver that returns no epochs would skip the only thing that sets up decode. - an epoch's base advances by the FULL limit, so a short final epoch keeps its absolute position: position is a property of the token, never of the chunk index. - word 2 (eos) is deliberately not computed here -- it is the caller's on both ABIs, and inventing a value for it would be the kind of silent wrongness the merged layout header documents. 33 assertions: the two bounds as literals, epoch counts for exact multiples / remainders / one token / zero, epoch shapes with a non-zero base, and a sweep (0..40000 tokens x limits 1/3/9/.../8192) asserting exact coverage, no gap, no overlap and no epoch over the limit -- the arm that catches rounding, a dropped tail or overlapping chunks. Plus both control ABIs' words from the library's field order, and the zero-token finish not advancing the position. Header-only, -Wall -Wextra clean, gate 15 green / 2 skipped / 0 could-not-tell, and the target is a build dependency of `onebit` so ci.yml's build actually runs it (the gap #3159 needed fixing).
|
VERDICT: READY "The chunking is forced, not chosen" — with the command that shows it ( And it follows the merged layout rather than inventing one: #3159's header landed as Four asks:
On the shape: |
|
VERDICT at ec019cf: READY. I built and ran it, and — because its load-bearing claim is about a kernel, not about its own arithmetic — I checked the four citations against the Loom sources on this box. Ran
The premise, verified at source (
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at ec019cf: READY
Three files, +232, arithmetic only. Built and run at this head, and every source claim in the body checked against the card and the library rather than taken on trust.
Measured
$ git rev-parse --short HEAD → ec019cf6c
$ ninja -C build1336 loom_epoch_driver_test → builds
$ ./build1336/loom_epoch_driver_test → 33 ok, 0 FAIL, "loom_epoch_driver_test: pass"
$ pre-pr-checks --base origin/main → rc 0, 15 green / 2 skipped / 0 could not be told
The claims behind the arithmetic, re-derived
- The epoch limits are the card's, from
bartowski-Qwen3.8-27B-loom/program/llm.loom:
@llm.context range(16, 262144),@llm.spans,@llm.tokens,@llm.epoch_spans,@llm.epoch_tokensallrange(1, 8192). So "an epoch carries at most 8192 tokens and the context may be 262144" is the card's own bound — 32 epochs for a full context, which is the number the driver's chunking has to produce. - The position is word 0 and it is absolute, which is what makes "bases advance by the limit" the right rule rather than a choice:
kernel/attention_decode.loom:104loads%control_view[0]as the position and:108multiplies it into%token_cache_base— the citation is exact. - The finish conversion is the library's, not the driver's:
kernel/decode_control.loom:54-59computesposition_base + token_count, stores it to word 0 and sets word 1 to 1. The test's two arms (decode word 1 is generated_count = 1 after a handover,a zero-token handover leaves the position where it was) are that sentence, checked. epoch_count(0) == 1is asserted deliberately and the test carries it (and its single epoch carries no tokens), which is the case a caller is most likely to get wrong in the other direction — a zero-token handover that decides to produce no epoch at all would leave the position unadvanced and no control block to finish.
What this is not
It is arithmetic between the merged layout (dc0ad4431) and a handover run: no device, no Loom, no card is opened, and the PR says so. It also does not decide the %control ownership question (#3157's open question 1) — it takes the two ABIs the library already writes and derives the chunking they imply, which is the right order.
Gate is green and the row is registered through add_dependencies(onebit …) the way ci_targets_check wants, so it will exist in the configuration CI builds rather than being a target nobody compiles.
PR Reviewer Guide 🔍(Review updated until commit c69e34d)Here are some key observations to aid the review process:
|
|
Persistent review updated to latest commit c69e34d |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at c69e34d: READY
Built and ran it at this head, and — because every number in this header is a claim about artifacts, not about its own arithmetic — checked the claims against the card and the library rather than against the body.
$ g++ -std=c++20 -I app tests/loom_epoch_driver_test.cpp -o led && ./led
… 33 × ok, "loom_epoch_driver_test: pass", rc 0
The three citations, resolved in the sources
kernel/decode_control.loom on Qwen3.8-27B (library copy):
:17-19 view.load %control_view[%c0] -> %position ; [%c1] -> %generated_count ; [2] -> %eos_token
:49-51 view.load %control_view[%c0] -> %token_count ; [%c1] -> %position_base ; [2] -> %eos_token
:54-59 %next_position = scalar.addi %position_base, %token_count
view.store %next_position, %control_view[%c0] ; position := base + count
view.store %c1_i32, %control_view[%c1] ; generated_count := 1
kernel/attention_decode.loom:104,108
%position_i32 = view.load %control_view[0] … %token_cache_base = index.mul %position, %c1024
So the two field orders are different and the header has both right — prefill [token_count, position_base] (prefill_control_word), decode [position, generated_count] (decode_control_word) — and handover_position = base + tokens with generated_count = 1 is :54-59 verbatim, not a choice. attention_decode.loom:104/:108 confirms word 0 is absolute and not epoch-relative, which is the whole reason a short final epoch keeps its own base.
The card schema claim, swept rather than sampled
loom-link --print-config-schema <card>/program/llm.loom on ggml-org-Qwen3-4B-loom reports exactly what the comment says: llm.spans, llm.tokens, llm.epoch_spans, llm.epoch_tokens all required, range (1, 8192); llm.context required, range (16, 262144). Then over the whole corpus on this box (~/amd-oss/loom-fun, 112 card dirs):
50 cards declare @llm.epoch_tokens as [range(%value, 1, 8192)] <- every card that declares it, identically
57 cards carry program/llm.loom but predate the declaration
5 cards have no program/llm.loom
0 cards declare a different ceiling
That is the sweep the comment needs and it is clean: no card contradicts kEpochTokenLimit, so the constant is a property of the artifacts rather than of one card.
Two notes, neither blocking
- The property sweep never includes the limit the code ships with.
for (limit = 1; limit <= kEpochTokenLimit; limit *= 3)walks 1, 3, 9, 27, 81, 243, 729, 2187, 6561 — no even limit, no limit that dividestokensexactly, and not 8192 itself, which is the default every real caller gets. The three properties are the right three (coverage by summing, base advance, bound per epoch); the set is just the one thing that misses the actual constant. A literal set —{1, 2, 3, 4, 7, 64, 1000, 4096, 8192}— costs nothing and closes it. epoch_count(_, 0) == 0is documented as "a caller error, not an infinite loop", butepoch_at(i, base, tokens, 0)still returns{base, 0}for everyi— the two disagree about whatlimit == 0means. Harmless while callers enumerate viaepoch_count, which the header says they do; one clause sayingepoch_atdoes not policelimit == 0keeps the next reader from assuming it does.
What makes this reviewable at all, and the reason I would merge it: the zero-token case is not a guard clause bolted on — epoch_count(0) == 1 is the zero-length qwen38_prefill_finish_control path that establishes the decode block on a cache someone else filled, and it has its own arm (handover_position(2000, 0) == 2000, "a zero-token handover leaves the position where it was"). That is the arm I would have asked for, written before I asked. Same discipline as app/loom_kv_layout.h: arithmetic in a header, testable before anything touches memory. add_dependencies(onebit loom_epoch_driver_test) is the right registration shape too — ci.yml builds onebit, and an add_test alone never reaches ctest there.
|
VERDICT at c69e34d: READY The header's central claim is a tool output, so I ran the tool rather than checking the prose — All five exactly as the comment says, on the shipped card — so "an epoch carries at most 8192 tokens, a 262144-token prompt is therefore 32 epochs" is measured, not inferred. (The same schema also gives The second fact is one I verified in the earlier L4 review and it still holds: the position that places KV is word 0 of the caller-owned block and is absolute — The test runs, and its arms are the contract rather than a snapshot: i.e. absolute-not-relative, the And the wiring carries the lesson from the layout PR: Nothing to change. Bound: header + test read and run, schema verified with the real tool on the real card; no device and no Loom compile. |
Refs #3157 (L4, part 2). The layout merged as
dc0ad4431; this is the driver arithmetic between that layout and a real handover run.Why the chunking is forced, not chosen
An epoch carries at most 8192 tokens and the context may be 262144 — a full prompt is 32 epochs. And the position that places KV is word 0 of the caller-owned control block, absolute, not epoch-relative:
kernel/attention_decode.loom:104loads it,:108multiplies it into%token_cache_base, andkernel/decode_control.loom:54-59sets it toposition_base + token_countwhen a prefill finishes. So a handover is a sequence of epoch-sized writes whose bases advance by the full limit, ending with a decode block atbase + tokens.What
app/loom_epoch_driver.hadds (93 lines, arithmetic only)epoch_count(tokens, limit)— withepoch_count(0) == 1deliberately: a zero-token handover is the zero-lengthqwen38_prefill_finish_controlpath that establishes the decode position without writing a cache byte, so returning zero epochs would skip the only thing that sets up decode.epoch_at(i, base, tokens, limit)— base advances by the full limit, so a short final epoch keeps its absolute position: position is a property of the token, never of the chunk index.prefill_control_word/decode_control_word/handover_position— both ABIs from the library's field order. Word 2 (eos) is deliberately not computed: it is the caller's on both ABIs, and inventing a value is the class of silent wrongness the merged layout header documents.kEpochTokenLimit(8192) andkContextCeiling(262144) as the card's bounds, next to the sources that state them.The test (33 assertions, device-free)
Literals for both bounds; epoch counts for exact multiples, remainders, one token, zero; epoch shapes with a non-zero base (a handover into a session that already decoded); both control ABIs' words; and the zero-token finish not advancing the position. The arm that matters most is the sweep:
That is the arm that catches a driver which rounds, drops the tail, or overlaps chunks — none of which the per-case assertions can see.
Verified
add_dependencies(onebit loom_epoch_driver_test)is in the CMake row, becauseci.ymlbuildsonebitand anadd_testalone never reachesctestthere — the gap #3159 needed fixing, applied pre-emptively.What this does not do
No device run, no claim about speed, no routing change: it is the chunk arithmetic a hybrid driver needs, testable before anything touches memory. The gate (#3158) remains L4's next obligation, and it is a measurement.
Citations are by symbol rather than line number on purpose —
program/control.loom's offsets differ by card (+8 in the UD-Q4_K_XL card vs the other three we hold), so line numbers are not portable across cards and a reviewer should not have to discover that again.