Skip to content

loom: the hybrid route's NPU prefill -> Loom decode KV handover (L4 design: two caller-owned state roots, f16 attention cache + f32 GDN state) #3157

Done

Description

@bong-water-water-bong

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)

  1. 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 fails Populate ranges failed, ret -14 and poisons every later submission in the process). Today the decoder exports and the provider imports; the same shape holds with the roles unchanged — Loom allocates attn_cache and gdn_state, exports fds, our NPU prefill imports and writes them.
  2. 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 per gdn_ordinal, f32, 256-aligned blocks. No intermediate buffer, no repack pass — that is the zero-copy requirement, not an optimisation.
  3. Capacity is agreed before materialization. cache_capacity specializes Loom's command buffers, so the route must fix it (a context-size class) before the first decode is materialized, and the exporter allocates exactly 2 × align256(capacity × 2048) per attention ordinal. A capacity that changes per request means re-materializing; that is a cost to measure, not to assume.
  4. Position advance via %control is the one interface we do not control yet (see below).
  5. 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

  1. %control's layout: not in the .loom. Either Loom produces it (a zero-token "epoch" prefill that only establishes position/length — epoch.loom suggests 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.
  2. Who owns cache_capacity when 1bit serve picks 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.
  3. MTP/dflash: the composition has dflash*.loom and mtp.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.
  4. 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/%rows state), 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

  1. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    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:

    :46   command.def public … @qwen38_attention_layer_decode(%layer, %attention_ordinal) launch(%parameters, %residual, %control, %attention_cache, %attention_output)
    :49     %control_position_index = index.constant 0 : index
    :39   command.decl @qwen38_dispatch_attention_decode_split_partial(%token_count, %token_ordinal, %control_position_index) launch(%control, %query, %key_cache, %value_cache, %partials)
    :122    command.launch @…[%token_count, %token_ordinal, %control_position_index](%control, %query, %key_cache, %value_cache, %attention_decode_partials)
    

    So the parameter the cache walk advances by is a command-list parameter, materialized as a constant 0 in 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. %control is 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:

    program/text/qwen3_8/epoch.loom:192   func.def public @text_encode_epoch_v1(%control_state: buffer, %plan: buffer, %inputs: buffer, %media_plan: buffer,
                                            %first_count: i32, %next_count: i32, %input_count: i32, …, %eos: i32, %metadata: buffer, %tokens: buffer)
                                            -> (i32, buffer, i64, i64)
    :268   %state_bytes = buffer.length %control_state
    :273   func.return %outputs, %control_state, %transfer_begin, %transfer_length : i32, buffer, i64, i64
    

    %control_state is caller-owned, passed in and back out, with a buffer.length the 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 with first_count = N and zero next_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 a gpu-hold ticket 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%).

    recurrent_state_bytes = 3,145,728   (786,432 f32)      ← the number the body uses as "per layer"
    conv_history_bytes    =   122,880   ( 30,720 f32)
    gdn_layer_state_bytes = 3,268,608   (both 256-aligned, buffer.pack)
    

    3,268,608 is what %layer_state_offset = gdn_ordinal * gdn_layer_state_bytes strides by, and the proposal's own item 2 lists both blocks ("GDN recurrent + conv history per gdn_ordinal"). So 3,145,728 is the recurrent part only:

    48 layers × 3,145,728 × 4 passes = 604.0 MB     ← matches docs/zero-copy.md:197 as quoted
    48 layers × 3,268,608 × 4 passes = 627.6 MB     ← same shape, Loom's per-layer state
    

    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_capacity ownership) 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 %control field.

  2. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Open question 1 is answered from the library: %control is a struct we write, not an API to negotiate

    Read at hrx-loom-library ba7abef, 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:

    kernel/attention_decode.loom:104   %position_i32 = view.load %control_view[0] : view<1xi32> -> i32
    kernel/attention_decode.loom:108   %token_cache_base = index.mul %position, %c1024
    kernel/attention_decode.loom:148   %position_i32 = view.load %control_view[0] : view<1xi32> -> i32
    kernel/attention_decode.loom:151   %context_count  = %position + 1
    

    %control is therefore the sequence packet, and its arithmetic is the function bodies in motif/sequence/qwen3_8/packet.loom (packet_bytes = 40 + 112·capacity, two 16 + 36·capacity banks, 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:

    word decode form (decode_control.loom:17-19) prefill form (decode_control.loom:49-51)
    0 position token_count
    1 generated_count position_base
    2 eos_token eos_token

    qwen38_prefill_finish_control is the converter: it loads [token_count, position_base, eos] and stores [position_base + token_count, 1] (:54-59, fixtures at test/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.loom was the right hunch. qwen38_prefill_finish_control loads token_count with no range assumption, so token_count = 0 is legal and stores position := position_base, generated_count := 1 without touching a cache byte. Every public prefill command is stricter — range 1..512 in epoch.loom:10, model_prefill.loom text_prefill_chunk/_transition — so no command is zero-length, and that kernel is the library's only zero-length path. Meanwhile qwen38_continue_spans assumes its plan count as range(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:

    • to hand over a prefill Loom itself ran: leave control = [N, base, eos] and let prefill_finish convert it;
    • to hand over a prefill we filled ourselves: write the decode form directly, control = [base + N, 1, eos], where base + N is the absolute index of the next token (context_count = position + 1 is what the decode attention attends over, so this is the whole prompt by construction).

    Consequences for the other questions

    • Q4 (is Loom's prefill optional): yes for the state, and the interface is small. @qwen38_text_decode_greedy takes %control and calls output_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/policies regions, at the offsets in the table above.
    • Q3 is unaffected: mtp.loom/dflash* keep their own drafts; the handover boundary above does not move.
    • A caveat worth carrying into the writer, because it is silent when wrong: word 2 is eos_token to the commit kernels but the live row count to the samplers (kernel/sampling.loom:45,92) and kernel/output_spans.loom:35, and nothing in the sampled path writes that count. An eos id smaller than the row count would drop rows without an error. The writer owns which meaning is in place.

    Status

    #3159 now carries this as arithmetic as well as prose: the header offsets, both ABIs, the packet geometry and packet_capacity(bytes), with the geometry checked against two independent artifacts rather than restated — packet.loom's function bodies and test/sampling_test.loom's own hardcoded literals (policy origin 9760 = 32 + 128·76, identity origin 12832 = 32 + 128·100, and a tensor<3594xi32> epoch = 3594 · 4 = 40 + 112·128 bytes 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.

  3. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    @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:49 materializes %control_position_index = index.constant 0 and :122 passes it into @qwen38_dispatch_attention_decode_split_partial, which is exactly kernel/attention_decode.loom:104 using it to select control[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_v1 is real, and next_count = 0 is first-class — but it is the planner layer, not a token-consuming pass. program/text/qwen3_8/epoch.loom:192 takes %control_state and %metadata as separate buffers, and %control_state is a 14×5 i64 transfer table (epoch_transfers, :567-640: metadata/input/word/pair/header/descriptor/record slot 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 eos meaning belongs to the decode-only %control. In the text composition the two roles live in two buffers (%control_state vs %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:10 and every model_prefill.loom entry are range 1..512, with prefill_finish_control as the only zero-length kernel); at the planner level next_count = 0 is 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. #3159 at afdcbb2ec carries 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 gap 192 × 122 880 = 23 592 960 as the conv history. That also corrected a number in this thread from another lane: 627 498 240 is 74 496 low, which is why the test asserts the computed literal rather than the quoted one.

  4. added
    enhancement
    rfc
    on Nov 21, 2026
  5. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Correction to this issue's own premise, from the #3159 review: 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), so range(%attention_ordinal, 0, 15) admits 0..15 and range(%gdn_ordinal, 0, 47) admits 0..47. The composition agrees: model_decode.loom:26-27 unrolls 16 groups of 3 GDN + 1 attention, :48-50 launches GDN ordinals 3*group + {0,1,2} (group 15 → ordinal 47) and :54 launches 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. #3159 now 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).

  6. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    L4 re-check at cb9ae9e: the reading holds, and one part of my own answer is now out of date

    Diffed 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:

    claim at cb9ae9e
    cache_capacity specialization attention_layer_decode.loom:74, range(1, 262144)
    %cache_token_bytes = 2048 :75 — unchanged
    buffer.pack [align(256) …, align(256) …] :77 — unchanged
    token-major key/value views :82-83 — unchanged
    GDN 3145728 / 122880 + pack gdn_layer_decode.loom:69-71 — unchanged
    sampling fixture literals (9760 / 12832 / 3594 words) identical, so the two-artifact agreement on the packet geometry survives the refresh

    The part that changed: the packet's word 2 has a writer now

    At ba7abef I 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.loom gained @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 it range(0, capacity)), and kernel/sampling.loom gained a %first argument so the samplers test first + 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:

    • decode control block — [position, generated_count, eos], convertable from [token_count, position_base, eos] by prefill_finish_control (unchanged at decode_control.loom:17-19, 49-51, 54-59);
    • sequence packet — [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 eos id smaller than the output count drops sampling rows with no error). #3159 is updated at 9dda95b78 with 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 = 2048 is 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: 262144 is exactly the cache_capacity specialization's upper bound, i.e. the card can be materialized at full context — which is the constraint Q2 has to fit 1bit serve's context choice into.

    Checked and out of scope

    @qwen38_proposal_origin_bytes (new, 12 × capacity) is consumed by mtp.loom / Qwen3.8-Flash-Next/program/propose.loom — the draft side, not part of packet_bytes, so the exporter's allocation for the handover is unchanged. continue.loom gained a %feedback_capacity config argument; the packet capacity range is still range(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.

  7. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    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.json gives hrx_loom 0.2.0 from PyPI with hrx_system v0.2.0, and its version.json names model-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 of v0.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:

    claim at v0.2.0
    cache_capacity specialization range(1, 262144) attention_layer_decode.loom:15
    %key_value_size = 1024, %cache_token_bytes = 2048 :52, :75
    align-256 key/value pack :77
    GDN 3145728 / 122880 + pack gdn_layer_decode.loom:69-71
    ordinals range(…,0,15) / range(…,0,47) → 16 / 48 unchanged
    packet origins 32+{72,76,100,108,112}C, bank 16+36C, packet_bytes = 40+112C packet.loom:35-76, :82
    fixture literals 9760 / 12832 / tensor<3594xi32> identical

    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 %control answer, and it is the opposite of what I said this morning. At v0.2.0 there is no qwen38_packet_compact_prefix and the samplers have no %first window: sampling.loom:45,92 read 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 absolute first + row bound 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. #3159 is updated at 4742be14f to state both revisions side by side, with v0.2.0 as the primary pin.

  8. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Open question 2 is answered, empirically, and not the way I assumed. It asked who owns cache_capacity when 1bit serve picks the route. The answer is different for the two roots, and I had it wrong for the packet in #3159 until this turn.

    The packet's capacity is caller-owned, not a specialization. The encode step infers it from the allocation it is handed:

    program/text/qwen3_8/epoch.loom:91-92   %metadata_bytes = buffer.length %metadata
                                            %capacity = @qwen38_packet_capacity(%metadata_bytes)
    

    and the shipped card's own encoder bounds it at range(%packet_capacity, 1, 524288) (control.loom:2519,2551,3215 in the Qwen3.8-27B card), tighter than the motif's range(2, 2147483646), multiple_of(2). So the ceiling is 524288, and the largest packet an exporter budgets is 40 + 112 × 524288 = 58 720 296 B (~56 MiB).

    The attention cache is the opposite, and the card does not pin it: cache_capacity is a config.decl specialization in the model program, while the card's model.json variant config carries only llm.card / llm.logits and cache_capacity appears 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-SWITCH condition 2 already requires for the runtime), while packet size may vary without invalidating the comparison.

    Landed as code and arms in #3159 at 155febd47 (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.

  9. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Correction to my pin comment above: v0.2.0 and HEAD have not diverged — the tag is 85 commits behind HEAD on a straight line.

    $ git merge-base --is-ancestor 1fd6bd23 cb9ae9e → rc 0   (v0.2.0 IS an ancestor of HEAD)
    $ git rev-list --count 1fd6bd23..cb9ae9e        → 85
    

    I had tested only the other direction (cb9ae9e is not an ancestor of 1fd6bd23), seen rc 1, and written "the lines diverged" in #3159 and in the comment above. The tag is a subset of HEAD, so the 27B program diff I quoted (~2.9k insertions 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:

    • the layout arithmetic is identical at the tag and at HEAD (16 attention / 48 GDN, 2048 B/token, 3145728+122880 per GDN ordinal, 40+112C packet, the eight origins) — verified at 1fd6bd23 directly;
    • the packet word-2 contract differs between the two: at v0.2.0 nothing writes the epoch header and the count is caller-owned; at HEAD qwen38_packet_compact_prefix writes [token_count, span_count, output_count] and the samplers bound on first + row. That is a real difference across the 85 commits, not a branch divergence.
    • the capacity ownership answer (my previous comment) is unaffected: the packet's capacity is inferred from the caller's allocation (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 #3159 at 928dc00d5, where the paragraph now says "the tag is a subset of HEAD, 85 commits back" and gives the count.

  10. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    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:

    • logits are a compile/link-time config (loom-link --config=llm.logits=true, with llm.logit_slots), not a serve-time flag: loom-serve --help has zero logits flags and no --config surface at all, and neither loom-benchmark nor loom-check mentions logits;
    • 55 of 59 cards declare llm.logits and all 55 are false (the other 4 default off), including both 27B cards, whose variant config is {"llm.card": true, "llm.logits": false};
    • the program's tail is guarded by config.get @llm.logits (documented in loom-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-hold ticket 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.

  11. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    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.loom in the shipped card declares func.decl import("prepare") @source_scope(%scope: buffer) and passes the key names as string literals through it:

    llm.context   llm.spans   llm.tokens   llm.pool   llm.width
    llm.epoch_spans   llm.epoch_tokens   llm.logit_slots   llm.prep_{blocks,input,skip,split}
    

    Measured, not assumed: linking the card's llm.loom on 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:

    1. L1's route table sets the shape class as config keys, not by re-materializing. llm.context/llm.epoch_spans/llm.epoch_tokens/llm.spans/llm.tokens/llm.pool are 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.
    2. My "specialization vs inferred" split needs one qualifier: the library's cache_capacity is a config.decl specialization and the card's epoch shapes are config.decl keys — 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, one gpu-hold ticket, and it decides how much of L1's route table is dynamic.
    3. The KLD arm and the shape class are the same surface. llm.logits is one of these host-scope keys, sitting in // logits:begin/// logits:end marker 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; #3159 is unchanged at 078c8ccd3 with two READYs at head.

  12. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    A hard epoch bound for the handover, read from the card's config contract

    loom-link --print-config-schema <card>/program/llm.loom prints 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:

    llm.context         required  range 16 … 262144     ← the capacity class (what a preset sets)
    llm.spans           required  range  1 … 8192       ← spans per epoch
    llm.tokens          required  range  1 … 8192       ← tokens per epoch
    llm.epoch_spans     required  range  1 … 8192
    llm.epoch_tokens    required  range  1 … 8192
    

    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:

    1. The handover is not one write, it is a sequence of epoch-sized writes. A hybrid prefill of N tokens must be chunked at ≤8192 per epoch, and each epoch's KV lands at its own absolute positions. That is exactly the case my header's token-major indexing handles (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.
    2. It is the same pattern as the packet ceiling I already recorded: the card is tighter than the library. The library's packet.loom:96 allows 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 #3159 now measures at the card's tag rather than at HEAD.
    3. It fixes the gate's shape. An accuracy row at 262144 context is a 32-epoch run on the Loom arm; a row at 8192 is one epoch. Those are not the same experiment, and a KLD comparison must state how many epochs the prompt spans — otherwise "Loom at 8k vs fallback at 8k" and "Loom at 262k vs fallback at 8k" would be reported as the same row.

    Not verified: whether llm.tokens/llm.spans are per-epoch or per-request bounds in loom-serve's own bookkeeping — the schema gives ranges, not semantics, and the card's prepare.loom passes 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/ has chat-8k and chat-logits ready for it), so I am not spending a ticket on it separately from L2's queued 27B row.

  13. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The epoch bound is model-size-independent; the config set is not — measured on two cards

    I checked whether the 8192-token epoch ceiling #3170 encodes is a property of one model or of the card format, by running loom-link --print-config-schema on a second, much smaller card (Qwen3-0.6B, 40 960-token context) and comparing:

    key Qwen3.8-27B card Qwen3-0.6B card
    llm.context 16 … 262144 16 … 262144
    llm.spans 1 … 8192 1 … 8192
    llm.tokens 1 … 8192 1 … 8192
    llm.epoch_spans 1 … 8192 absent
    llm.epoch_tokens 1 … 8192 absent

    Two conclusions, in the order they matter for L4:

    1. The per-epoch ceiling is 8192 regardless of model size — a 0.6B card and a 27B card agree, and the context bound is identical too (both list 262144, even though the 0.6B card's own preset is 40 960). So #3170's kEpochTokenLimit = 8192 is 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.
    2. The config set is not uniform: llm.epoch_spans / llm.epoch_tokens exist 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 the control.loom line offsets.

    One precision note against my own merged wording: #3170's header comment says the four epoch keys are range 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.tokens are 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.

  14. 1 remaining item

  15. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The epoch bound is per program family, and my merged constant overstates it — found by auditing the corpus against my own merged code

    #3170 merged kEpochTokenLimit = 8192 documented as "the per-epoch token ceiling the shipped cards declare". I checked that claim exhaustively rather than trusting the two cards I had sampled:

    $ python3 epochaudit.py          # loom-link --print-config-schema over every card
    cards with a program/llm.loom: 55   without: 4   failures: 0
      llm.tokens   upper=(1, 8192)  cards=55
      llm.spans    upper=(1, 8192)  cards=55
    

    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.loom are 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:

    program/epoch.loom:11   config.decl @flash_next.token_count : %value: index where [range(%value, 1, 32768)]
    program/epoch.loom:34     %tokens = config.get @flash_next.token_count : index
    

    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:

    family key bound cards
    llm.* llm.tokens / llm.spans 8192 55 of 59
    Flash-Next flash_next.token_count 32768 1 (text)

    Consequence 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.

  16. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    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:

    1. The thinking flag, per arm. The card takes enable_thinking / chat_template_kwargs / reasoning_effort per request (control.loom:39,46,736) and defaults to thinking_default: true, and it selects between generation_think and generation_plain on that bit (@chat_end, :1016-1032). A silent request and an explicit false are 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.
    2. The prompt itself, not just its length. The current row reports 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.
    3. Whether the MTP layer's KV is cached. Verified earlier in Loom route gate: gated A/B (Loom vs fallback) per shipped model, with the accuracy gate #3158: 64 target layers = 48 recurrent + 16 KV, and the checkpoint's 65th block is 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.
    4. Contiguous versus paged KV. For the same context_capacity, a contiguous card costs capacity × 2048 × layers resident, while a paged one (Inkling) costs 2 × 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.

  17. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    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 in cl-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."

    %record_stride     = 40                      // per-row record
    %records           = view<5xi64>             // field [4] = the page-map origin for THIS row
    %position_bytes    = 2048                    // bytes per (plane, slot)
    %page_value        = position / 16           // 16-position pages
    %physical          = map[page]               // map: view<[%blocks]xi32>, per row
    %page_base         = physical * 16
    %slot              = page_base + position % 16
    %plane_slot        = plane * pool + slot
    offset             = plane_slot * 2048
    

    Four things a zero-copy handover has to respect, and one contradiction worth fixing in the generator:

    1. The map is per row, not per model. The page map's origin is loaded from the row's own 40-byte record (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, so app/loom_kv_layout.h's contiguous arithmetic does not describe either card.
    2. 2048 bytes per position per plane, two planes per layer, layer-major — so 256 KiB per token across all 64 layers for K+V (2 × 2048 × 64), and 4 MiB per 16-token chunk. A 1024-token prefill chunk is 256 MiB of KV: that is the size of the zero-copy window the handover needs, and it is worth knowing before designing anything that stages it.
    3. A position is only addressable page-aligned per 16, so a handover that writes a partial page has to either own the page (write all 16 positions) or read-modify-write. prefill_capacity in the card's preset is 1024 = a whole number of 16-position pages, which looks deliberate.
    4. Whether the first chunk is contiguous is an empirical question, not a design one: map[page] = page would 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 against range(blocks).

    The contradiction: the header comment says "KV heads x 128 F16 values", but head_dim is 256 in llm_config.json (kv_heads 4, hidden 5120, layers 64, context_length 262144) and %position_bytes = 2048 is 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 in gen_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.

  18. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    L4 decision, from the pinned source: Loom at 0cd370f2ba has 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.md at the pin, not from assumption:

    surface what it lets a caller do
    POST /v1/sequences append exact known token IDs to a server-side session; SSE chunks return session, position, next_position, token_ids and base64 data whose "shape, dtype, and interpretation belong to the model package"
    POST /v1/checkpoints/NAME with X-Loom-Session pin an idle completed session; 201 reports the consumed token position
    POST /v1/checkpoints/NAME/suspend park the endpoint in host memory (elastic backing only); 200 reports host_snapshot_bytes
    DELETE /v1/checkpoints/NAME release the pin
    POST /v1/models/pin / unpin parameter eviction policy, not state
    stale/forked sessions a stale position or concurrent use → 409, evicted handle → 404; handles are not durable across registration replacement or restart

    And the part that decides the design: every one of those writes state through Loom's own execution. /v1/sequences re-runs the tokens; checkpoints pin or move what Loom itself computed; suspend writes 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

    1. Replay the prefill as token IDs through /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.
    2. Write into Loom's KV pages from the NPU, placing bytes at plane_slot * 2048 through 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.
    3. Keep the handover inside our own side: the NPU produces the prefill and our decoder consumes it (today's route), and Loom is used for models with no NPU path. This is the only shape that is implementable tonight, and it is what the current tree already does.

    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:

    Verified device-free from the pin; no ticket taken, and row27b-ud-v8 is running in the GPU queue where it should be.

  19. bong-water-water-bong commented on Nov 21, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    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 -n clean, not yet run — the device is L2's tonight):

    l4-seq-probe.sh <base-url> <token-id,token-id,...> [decode-tokens]
    

    Four steps, each echoing its HTTP status so a refusal is read as a refusal rather than as a shape mismatch:

    1. POST /v1/sequences with {"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 the attached event's session and the last position.
    2. POST /v1/checkpoints/l4-prefill with X-Loom-Session + X-Loom-Model — pins the completed session, which is the handover seam proper: the state stays Loom's, addressed by its handle.
    3. a completion carrying the same two headers, extending the canonical transcript — the decode from the pinned endpoint.
    4. prints content / 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:

    • it does not touch KV bytes or the page map (that is shape 2, which needs a Loom feature that does not exist at the pin);
    • it does not claim the prefill is transferred — Loom recomputes it from the IDs, so the honest comparison is replay cost vs our own prefill cost on the same card, which is a number the gate can hold (§ condition 2's perf half) rather than a design argument.

    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 (no checkpoint_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.sh and this probe are both on disk, unqueued. When an L4 window is mine rather than L2's, this is the command that runs.

  20. bong-water-water-bong commented on Nov 22, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    cl-game state, 22 Nov 01:0xZ (tonight's row: keep, no new scope). On main now: 3f131a5 (#3262) landed the proxy status pass — shape decided from complete lines (loom_stream_shape) with upstream cancellation through a shared Client::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 a tests/loom_route.sh row with a stalling fake upstream, which I would take after the c34 cut rather than widen tonight's window.

  21. bong-water-water-bong commented on Nov 22, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    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), under box-hold gpu sudo -n, with every child killed on exit. Lemond and the NPU proxy were not touched.

    1. /v1/sequences does not exist for generative models at the pin. The probe as written (l4-seq-probe.sh: replay exact IDs through /v1/sequences) gets 404 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-251 accepts /v1/sequences only 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 an X-Loom-Session, pin it with a named checkpoint, and decode from that.

    2. That works, with two conditions.

    • The deployment needs checkpoint_capacity > 0. The card's default is 0, so the first pin returns 503 checkpoint capacity exhausted. I used a copy of the card whose only change is presets.chat.execution.checkpoint_capacity = 2; the original card is untouched.
    • The continuation must extend the canonical transcript byte-exactly. With thinking off, the history's assistant turn has to carry the literal empty think block ("<think>\n\n</think>\n\n" + reply). Resending the same prompt, or the reply without that block, gets 400 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):

    prompt ours vs Loom prompt tokens replay (prefill + 1 tok) pin continue from checkpoint same history, fresh session
    short 28 / 28 22–50 ms 201 at position 28, 25–29 ms 47–49 ms, cached 28 of 45 48–53 ms, cached 0
    long 780 / 780 62–65 ms 201 at position 780, 20–29 ms 71–74 ms, cached 780 of 797 113–120 ms, cached 0
    • "ours" is our CPU 1bit serve /apply-template + /tokenize on 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.
    • The checkpoint continuation produced the same text as the fresh-session control ("The animal that jumps is the fox." / "Strix Halo pairs a large iGPU with an XDNA2 NPU and").

    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_capacity in 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-*.

  22. bong-water-water-bong commented on Nov 22, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    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).

    • Each prompt is chat-templated, with max_tokens: 1 and thinking off.
    • Every rep is a distinct prompt (unique prefix), and cached_tokens = 0 confirms nothing was reused.
    • One warm-up request is discarded, because the first request loads the weights.
    card ~700 tok ~2.7k tok ~10.7k tok
    Qwen3-0.6B (unsloth-Qwen3-0.6B-loom) 13.5–15.2k tok/s (46–52 ms) 12.8–13.7k tok/s (197–210 ms) 8.1–8.3k tok/s (1.29–1.31 s)
    Qwen3.8-27B UD-Q4_K_XL (qwen38-27b-ud) 554–576 tok/s (1.21–1.26 s) 487–514 tok/s (5.25–5.54 s) 520 → 421 → 362 tok/s (20.5 → 25.4 → 29.5 s)

    (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:

    1. Shape 1 cannot speed anything up with Loom as the decoder. The pinned loom-serve takes a chat model's prompt only as text and re-prefills all of it (see the comment above: /v1/sequences is 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.
    2. A hybrid NPU-prefill → Loom-decode route only pays off with shape 3, a KV/state import, and the pinned loom-serve has no HTTP surface for that in generative models. The bar a shape-3 import has to beat is the table above: on the 27B, about 500 tok/s of Loom prefill, which is about 20 s for a 10k-token prompt.
    3. Until Loom gets such an import, the hybrid route stays on the llama.cpp decoder (--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

  23. bong-water-water-bong commented on Nov 23, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    #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):

    • Qwen3.8-27B UD-Q4_K_XL, 8,205 prompt tokens, 3 distinct prompts per arm (no prefix reuse), max_tokens 1.
    • Tctl stayed at 64–65 °C, so no throttling.
    arm prefill tok/s (3 reps)
    fallback (shipped 1bit serve --device hrx --no-loom, engine e697c40) 396 / 446 / 451
    Loom raw (card quick-start flags, pinned loom-serve) 537 / 524 / 524
    the bar 1,335

    The arithmetic (the card's own geometry: qwen35, 64 layers, hidden 5120, FFN 17408):

    • FFN (gate + up + down) is ~70 % of ~50 GFLOP per prompt token; attention/GDN projections are ~28 %, attention scores at 8K ~3 %.
    • The bar is ≈ 67 TFLOP/s effective; Loom today is ≈ 26.
    • If the NPU takes a share of the FFN concurrently, they balance at r·f = P_npu / (P_gpu + P_npu), and speedup = (P_gpu + P_npu) / P_gpu, minus a per-layer handoff/sync cost.
    • So the NPU's contribution is bounded by its FFN-GEMM rate measured while the GPU runs (memory bandwidth is shared on Strix Halo). Most of the 2.5× has to come from the GPU half (hrx/loom: int4 x int4 prefill on the GPU matrix units for dense projections (Qwen3.8-27B prefill ~500 -> 1,300+ tok/s) #3349).

    Where the split can live (checked at the pinned hrx-loom 0.2.0 / hrx-system 0cd370f2ba):

    • loom-serve route: not at the pin. A deployment runs on one execution device. The machine JSON can name 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.
    • HRX / llama.cpp route: feasible as a scheduler-level split of whole FFN ops (e.g. some layers' FFN on the NPU). tools/npu_accel: llama-npu-server - llama.cpp models with their weight matmuls on the NPU (ggml ACCEL backend) #3348 (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:

    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

  24. bong-water-water-bong commented on Nov 24, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Merged: #3464 (396f60f1) retires the design in the four docs that still sold it, and adds the canonical
    entry 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#3157 entry in KNOWN-ISSUES.md. What a future hybrid would need before it can be
    designed 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementrfc

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions