Repository navigation
Description
What this is
L4 of the Loom GPU switch. GPU serving moves to Loom (loom-serve + hrx-loom cards); NPU work continues unchanged. That splits our hybrid route in two: today the NPU prefills a prompt and hands the KV to our llama.cpp/HRX decoder; after the switch the consumer of that prefill is Loom's decode, whose state lives in its own layout. This issue is the design for that handover, before any code.
Frozen by the same direction: no new GPU HIP kernels, no new llama.cpp-fork HRX matcher work, the current route stays as the fallback for models Loom does not cover. Nothing here touches the fallback.
What Loom holds, measured from the MIT sources
Read at hrx-loom-library ba7abef (MIT, © 2026 AMD ROCm Software), model Qwen/Qwen3.8-27B, whose composition is a hybrid like ours (64 layers: 15 full-attention, 47 gated-delta-net).
Both state roots are caller-owned buffers, bound at issue time and shared between prefill and decode. That is the whole handover surface:
model_decode.loom:14 @qwen38_gdn_layer_decode(%layer, %gdn_ordinal) launch(%parameters, %residual, %gdn_state)
model_decode.loom:16 @qwen38_attention_layer_decode(%layer, %attn_ordinal) launch(%parameters, %residual, %control, %attention_cache, %attention_output)
epoch.loom:16 @qwen38_text_prefill_body_impl(%token_count…) launch(%parameters, %residual, %control, %gdn_state, %attention_cache,
%transition_capture, %rows, %input_tokens)
So prefill and decode take the same two roots (%gdn_state, %attention_cache) plus %control; the prefill's %transition_capture and %rows are prefill-only scratch. Nothing about the caches is Loom-internal — the caller supplies them.
Attention cache (attention_layer_decode.loom:73-83) — one root, blocked per attention ordinal:
%cache_token_bytes = 2048 // 1024 f16 per token, per K and per V
%cache_bytes = cache_capacity * 2048
[attention_layer_cache_bytes, key_off, value_off] = buffer.pack [align(256) %cache_bytes, align(256) %cache_bytes]
%layer_key_cache_offset = attention_ordinal * attention_layer_cache_bytes + key_off // key_off = 0
%layer_value_cache_offset = attention_ordinal * attention_layer_cache_bytes + value_off
view<[cache_capacity * 1024] x f16> // token-major: element = position*1024 + j
cache_capacity is a specialization (config.decl … range(1, 262144), attention_layer_decode.loom:15) — chosen when the command buffer is materialized, not an issue-time value. The comment at :70-72 states the intent: one persistent root for all full-attention layers, key and value arrays adjacent, token-major so the grouped-query traversal is contiguous within a head.
GDN state (gdn_layer_decode.loom:69-76) — one root, blocked per gdn ordinal, and it is f32:
%recurrent_state_bytes = 3145728 // 786432 f32
%conv_history_bytes = 122880 // 30720 f32
[gdn_layer_state_bytes, recurrent_off, conv_off] = buffer.pack [align(256) …, align(256) …]
%layer_state_offset = gdn_ordinal * gdn_layer_state_bytes
Consequence for us, and it is the encouraging one: 3,145,728 B per layer is the same 3.14 MB/layer our own route already moves — docs/zero-copy.md:197 measures the GDN state sweep at 604 MB read+written = 48 layers × 3.14 MB × ~4 passes. So the hybrid's GDN state is the same object in the same size; Loom keeps it device-side where we sweep it on the host. That is the first thing to measure after the handover exists, and it is a candidate win independent of decode speed.
%control is opaque. It is passed to kernels as a buffer and its fields are not described in the .loom (attention_layer_decode.loom:39,113 pass it straight to @qwen38_attention_kv_prepare_decode / @qwen38_dispatch_attention_decode_split_partial). The token position that advances the cache is read from it. This is the one part of the contract I cannot specify from the library alone — see the open questions.
What our hybrid does today
docs/hybrid.md:125-132, ONEBIT_KV_SHARE=1: the decoder exports its KV buffers and the prefill imports them as two dma-buf fds; the provider writes the prompt's cells; the decoder then takes cells 0..N-1 as positions 0..N-1 with no data movement (llama_kv_cells_adopt). The layout contract is llama.cpp's (src/llama-kv-share.cpp, share_layout): a token's K|V row is contiguous in the prefill's output and is not the layout the decoder reads, so the writer splits it.
The handover mechanism is therefore already the right one — a zero-copy fd handoff, writer addresses the reader's memory. What changes is the layout and the number of roots: one llama.cpp KV cache becomes two Loom roots (f16 attention per attention ordinal, f32 GDN per gdn ordinal), and Loom's cache_capacity is a specialization rather than a runtime size.
The design (proposal, to be argued in this thread)
- One exporter: the Loom-serving process. Loom already takes the roots from the caller, and the zero-copy rule is that the exporter's mapping is what the NPU must address (
docs/zero-copy.md:219-235: an imported range works when the NPU addresses the exporter's mapping;mmaping an import through amdxdna failsPopulate ranges failed, ret -14and poisons every later submission in the process). Today the decoder exports and the provider imports; the same shape holds with the roles unchanged — Loom allocatesattn_cacheandgdn_state, exports fds, our NPU prefill imports and writes them. - The writer writes Loom's layout directly, at the offsets and strides above: attention key/value blocks per
attention_ordinal, token-major f16; GDN recurrent + conv history pergdn_ordinal, f32, 256-aligned blocks. No intermediate buffer, no repack pass — that is the zero-copy requirement, not an optimisation. - Capacity is agreed before materialization.
cache_capacityspecializes Loom's command buffers, so the route must fix it (a context-size class) before the first decode is materialized, and the exporter allocates exactly2 × align256(capacity × 2048)per attention ordinal. A capacity that changes per request means re-materializing; that is a cost to measure, not to assume. - Position advance via
%controlis the one interface we do not control yet (see below). - KV precision changes: Loom's attention cache is f16 only, while our route's KV types are configurable (q8_0/q4_0 work exists on the fallback). So the hybrid under Loom is an f16-KV hybrid; whether that is acceptable on accuracy is a gate question, not a design choice, and it goes in the same table as L2's.
Zero-copy rules that bind all of this, quoted from docs/zero-copy.md: strixhalo is one DRAM shared by CPU, iGPU and NPU, so a copy between them is a tax with no coherence benefit; the NPU must address the exporter's mapping; import acceptance is a driver contract with its own test (npu_import_contract).
Open questions, and who can answer them
%control's layout: not in the.loom. Either Loom produces it (a zero-token "epoch" prefill that only establishes position/length —epoch.loomsuggests such a boundary exists), or we need its field layout from the Loom side. This decides whether the handover is an API call or a struct we write.- Who owns
cache_capacitywhen1bit servepicks the route (L1's route table): the serve context size must be expressible as a Loom specialization class, or the card needs a capacity range that covers it. - MTP/dflash: the composition has
dflash*.loomandmtp.loom; our hybrid explicitly hands only the prompt KV and drafts on the target (docs/hybrid.md:75). Whether Loom's decode is driven with its own MTP head under the hybrid is out of scope here but decides which decode program the prefill must feed. - Is Loom's prefill program optional? If Loom can decode from a cache we filled, we skip its prefill entirely; if its prefill also computes something the decode expects beyond KV/GDN (the
%control/%rowsstate), we must produce that too.
Acceptance for L4
Per the switch's condition 2, this handover only routes traffic after the same gate as L2 on the same model: interleaved A/B (≥ 4 rounds per arm, gpu-hold, same prompts, load and power mode recorded) plus accuracy (greedy agreement on fixed prompts, mean KLD and same-top-token % vs CPU on wiki.test.raw 8x512), and the numbers go in a table here. The comparison for L4 is hybrid-NPU-prefill → Loom decode against hybrid-NPU-prefill → our decoder, so the prefill cost cancels and the decode side is the only difference.
First PR (next in this thread)
The layout, as code, with a device-free test: a small header that computes Loom's offsets and sizes from (capacity, attention_ordinals, gdn_ordinals) and asserts the numbers against the values above (2048 B/token, 3,145,728 + 122,880 B/ordinal, 256-alignment). That is the contract the NPU writer will implement, testable without a device and without Loom present — the same shape as app/mem_admit.h + tests/mem_admit_test.cpp, which is how the GTT reserve arithmetic landed.
No new HIP kernels, no matcher work, nothing in the fallback path touched.
Activity
bong-water-water-bong commentedon Nov 21, 2026
Three things the sources here settle, and one arithmetic correction to the proposal
Read at the same ref the issue cites —
~/amd-oss/loom-fun/hrx-loom-library@ba7abef([Qwen] Bound output-head work with shared GPU kernels (#89),git log -1).1.
%control's position is not necessarily inside the buffer — there is a separate command parameter.model/Qwen/Qwen3.8-27B/program/attention_layer_decode.loom:So the parameter the cache walk advances by is a command-list parameter, materialized as a constant
0in this program — not a field the caller writes into%control. That reframes open question 1: it is not only "what is inside%control", it is "which command-list variant carries position N", i.e. whether the handover needs one materialized decode list per position (or per class of positions) — a materialization cost question like item 3, not a struct layout question.%controlis still passed into@qwen38_attention_query_prepare_decode/@…kv_prepare_decode(:35,:37) and its fields are still undescribed, so this does not close Q1 — but it splits it into one problem we can work around (position via command variants) and one we cannot (whatever else the two prepare kernels read from%control).2. An epoch entry point that takes and returns the control state does exist in the public surface — which is Q4's boundary:
%control_stateis caller-owned, passed in and back out, with abuffer.lengththe program reads. So the shape the proposal wants for Q1's optimistic branch is real, and the first experiment is cheap: materialize a decode with a capacity class, call the epoch program withfirst_count = Nand zeronext_count, and see whether the subsequent single-token decode produces the same logits as feeding the same N tokens to Loom's own prefill. That test decides "API call or struct we write" without needing the struct described — and it is device work, so it belongs in agpu-holdticket rather than in this thread.3. Arithmetic correction: the "same 3.14 MB/layer" claim understates Loom's per-layer GDN state by 122,880 B (3.9%).
3,268,608is what%layer_state_offset = gdn_ordinal * gdn_layer_state_bytesstrides by, and the proposal's own item 2 lists both blocks ("GDN recurrent + conv history pergdn_ordinal"). So3,145,728is the recurrent part only:Both numbers are arithmetically right; they are just not the same object. If
docs/zero-copy.md:197's 604 MB counts only the recurrent sweep, then the comparison "Loom keeps it device-side where we sweep it" is exact only for the recurrent part, and our route's conv-history traffic (if any) is the rest. Worth stating in the same units before the "candidate win independent of decode speed" is quoted anywhere — 3.9% is small, but it is the difference between "the same object in the same size" and "the same object plus one block we did not count".What I am not answering: Q2 (
cache_capacityownership) needs L1's route table, which is not in this tree yet; and Q3 (MTP/dflash) is out of scope by the issue's own words. Nothing above changes the proposal's five items — items 1, 2 and the exporter rule in particular hold as written; the only corrections are the per-layer figure and the fact that position is a command variant, not (only) a%controlfield.bong-water-water-bong commentedon Nov 21, 2026
Open question 1 is answered from the library:
%controlis a struct we write, not an API to negotiateRead at
hrx-loom-libraryba7abef,model/Qwen/Qwen3.8-27B. It looked opaque because the program files pass it straight to kernels — but a kernel views it, and the geometry is spelled out in the library's own sources.The position that advances the cache is word 0, read directly by every attention layer:
%controlis therefore the sequence packet, and its arithmetic is the function bodies inmotif/sequence/qwen3_8/packet.loom(packet_bytes = 40 + 112·capacity, two16 + 36·capacitybanks, then indices / policies / identities / sources / shape). The header is three words, and there are two ABIs over the same three words, distinguished only by which command runs next:decode_control.loom:17-19)decode_control.loom:49-51)positiontoken_countgenerated_countposition_baseeos_tokeneos_tokenqwen38_prefill_finish_controlis the converter: it loads[token_count, position_base, eos]and stores[position_base + token_count, 1](:54-59, fixtures attest/decode_control_test.loom:53-71—[3, 17, 31]→[20, 1]). That kernel is the handover's landing point.The zero-token epoch exists, but only at kernel granularity
epoch.loomwas the right hunch.qwen38_prefill_finish_controlloadstoken_countwith no range assumption, sotoken_count = 0is legal and storesposition := position_base,generated_count := 1without touching a cache byte. Every public prefill command is stricter —range 1..512inepoch.loom:10,model_prefill.loomtext_prefill_chunk/_transition— so no command is zero-length, and that kernel is the library's only zero-length path. Meanwhileqwen38_continue_spansassumes its plan count asrange(0, capacity), i.e. zero accepted results are a normal state on the continuation side.So: no need to ask the Loom side. Both halves of the L4 question are now concrete:
control = [N, base, eos]and letprefill_finishconvert it;control = [base + N, 1, eos], wherebase + Nis the absolute index of the next token (context_count = position + 1is what the decode attention attends over, so this is the whole prompt by construction).Consequences for the other questions
@qwen38_text_decode_greedytakes%controland callsoutput_head_greedy_with_hidden, which has no packet argument at all — so a greedy handover writes 12 bytes of header + the two state roots and no packet tail. Only the sampled path (output_projection_sampled→sampling_partial_rows/sample_rows) reads the identities/policiesregions, at the offsets in the table above.mtp.loom/dflash*keep their own drafts; the handover boundary above does not move.eos_tokento the commit kernels but the live row count to the samplers (kernel/sampling.loom:45,92) andkernel/output_spans.loom:35, and nothing in the sampled path writes that count. Aneosid smaller than the row count would drop rows without an error. The writer owns which meaning is in place.Status
#3159now carries this as arithmetic as well as prose: the header offsets, both ABIs, the packet geometry andpacket_capacity(bytes), with the geometry checked against two independent artifacts rather than restated —packet.loom's function bodies andtest/sampling_test.loom's own hardcoded literals (policy origin9760 = 32 + 128·76, identity origin12832 = 32 + 128·100, and atensor<3594xi32>epoch =3594 · 4 = 40 + 112·128bytes at capacity 128), plus a tiling sweep proving the regions cover the allocation with no gap and no overlap. 38 assertions, device-free.What L4 still owes is unchanged and is the gate's, not this issue's: the interleaved A/B and the accuracy table (§Acceptance). Nothing here claims a speedup.
bong-water-water-bong commentedon Nov 21, 2026
@cl-npurt's three points above are the right corrections to read my answer against, and they converge with it rather than competing. Reconciled, with the one place I have to refine my own wording:
1. "The position is a command-list parameter" — yes, and it is the word index, not the value.
attention_layer_decode.loom:49materializes%control_position_index = index.constant 0and:122passes it into@qwen38_dispatch_attention_decode_split_partial, which is exactlykernel/attention_decode.loom:104using it to selectcontrol[0]. So the index is baked at materialization (a different position word would need re-materialization); the value is not — the file's own header says so: "The residual, control, and cache roots are rebound for each sequence at issue time" (attention_layer_decode.loom:44-45). That is what makes the handover a struct write: word 0 is caller-owned, and its index being a compile-time 0 is a strengthening of the answer, not a caveat on it.2.
@text_encode_epoch_v1is real, andnext_count = 0is first-class — but it is the planner layer, not a token-consuming pass.program/text/qwen3_8/epoch.loom:192takes%control_stateand%metadataas separate buffers, and%control_stateis a 14×5 i64 transfer table (epoch_transfers,:567-640:metadata/input/word/pair/header/descriptor/recordslot geometry), not the model's KV position. It also writes the packet header as[token_count, count, output_count](:184-186), which is the production form of word 2.That last detail refines something I stated too flatly: word 2's "live row count" meaning is the production convention, and the
eosmeaning belongs to the decode-only%control. In the text composition the two roles live in two buffers (%control_statevs%metadata); in the 27B model program they are one (%epoch). So my caveat stands and is now located precisely: a writer mixing the two must know whether its buffer is the packet or the control block.And the zero-length claim needs the same refinement: I said "no command is zero-length". At the model level that holds (
epoch.loom:10and everymodel_prefill.loomentry arerange 1..512, withprefill_finish_controlas the only zero-length kernel); at the planner levelnext_count = 0is an explicit branch (:223,%continues). Both support the same conclusion from different ends: a zero-token call is representable, and Loom does not have to run a prefill for us to take over its decode.3. The 3.14 MB vs 3.27 MB distinction is accepted and is now asserted, not narrated.
#3159atafdcbb2eccarries the three literals:4 × 48 × 3145728 = 603 979 776(the docs' 604 MB, recurrent only),4 × 48 × 3268608 = 627 572 736(a whole block, +3.9 %), and the gap192 × 122 880 = 23 592 960as the conv history. That also corrected a number in this thread from another lane:627 498 240is 74 496 low, which is why the test asserts the computed literal rather than the quoted one.bong-water-water-bong commentedon Nov 21, 2026
Correction to this issue's own premise, from the
#3159review: the shape is 16 full-attention and 48 GDN ordinals, not 15 and 47.Loom's
range(%value, lo, hi)is inclusive (hrx-system/loom/docs/src/guide/facts-and-specialization.md:88), sorange(%attention_ordinal, 0, 15)admits 0..15 andrange(%gdn_ordinal, 0, 47)admits 0..47. The composition agrees:model_decode.loom:26-27unrolls 16 groups of 3 GDN + 1 attention,:48-50launches GDN ordinals3*group + {0,1,2}(group 15 → ordinal 47) and:54launches attention ordinal%group→ 15. And 16 + 48 = 64, the model's depth.This matters beyond the header that pins it: anyone sizing an exporter from the sentence "15 full-attention, 47 gated-delta-net" allocates one block short on each root — 3 268 608 B of GDN and, at 4096 context, 16 777 216 B of attention — and the decode body writes into both.
#3159now carries 16/48 with the derivation in the header, so the arithmetic in that PR is the authoritative version and this paragraph should be read as superseded.The design's conclusions are unaffected (caller-owned roots, a struct we write, the handover is a re-layout): only the sizes move. Re-stated, at 4096 context the two roots are 425 328 640 B (16 × 16 777 216 attention + 48 × 3 268 608 GDN).
bong-water-water-bong commentedon Nov 21, 2026
L4 re-check at
cb9ae9e: the reading holds, and one part of my own answer is now out of dateDiffed the eleven files this design cites,
ba7abef..cb9ae9e(132 commits). Six changed; none of the changes touches the layout arithmetic. Constants re-quoted at the new pin rather than assumed:cache_capacityspecializationattention_layer_decode.loom:74,range(1, 262144)%cache_token_bytes = 2048:75— unchangedbuffer.pack [align(256) …, align(256) …]:77— unchanged:82-83— unchanged3145728/122880+ packgdn_layer_decode.loom:69-71— unchangedThe part that changed: the packet's word 2 has a writer now
At
ba7abefI wrote that word 2 is EOS to the commit kernels and the live count to the samplers, and that nothing in the sampled path writes that count. The second half is no longer true.motif/sequence/qwen3_8/packet.loomgained@qwen38_packet_compact_prefix, which ends by storing the header triple[token_count, span_count, output_count]across words 0/1/2 (it reads word 1 as the span count and assumes itrange(0, capacity)), andkernel/sampling.loomgained a%firstargument so the samplers testfirst + row < word 2— an absolute packet row bound, not a per-call count.So the two meanings of word 2 are two ABIs, not one buffer reused:
[position, generated_count, eos], convertable from[token_count, position_base, eos]byprefill_finish_control(unchanged atdecode_control.loom:17-19, 49-51, 54-59);[token_count, span_count, output_count], where the count is written by compaction and is absolute.That makes the writer contract stricter and the handover design unchanged: a hybrid writer must know which of the two blocks it holds, and conflating them still fails silently (an
eosid smaller than the output count drops sampling rows with no error).#3159is updated at9dda95b78with the new pin, corrected line citations, and this correction; 41 assertions, gate green.A fourth artifact for the row width, from the card
The refresh also re-mirrored the cards, and the Qwen3.8-27B card carries the model config next to the program:
layers: 64,kv_heads: 4,head_dim: 256,context_length: 262144,hidden: 5120. That is worth recording because it corroborates three things my arithmetic assumed from Loom's constants alone:kv_heads × head_dim = 4 × 256 = 1024 = %key_value_size, so%cache_token_bytes = 2048is the model's per-token K/V row, not an arbitrary constant;layers: 64 = 16 attention + 48 GDN, the cardinality corrected in#3159;context_length: 262144is exactly thecache_capacityspecialization's upper bound, i.e. the card can be materialized at full context — which is the constraint Q2 has to fit1bit serve's context choice into.Checked and out of scope
@qwen38_proposal_origin_bytes(new,12 × capacity) is consumed bymtp.loom/Qwen3.8-Flash-Next/program/propose.loom— the draft side, not part ofpacket_bytes, so the exporter's allocation for the handover is unchanged.continue.loomgained a%feedback_capacityconfig argument; the packet capacity range is stillrange(2, 2147483646), multiple_of(2).What L4 still owes is what it owed before: the gate (condition 2), on the model set L2 routes. Nothing here claims a speedup.
bong-water-water-bong commentedon Nov 21, 2026
Pin correction to my re-check above — and it is the pin that matters, so it should be read before the earlier comment. The L5 work moved to the released toolchain while I was re-checking, which fixes which revision this design should be measured against.
A shipped card records its own toolchain: the Qwen3.8-27B card's
info.jsongiveshrx_loom 0.2.0from PyPI withhrx_system v0.2.0, and itsversion.jsonnamesmodel-catalog: github:ROCm/[email protected]. So the programs a card runs are the tag's, and upstream HEAD (cb9ae9e), which I measured, is not an ancestor ofv0.2.0— the lines diverged, 50 files and ~2.9 k insertions apart in the 27B program alone.Re-verified at the tag (
v0.2.0=1fd6bd23), which is the authoritative revision for anything we ship:cache_capacityspecializationrange(1, 262144)attention_layer_decode.loom:15%key_value_size = 1024,%cache_token_bytes = 2048:52,:75:773145728/122880+ packgdn_layer_decode.loom:69-71range(…,0,15)/range(…,0,47)→ 16 / 4832+{72,76,100,108,112}C, bank16+36C,packet_bytes = 40+112Cpacket.loom:35-76,:82tensor<3594xi32>So the layout conclusion of this design is confirmed against the release the cards were built from, not just against a HEAD that day. Same line numbers as HEAD, so nothing in my arithmetic moves.
What does move is the word-2 half of the
%controlanswer, and it is the opposite of what I said this morning. Atv0.2.0there is noqwen38_packet_compact_prefixand the samplers have no%firstwindow:sampling.loom:45,92read word 2 as a live row count and nothing in the library writes it, so it is a caller-owned convention — the handover writer must store the count itself. The compaction writer and the absolutefirst + rowbound are a HEAD-only change, so my "the packet's word 2 has a writer now" applies to HEAD and not to what L2's gated models run.For L4 that is the stricter reading and the one to implement against: on the release, the writer owns words 0/1/2 of the packet (token count, span count, live output count) and the decode block's
[position, generated_count, eos], and mixing the two conventions fails silently in both directions.#3159is updated at4742be14fto state both revisions side by side, withv0.2.0as the primary pin.bong-water-water-bong commentedon Nov 21, 2026
Open question 2 is answered, empirically, and not the way I assumed. It asked who owns
cache_capacitywhen1bit servepicks the route. The answer is different for the two roots, and I had it wrong for the packet in#3159until this turn.The packet's capacity is caller-owned, not a specialization. The encode step infers it from the allocation it is handed:
and the shipped card's own encoder bounds it at
range(%packet_capacity, 1, 524288)(control.loom:2519,2551,3215in the Qwen3.8-27B card), tighter than the motif'srange(2, 2147483646), multiple_of(2). So the ceiling is 524288, and the largest packet an exporter budgets is40 + 112 × 524288 = 58 720 296 B(~56 MiB).The attention cache is the opposite, and the card does not pin it:
cache_capacityis aconfig.declspecialization in the model program, while the card'smodel.jsonvariant config carries onlyllm.card/llm.logitsandcache_capacityappears nowhere in the card's own program sources. So the number is chosen by whoever materializes the model program — i.e. L1's route table, exactly as Q2 suspected, but with no guidance from the card.The consequence that matters for the design: the two roots do not move together. One attention-cache specialization can serve requests with different packet sizes, so the route table can fix the cache class per model and let the packet track the request — no re-materialization per request size. That also fixes what the gate has to hold constant: the cache class must be pinned for both arms of an A/B (as
LOOM-GPU-SWITCHcondition 2 already requires for the runtime), while packet size may vary without invalidating the comparison.Landed as code and arms in
#3159at155febd47(45 assertions: the ceiling, its evenness, the 56 MiB budget, and the allocation-length round-trip). Q2 needs no further answer from Loom's side; what remains is for L1 to choose a class, and for the gate to measure it.bong-water-water-bong commentedon Nov 21, 2026
Correction to my pin comment above:
v0.2.0and HEAD have not diverged — the tag is 85 commits behind HEAD on a straight line.I had tested only the other direction (
cb9ae9eis not an ancestor of1fd6bd23), seenrc 1, and written "the lines diverged" in#3159and in the comment above. The tag is a subset of HEAD, so the 27B program diff I quoted (~2.9kinsertions over 50 files) is simply HEAD's work since the release — and, more usefully, anything verified at HEAD is evidence for the tag, which is the opposite of what "diverged" would have told a reader.What survives unchanged, because it never depended on ancestry:
2048B/token,3145728+122880per GDN ordinal,40+112Cpacket, the eight origins) — verified at1fd6bd23directly;v0.2.0nothing writes the epoch header and the count is caller-owned; at HEADqwen38_packet_compact_prefixwrites[token_count, span_count, output_count]and the samplers bound onfirst + row. That is a real difference across the 85 commits, not a branch divergence.epoch.loom:91-92) and capped at 524288 by the shipped encoder, while the attention cache is a materialization specialization the card does not pin.Fixed in
#3159at928dc00d5, where the paragraph now says "the tag is a subset of HEAD, 85 commits back" and gives the count.docs: the GPU route is moving to Loom; the HIP-kernel route is the fa…
bong-water-water-bong commentedon Nov 21, 2026
A constraint on this issue's own acceptance criterion, measured on the box: the accuracy arm requires
mean KLD, and no shipped Loom card can produce logits. Details and commands on #3158 (the gate issue), because it changes L2's harness rather than this design — summarised here because it decides what L4 can claim:loom-link --config=llm.logits=true, withllm.logit_slots), not a serve-time flag:loom-serve --helphas zero logits flags and no--configsurface at all, and neitherloom-benchmarknorloom-checkmentions logits;llm.logitsand all 55 arefalse(the other 4 default off), including both 27B cards, whose variant config is{"llm.card": true, "llm.logits": false};config.get @llm.logits(documented inloom-skills/tests/test_logits_fold.py:3), so with it off there is nothing to compare for KLD.For L4 that means: the handover's gate can be run on the shipped card for greedy agreement and same-top-token %, but KLD needs a logits-on link of the same program — an artifact to build, not a switch to flip. That is compatible with the design (it changes no layout or control ABI) and it does not change what L4 owes; it only means the KLD row has a build step in front of it, so it can be prepared before a
gpu-holdticket rather than discovered mid-run.Nothing in this affects the state layout or the
%control/packet contract — it is a property of how the cards are linked, and it is the same constraint for the fallback comparison arm.bong-water-water-bong commentedon Nov 21, 2026
Q2 gets a sharper answer, and it partly revises what I said two comments ago. I said the attention-cache capacity is a materialization specialization while the packet's capacity is inferred from the caller's allocation. Both hold. What I did not know is where the epoch/shape class comes from, and the card answers it: the host supplies it at load, as named config keys.
program/prepare.loomin the shipped card declaresfunc.decl import("prepare") @source_scope(%scope: buffer)and passes the key names as string literals through it:Measured, not assumed: linking the card's
llm.loomon its own fails[SYMBOL/007] … unresolved count: 12, and those twelve are exactly this list — so they are host-scope values resolved when the model is prepared/loaded, not constants baked at build.Consequences for L4, in order of how much they change:
llm.context/llm.epoch_spans/llm.epoch_tokens/llm.spans/llm.tokens/llm.poolare the same family of decision as the attention-cache class, and they are supplied together at load. That is a better place for the route table to act than a rebuild, and it means an A/B arms comparison can hold them fixed by pinning the deployment config.cache_capacityis aconfig.declspecialization and the card's epoch shapes areconfig.declkeys — both are configs; the difference is who supplies the value and when (host scope at load vs the bound the caller's allocation implies). Not verified: whether loom-serve can vary the host-scope keys per request, which is the difference between "one card, many classes" and "one card per class". That is a load-time experiment, onegpu-holdticket, and it decides how much of L1's route table is dynamic.llm.logitsis one of these host-scope keys, sitting in// logits:begin/// logits:endmarker regions that the card ships intact (prepare.loom:3-6, 37-40, 148-151, 162-167) — so "gate with logits on" and "gate at a chosen capacity class" are both deployment-config variants of the same artifact, not two different builds.Nothing here moves the state layout or the
%control/packet contract;#3159is unchanged at078c8ccd3with two READYs at head.bong-water-water-bong commentedon Nov 21, 2026
A hard epoch bound for the handover, read from the card's config contract
loom-link --print-config-schema <card>/program/llm.loomprints the card's fourteen configs with their ranges. Two of them bound how many tokens one Loom epoch can carry, and that is a constraint on this design that nothing in the library sources shows:So a Loom epoch is at most 8 192 tokens, while the context may be 262 144 — 32 epochs. For L4 that is not a detail:
attention_element_index(position, j, kv)is position-absolute, not epoch-relative), so the layout survives — but the driver has to run the epoch loop, and%control's position word (word 0) is what carries the absolute position from epoch to epoch. This is the concrete reason word 0 is caller-authoritative rather than derived.packet.loom:96allows capacity up to 2 147 483 646; the card's config caps the epoch at 8 192. Both times the shipped artifact is the binding limit, which is why#3159now measures at the card's tag rather than at HEAD.Not verified: whether
llm.tokens/llm.spansare per-epoch or per-request bounds in loom-serve's own bookkeeping — the schema gives ranges, not semantics, and the card'sprepare.loompasses both through the host scope. That question is answerable in the same one-ticket load check as the logits variant (~/.cache/scratch-cl-hrxnan/logits-card/card/haschat-8kandchat-logitsready for it), so I am not spending a ticket on it separately from L2's queued 27B row.bong-water-water-bong commentedon Nov 21, 2026
The epoch bound is model-size-independent; the config set is not — measured on two cards
I checked whether the 8192-token epoch ceiling
#3170encodes is a property of one model or of the card format, by runningloom-link --print-config-schemaon a second, much smaller card (Qwen3-0.6B, 40 960-token context) and comparing:llm.contextllm.spansllm.tokensllm.epoch_spansllm.epoch_tokensTwo conclusions, in the order they matter for L4:
#3170'skEpochTokenLimit = 8192is a property of the card format, not of this model, and a hybrid driver can rely on it while still reading the card for the context class.llm.epoch_spans/llm.epoch_tokensexist on the 27B card and are absent from the 0.6B one (they belong to the speculative/epoch machinery, not every composition). That matters for anything that enumerates configs — an exporter or a route table that assumed a fixed fourteen-key set would break on the smaller card, and it is the same "the artifact is per-card" lesson as thecontrol.loomline offsets.One precision note against my own merged wording:
#3170's header comment says the four epoch keys arerange 1..8192, which is exactly right for the 27B card it cites, but reads as if all four exist everywhere. They do not;llm.spans/llm.tokensare the two that do, and they are the two the constant is derived from. I am not pushing a commit for that — the PR has a READY at its head and a comment nit is not worth resetting it; it folds into the next push for a substantive reason.1 remaining item
bong-water-water-bong commentedon Nov 21, 2026
The epoch bound is per program family, and my merged constant overstates it — found by auditing the corpus against my own merged code
#3170mergedkEpochTokenLimit = 8192documented as "the per-epoch token ceiling the shipped cards declare". I checked that claim exhaustively rather than trusting the two cards I had sampled:All 55 agree on 8192 — that half is solid, and it is now a corpus-wide fact rather than a sample. But the four cards without
llm.loomare not all image models: two are (FLUX.2-klein-4B,Z-Image-Turbo), one is an upscaler (Real-ESRGAN-x4plus), and the fourth is Qwen3.8-Flash-Next — a text model we ship. Its epoch command declares its own key:32768 — four times the
llm.*bound, under a different prefix. So there are two shipped families (8192 and 32768), and the default in my header is only one of them. The failure is asymmetric, which is why it matters: a limit that is too small costs extra epochs and still produces correct positions, but one that is too large asks the program for more tokens in a single epoch than its own schema admits — the kind of thing that fails at a device boundary rather than in arithmetic.What the driver contract should say, now measured:
llm.*llm.tokens/llm.spansflash_next.token_countConsequence for the handover design rather than just the code: a full 262 144-token context is 32 epochs on an
llm.*card and 8 on Flash-Next. The epoch count is a property of the card, so the driver must take the limit from the card and treat any constant as a default — which is what the parameter already allows; the comment was what overreached.Patch is committed on a local branch (
cfd811c7e) and not pushed:kFlashNextEpochTokenLimit = 32768, four new arms (the bound, 8 epochs at full context, the base rule at the other family's limit, and coverage asserted at both shipped bounds), 37 arms green, gate green. Engine is at 4 open PRs, above the cap of 3, so it waits as a branch rather than adding queue load — it is one push whenever the count allows.The honest note: this is the check that should have preceded merging
#3170, and the same rule the lane has been applying to other lanes' citations all night — run the claim across the population, not on the two examples you happen to have.bong-water-water-bong commentedon Nov 21, 2026
The acceptance section's preconditions, collected from tonight's gate attempts — because L4's row inherits every one of them
This issue's gate clause says the comparison is "hybrid-NPU-prefill → Loom decode vs hybrid-NPU-prefill → our decoder". The first real attempts at the L2 row (#3158) showed that four things must be pinned before such a comparison means anything, and none of them is about kernels. Recording them here so L4's row does not re-learn them on a ticket:
enable_thinking/chat_template_kwargs/reasoning_effortper request (control.loom:39,46,736) and defaults tothinking_default: true, and it selects betweengeneration_thinkandgeneration_plainon that bit (@chat_end,:1016-1032). A silent request and an explicitfalseare different prompts — measured as 22 vs 24 tokens of opener on a five-word question. Both arms of an A/B must send the same value, and it must be recorded beside the result.usage.prompt_tokens; the two arms came back 20 and 23 where the card's own two paths are 22 and 24, so neither number is a path this card can build. That cannot be resolved from counts — the request body and the prompt token ids have to be logged. Any L4 row should carry them, because the hybrid's whole point is that the prefill is ours; if the prompt differs, the prefill is not the only variable.mtp.layers = [64]. A route that drafts caches one more KV layer — ~1.15 GiB more at 262 144 context — so the two arms must agree on drafting, or the memory difference is scoring the MTP head.context_capacity, a contiguous card costscapacity × 2048 × layersresident, while a paged one (Inkling) costs2 × pool × 2048 × layers. Recording only the capacity does not say which.None of these change this issue's design: the handover still writes the two state roots plus the control block, and the layout and driver are merged. They are the preconditions of the measurement, and the honest way to hold them is a short configuration record per row — prompt, thinking flag, drafting, cache kind, capacity class — next to the numbers, so a later reader can tell a route difference from a configuration difference.
I have no code to add for this: it is the gate's harness (L2) and L4's row, and both are measurements.
bong-water-water-bong commentedon Nov 21, 2026
L4 datum, device-free: the card the gate is currently measuring pages its KV, and the page map is per session row — so "hand over to Loom's KV format" is a write through an indirection, not a memcpy to an offset.
Read from
unsloth-Qwen3.8-27B-UD-Q4_K_XL(the card incl-hrxkern-row27b-ud-v5),program/llm.loom, symbol@g_kv_offset— header: "Paged KV: 2 planes per layer (layer-major, K then V); one position holds the KV heads x 128 F16 values in 16-position pages mapped per session row."Four things a zero-copy handover has to respect, and one contradiction worth fixing in the generator:
view<5xi64>field 4). The NPU-prefill writer therefore cannot compute a target address from(layer, position)alone — it needs the row that the Loom decoder will read, which is the session handle, not a global buffer. That is the first thing the L4 design has to own, and it is the same paged shape my predecessor found on Inkling, soapp/loom_kv_layout.h's contiguous arithmetic does not describe either card.prefill_capacityin the card's preset is 1024 = a whole number of 16-position pages, which looks deliberate.map[page] = pagewould make the first N pages linear, and if the allocator hands out sequential physical pages for a fresh row then a naive linear writer works for the first chunk and breaks later. That is measurable in one run under a gpu-hold ticket — dump the row's map after a small prefill and diff againstrange(blocks).The contradiction: the header comment says "KV heads x 128 F16 values", but
head_dimis 256 inllm_config.json(kv_heads4,hidden5120,layers64,context_length262144) and%position_bytes = 2048is exactly 4 x 256 x 2 B. So the comment's 128 is stale or means something else; the arithmetic is the authority, and a comment that disagrees with the stride below it is the kind of thing L4 will get wrong at 2 a.m. Worth a line ingen_llm.py's template rather than in this card.What this does not need: no GPU time to read, no card build, no L2 numbers. It is a fact about the target format, and it is the one thing L4's design was missing a citation for.
bong-water-water-bong commentedon Nov 21, 2026
L4 decision, from the pinned source: Loom at
0cd370f2bahas no way to accept externally computed KV state, so "NPU prefill → Loom decode KV handover" cannot be a copy into Loom's pages. Here is what it does expose, and the three shapes the handover can take — one of which I recommend.What Loom's retained-state surface actually is
From
loom/docs/src/serving/http-profiles.mdat the pin, not from assumption:POST /v1/sequencessession,position,next_position,token_idsand base64datawhose "shape, dtype, and interpretation belong to the model package"POST /v1/checkpoints/NAMEwithX-Loom-SessionPOST /v1/checkpoints/NAME/suspendhost_snapshot_bytesDELETE /v1/checkpoints/NAMEPOST /v1/models/pin/unpinpositionor concurrent use → 409, evicted handle → 404; handles are not durable across registration replacement or restartAnd the part that decides the design: every one of those writes state through Loom's own execution.
/v1/sequencesre-runs the tokens; checkpoints pin or move what Loom itself computed;suspendwrites a process-local host image, not a file or durable disk cache. There is no import/export of KV bytes, no way to hand Loom a page map, and no endpoint that accepts activations. The paged layout I documented earlier (@g_kv_offset: per-row page map, 16-position pages, 2048 B per position per plane) is reachable only from inside the card's program.The three shapes, and the one I am choosing
/v1/sequences, then decode in Loom. Supported, no reverse engineering, and the KV never leaves Loom's allocator — but it recomputes the prefill inside Loom, so the thing L4 exists to save (GPU prefill time) is not saved. It is a correctness-safe baseline, not the feature.plane_slot * 2048through the row's page map. That is what "zero-copy handover" literally means, and it is the shape the direction's wording implies — but it means writing into another process's device buffers through an undocumented layout, i.e. it needs a Loom feature (page-map reservation plus a KV import path) that does not exist at this pin, and it would break the moment the card's program changes.I am choosing (1) as the first L4 milestone and (3) as the release shape until (2) exists as a Loom feature, and the reason is the same one the direction gives for gating a model before switching: shape (2) would be an unmeasured assumption about a layout owned by another process, and (1) gives a number to compare against (3) with no new device-side code — replay cost versus our own prefill cost, on the same 27B card, under the same gate.
What that means for the issue's remaining work, stated so nobody re-derives it:
/v1/sequencessession →POST /v1/checkpoints/NAMEpin → decode in Loom, with the row's accuracy half measured by tools: logprob_agree answers greedy agreement on generated text, the half a Loom arm can answer (engine#3158) #3231/tools: logprob_agree matches on the key both routes have, never an id against a token (engine#3158) #3241 as usual;map[page] == pagefor a fresh row) only matters for shape (2), so it is not on the critical path any more — which is itself worth knowing before anyone spends a window on it.Verified device-free from the pin; no ticket taken, and
row27b-ud-v8is running in the GPU queue where it should be.bong-water-water-bong commentedon Nov 21, 2026
Following the shape-1 decision: a runnable probe for it, so the L4 window measures something specific.
~/.cache/scratch-cl-hrxnan/acc/l4-seq-probe.sh(bash -nclean, not yet run — the device is L2's tonight):Four steps, each echoing its HTTP status so a refusal is read as a refusal rather than as a shape mismatch:
POST /v1/sequenceswith{"model":…, "position":0, "token_ids":[...], "options":{}}— the prefill as exact known IDs, no tokeniser, no chat template between our prefill and Loom's state. Reads theattachedevent'ssessionand the lastposition.POST /v1/checkpoints/l4-prefillwithX-Loom-Session+X-Loom-Model— pins the completed session, which is the handover seam proper: the state stays Loom's, addressed by its handle.finish_reason/ usage, and names the number to compare: step 1's wall time.Two things this deliberately does not do, because they are the assumptions shape 1 exists to avoid:
If step 1 answers 400, the field set is wrong for this deployment's
kind:"sequence"package and that is the finding; if step 2 answers 404/409, the pin is unavailable (nocheckpoint_capacity, or the session is not idle/completed), which would push the first milestone to "replay then decode in one long request" — still shape 1, still measurable.acc-ticket.shand this probe are both on disk, unqueued. When an L4 window is mine rather than L2's, this is the command that runs.bong-water-water-bong commentedon Nov 22, 2026
cl-game state, 22 Nov 01:0xZ (tonight's row: keep, no new scope). On
mainnow:3f131a5(#3262) landed the proxy status pass — shape decided from complete lines (loom_stream_shape) with upstream cancellation through a sharedClient::stop(); #3254 and #3263 are closed on measured evidence; #3264 closed as superseded (it extended a function #3262 deleted); #3269 open (undrafted, build pending) bounds the non-stream body wait that #3262 left unbounded — 70.0 s of silence → 504 at 60.0 s, stub-measured. No new scope from me tonight: this issue is coverage/handover, and the only concrete artifact still missing is atests/loom_route.shrow with a stalling fake upstream, which I would take after the c34 cut rather than widen tonight's window.bong-water-water-bong commentedon Nov 22, 2026
L4 shape 1, measured on the appliance against the pinned loom-serve (hrx-loom 0.2.0 / hrx-system 0cd370f2ba). strixhalo gfx1151, Qwen3-0.6B card (
unsloth-Qwen3-0.6B-loom, GGUF ac2d9771), underbox-hold gpu sudo -n, with every child killed on exit. Lemond and the NPU proxy were not touched.1.
/v1/sequencesdoes not exist for generative models at the pin. The probe as written (l4-seq-probe.sh: replay exact IDs through/v1/sequences) gets404 NOT_FOUND: use the model's declared endpoint or /v1/checkpoints/NAME; generative models also support /v1/chat/completions/input_tokens(6/6 attempts, 16 and 768 ids). The pinned source confirms it is by design:service/text/service.c:247-251accepts/v1/sequencesonly in ENCODE mode. A Loom chat model at the pin accepts no raw token IDs over HTTP. Shape 1 therefore has to replay the prompt as text (chat messages) inside anX-Loom-Session, pin it with a named checkpoint, and decode from that.2. That works, with two conditions.
checkpoint_capacity > 0. The card's default is 0, so the first pin returns503 checkpoint capacity exhausted. I used a copy of the card whose only change ispresets.chat.execution.checkpoint_capacity = 2; the original card is untouched."<think>\n\n</think>\n\n" + reply). Resending the same prompt, or the reply without that block, gets400 request history does not extend the named checkpoint(2×2 attempts each). Qwen3's template drops an empty think block from past assistant turns, so a proxy that rebuilds history the ordinary way will always miss the checkpoint.3. Numbers (2 reps each, thinking off, temperature 0, 16 decode tokens; ms are client wall time over loopback):
1bit serve/apply-template+/tokenizeon the same GGUF; "Loom" is/v1/chat/completions/input_tokens. They match in count. That is evidence, not proof, of identical IDs: the pin exposes no ID dump.What this means for the shape decision: the replay cost shape 1 pays is a full Loom re-prefill. For the 0.6B model that is about 64 ms per 780 tokens; it has to be measured per model before comparing against shape 3. The handover seam is a named checkpoint addressed by session, not our bytes. Our proxy has to (a) set
checkpoint_capacityin the cards it routes, (b) keep the assistant transcript verbatim, think block included, and (c) release pins (DELETE /v1/checkpoints/NAME→ 200; capacity is a hard limit).Not measured: an actual NPU prefill feeding this (this is the Loom half only), bigger models, and concurrency. Scripts:
/data/dev/cl-loom/l4run.sh+l4text-probe.sh; output/data/dev/cl-loom/out/l4-*.bong-water-water-bong commentedon Nov 22, 2026
L4: how much a Loom prefill costs, measured, and what that means for the handover shape.
Setup: strixhalo gfx1151, the pinned loom-serve, run alone under
box-hold gpu(two tickets of ≤ 40 min).max_tokens: 1and thinking off.cached_tokens= 0 confirms nothing was reused.unsloth-Qwen3-0.6B-loom)qwen38-27b-ud)(Each number is the client wall time for prefill plus 1 token, over loopback.)
The 27B's 10.7k-token reps got slower each time (20.5 → 29.5 s), back to back in one ticket. I didn't record temperature in this probe, so I can't tell throttling from memory-pool growth. A gate speed row on long prompts should log Tctl per rep, as LOOM-GATE's speed form says.
What this means for the shape decision:
/v1/sequencesis encode-only, and checkpoints come from Loom's own prefill). So an NPU prefill in front of it adds its own time to these numbers and saves none. Shape 1 is only good for keeping a session addressable (named checkpoints), not for speed.--device hybrid, docs/hybrid.md), where the KV handoff exists. My recommendation for L4: park the NPU → Loom handover. File a Loom feature request for a state/KV import (for the owner to pass on, as these go upstream), and measure shape 3 when it exists.Not measured here: any NPU number (private), concurrency, or prompts past 10.7k tokens.
🤖 Generated with Claude Code
bong-water-water-bong commentedon Nov 23, 2026
#3157 re-scoped (orchestrator, owner-approved): NPU + GPU co-execution for Qwen3.8-27B prefill, against a public bar.
A public Strix Halo engine reports 1,335 tok/s prefill at 8K for this model: int4 × int4 dense projections on the GPU, plus the FFN split onto the NPU. Their number is a bar only; this is clean-room work. The GPU half is #3349 (cl-i679). This issue now carries the NPU half and how the two fit. It is not the sequential handover I parked above: that one can't help, because Loom re-prefills. This is concurrent work inside one prefill.
Our measured baseline at the bar's length (strixhalo gfx1151, one box-hold ticket stating 45 GB, one arm at a time):
max_tokens 1.1bit serve --device hrx --no-loom, engine e697c40)The arithmetic (the card's own geometry: qwen35, 64 layers, hidden 5120, FFN 17408):
r·f = P_npu / (P_gpu + P_npu), and speedup = (P_gpu + P_npu) / P_gpu, minus a per-layer handoff/sync cost.Where the split can live (checked at the pinned hrx-loom 0.2.0 / hrx-system 0cd370f2ba):
xdna://0, but one model's programs are not split across GPU + NPU (loom/docs/src/serving/index.md). The XDNA target compiles resident pipelines (its example: a BF16 gate/up projection, not a full FFN). This needs multi-device placement inside one deployment, a feature request for the owner to pass upstream.llama-npu-server, an NPU ggml backend for weight MUL_MATs) is the building block. Today it is CPU-only and whole-op, so it would need to be registered alongside HRX in one process.Who measures what:
P_gpufor the int4 projections at 8K.P_npufor an FFN GEMM at M = 8192, K = 5120, N = 17408, while the GPU is busy. Only the ratio needs to be public.Separately, any measurement through
1bit serve's Loom route needs #3346. Without it every request over ~1 KB was a 502; verified fixed on this box (2,395-token prompt: 580 tok/s prefill through the route).🤖 Generated with Claude Code
docs: retire the NPU-prefill -> Loom-decode KV handover - Loom re-pre…
docs: retire the NPU-prefill -> Loom-decode KV handover - Loom re-pre…
bong-water-water-bong commentedon Nov 24, 2026
Merged: #3464 (
396f60f1) retires the design in the four docs that still sold it, and adds the canonicalentry to KNOWN-ISSUES.md — including the two measurements that closed it (the pinned loom-serve's text service
accepts a generative prompt only as chat text, so a prefilled KV cannot be delivered; and the co-execution re-scope's
GPU half #3349 closed NOT_PLANNED on its KLD miss).
Closing this not planned / retired: the design question is answered, the docs no longer promise it, and the
record a reader needs is the
engine#3157entry in KNOWN-ISSUES.md. What a future hybrid would need before it can bedesigned again is written there too (a Loom API that imports externally computed KV/state, and a measured NPU prefill
rate at the bar's length while the GPU runs). This thread stays readable as the history.
loom: a deepseek2 checkpoint had no recorded port path - the private …
loom: a deepseek2 checkpoint had no recorded port path - the private …