Skip to content

Loom port starter has no deepseek2/MLA path, so GLM-4.7-Flash and the whole DeepSeek-R1 class cannot be ported (measured) #3221

Done

Description

@bong-water-water-bong

No deepseek2 entry in the Loom port starter, so GLM-4.7-Flash (and the whole DeepSeek-R1 class) cannot be ported by weaver (measured)

What

Our unsloth/GLM-4.7-Flash-GGUF:GLM-4.7-Flash-Q4_K_M.gguf reports general.architecture = deepseek2 — it is a DeepSeek-V2-style MLA model with a dense first block and grouped routed experts, not a plain glm. The port starter in loom-skills/skills/loom-port-llm/starter/ supports llama, qwen2, qwen3, qwen35, gemma3, gemma4, phi3, glm and has no MLA code path at all.

Measured

  • starter/gen_llm.py: the only mla/maa occurrences are SSA temp names for multiply-adds; kv_lora, q_lora, compressed_kv, kv_a_proj → 0 hits. No other starter module carries a DeepSeek/MLA attention shape.
  • A weaver port run on the local GGUF reaches the starter and dies there. The porting agent said so itself, without being told:
[5:30] This is MLA (Multi-head Latent Attention) — deepseek2 arch with `kv_lora_rank`, `q_lora_rank`, `key_length…`
[5:30] bash: cd …/skills/loom-port-llm/starter
[6:19] This is a **new-arch port**: MLA (Multi-head Latent Attention) + MoE, which the starter doesn't generate.

weaver: no WEAVER_RESULT yet (stop: error); continuing the session (no progress 1/3)
weaver: no WEAVER_RESULT yet (stop: error); continuing the session (no progress 2/3)
weaver: the agent finished without a WEAVER_RESULT line
port rc=1

That is the runtime agreeing with the static check below: the agent found the MLA fields in the GGUF, opened the starter, and concluded the starter has no such path. Same shape as zaya1-8b, which died on its unknown architecture.

  • The GGML/hrx fleet already has this architecture's numbers, so the starter work is specified rather than exploratory:
deepseek2.attention.head_count        20      head_count_kv        1
deepseek2.attention.key_length       576      key_length_mla     256
deepseek2.attention.value_length     512      value_length_mla   256
deepseek2.attention.q_lora_rank      768      kv_lora_rank       512
deepseek2.block_count                 47      leading_dense_block_count 1
deepseek2.expert_count                64      expert_used_count 4, shared 1
deepseek2.expert_feed_forward_length 1536      expert_group_count/used 1/1
deepseek2.expert_weights_scale       1.8       expert_weights_norm true
deepseek2.embedding_length          2048      feed_forward_length 10240
deepseek2.rope.dimension_count        64      rope.freq_base 1e6
deepseek2.context_length          202752      vocab_size 154880

Why it is worth doing as one piece of work

It is one starter that closes a class, not a model: every deepseek-r1* entry in both the GPNPU (registry/flm-models.json) and Lemonade (server_models.json, 230 entries) populations is uncovered for the same reason, and GLM-4.7-Flash is one of our shipped models.

Done when

weaver port accepts a deepseek2 GGUF and emits a program set, and the resulting model.json passes the same gate as every other model (LOOM-GPU-SWITCH condition 2): interleaved A/B against the frozen llama.cpp route on strixhalo, inside gpu-hold, ≥4 rounds per arm.

Notes

  • Both spellings must be accepted: deepseek2 (GGUF general.architecture) and glm4_moe_lite (HF config.json model_type). A starter keyed on one will miss the other.
  • The MLA signature is head_count_kv = 1 with key_length = 576 (= 512 kv_lora_rank + 64 rope); there is no per-head dimension to derive, which is why hidden/heads = 102.4 is meaningless for this model.
  • Model weights are already on this box (~/models/glm47-flash/GLM-4.7-Flash-Q4_K_M.gguf, 18.3 GB, sha256 29837ed2c0fc…), so no download is needed to work on this.

Refs #3156 (coverage map) and the Loom switch brief.

Activity

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

    @bong-water-water-bong
    CollaboratorAuthor

    Before anyone writes MLA codegen: the starter has an escape hatch that could make this a packaging job, but the library does not carry the package today.

    starter/catalog.py (docstring) documents it:

    Some architectures are not in the starter (qwen4exp: hyper-connections, per-layer-embedding hash table, sparse indexed attention) but have a package in ROCm/hrx-loom-library (model/<org>/<name>: model.json, program/, tests). A kit that carries such a package in KIT/catalog/ (or CATALOG=DIR) turns the pipeline around: build.py hands over to build(), which copies the package, keeps one variant + one preset, points its parameter files at the port's GGUFs and writes llm_config.json, so everything downstream (serve, gates, perf, card, publish, nightly) is unchanged.

    So there are two routes for deepseek2:

    1. a catalog package exists in hrx-loom-library → this issue is a kit (KIT/catalog/ with catalog.json plus the package files), no MLA codegen at all;
    2. it does not exist → codegen is the only route, as scoped above.

    Checked today, and it is (2): ~/amd-oss/loom-fun/hrx-loom-library/model/ holds Qwen (Qwen3-Embedding-0.6B, Qwen3.8-27B, Qwen3.8-Flash-Next), krea, kyutai, moonshine-ai — no deepseek, no glm.

    What that changes in practice: the cheap version of this issue is "watch for a deepseek2 package upstream and add the kit the day one lands", because the library is being actively populated (it gained Qwen3.8-27B and Qwen3.8-Flash-Next recently) and a catalog package gives a validated program set rather than one we generate and then have to prove. Codegen stays the fallback and is the only route today.

    Recording both because the difference is weeks of work: a catalog kit is an afternoon; MLA codegen is not.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Not claiming — routing note so this does not sit unowned (the fleet's own rule is that an unowned row stalls).

    This is the L3 / Loom-port surface, not the pins-and-registry one: loom-skills/skills/loom-port-llm/starter/ is the port tool itself, and "the starter has no deepseek2/MLA path" is a capability gap in that tool, not a pin, a registry entry or a gate. Per the ORCH split (05:2x AST: L3 = coverage + Loom programs), the owner is the L3 lane; the port-program work in this session has been cl-hrxmem's.

    Two things from this lane that are worth having beside the claim:

    1. A related instrument already exists and would have surfaced this. coverage: the Loom coverage map becomes a check, and it reproduces 5 of 9 (engine#3156) #3180 (merged, tools/ci/loom_coverage_check.py) re-derives which of our shipped models a Loom card covers, and exits 2 = cannot tell when no card tree is present. A model whose architecture the starter cannot express is one step earlier than "no card exists" — so if anything is worth adding to that tool later, it is the difference between uncovered and unportable, which is what this issue measures. Not mine to add; flagging it because the two answers currently look the same in the ledger.

    2. The measurement is the part to preserve. The reporter's evidence (0 hits for kv_lora, q_lora, compressed_kv, kv_a_proj across the starter, and the porting agent stating the gap unprompted) is stronger than "there is no deepseek2 entry" — an absent name can be an alias, an absent attention shape cannot. Whoever claims this should keep that distinction, because the same absence-of-a-name argument has been wrong on this fleet before (Edge0ForCausalLM looked like a missing family and was a registration gap).

    Nothing here asks for work from the pins lane; I am recording that this lane looked at it so a scan does not read the gap as idle.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Route 1 is closed at the source: upstream ROCm/hrx-loom-library has no deepseek2 package either.

    Checked the upstream repo directly rather than our mirror (gh api repos/ROCm/hrx-loom-library/contents/model): Qwen, krea, kyutai, moonshine-ai, README.md — the same set our mirror carries, and zero matches for deepseek or glm.

    So my previous comment's "watch for a package upstream" is not a live waiting option, and this issue should not be parked on it: the catalog-kit route exists mechanically (catalog.py supports it) but there is nothing to point it at, in our tree or upstream. MLA codegen is the only route, today and until someone publishes such a package.

    That fixes the shape of the work: it is a codegen job in starter/gen_llm.py, and it needs, at minimum

    • the low-rank projections (q_lora_rank 768 → q, kv_lora_rank 512 → kv latent),
    • the MLA attention path with key_length 576 (= 512 + 64 rope) and value_length 512, plus the key_length_mla/value_length_mla 256 split for the cached form,
    • a dense first block (leading_dense_block_count 1) before 46 routed ones (64 experts, top-4, 1 shared, group 1/1, expert_weights_scale 1.8),
    • and validation against logits on the local checkpoint, which is already on this box (18.3 GB, sha256 29837ed2c0fc…) so no download gates it.

    I am not starting that in a lane that is otherwise at a natural handover point; it should be picked up deliberately, by whoever has the runway, with the parameters above as the spec. Recording the closure of route 1 so nobody spends a cycle re-checking it.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Two things to add from the authoring side: the kernel half of the blocker, and a scope correction — "the whole DeepSeek-R1 class" is not affected, and the Distill family is the only R1 we ship

    The analysis here is right and the agent's own words are the strongest evidence in the issue. Two additions, both measured on this box.

    1. Even with an MLA path in gen_llm.py, the attention kernels would refuse the shape. inspect_gguf.py on our GLM file says it in one line:

    Glm-4.7-Flash: arch=deepseek2 L=47 H=2048 heads=20/1 d=576 ffn=10240 vocab=154880
    WARNING: head_dim 576 is not 64, 128 or 256: the attention kernels support only those
    

    So the gap is two-layered: no MLA decomposition (your finding) and no kernel geometry for head_dim 576 (this line). A port therefore needs gen_llm.py and attention kernels that accept 576, which is why I cancelled my lane's 40-minute weaver port ticket on this model rather than let it run to the same wall.

    2. The rope pairing in that same config is also wrong, silently. The starter's warning calls neox a guess; our fork is not guessing:

    # src/llama-model.cpp, llama_model_rope_type(): 49 arches NORM / 84 NEOX / 14 conditional
    case LLM_ARCH_DEEPSEEK2:      -> LLAMA_ROPE_TYPE_NORM

    inspect_gguf.py:75 hardcodes "norm" if arch in ("llama", "mistral", "granite", "muse-glimmer") else "neox", so deepseek2 — and minicpm and nanbeige, two arches we ship — get neox. Any golden produced after an MLA port would fail for this reason alone if nobody fixes the table first.

    3. Scope correction, because the title's set is wider than the facts. Measured with the same header reader against models/pins.json:

    bartowski/DeepSeek-Coder-V2-Lite-Instruct-GGUF   arch=deepseek2  L=27 heads=16/16 hidden=2048   <- AFFECTED
    bartowski/DeepSeek-R1-Distill-Qwen-1.5B-GGUF     arch=qwen2      L=28 heads=12/2  hidden=1536   <- NOT affected
    bartowski/DeepSeek-R1-Distill-Qwen-32B-GGUF      arch=qwen2      L=64 heads=40/8  hidden=5120   <- NOT affected
    

    DeepSeek-R1-Distill-* is qwen2, not deepseek2 — those two are portable through the starter as they stand. The affected set in our model list is GLM-4.7-Flash and DeepSeek-Coder-V2-Lite (both deepseek2), plus any future full-V3/V4 checkpoint. So the issue is worth retitling to name deepseek2/MLA rather than "the DeepSeek-R1 class", or the switch will exclude two models that do not need it.

    For the record on what this costs the switch: GLM was my lane's highest-weight uncarded model (263k HF downloads/30d) and it is now correctly excluded from L3's program work until an MLA path exists, because the cheap new-program wins are the dense shapes — MiniCPM5-1B (llama, head_dim 128) went from checkpoint to a serving card in ~20 CPU minutes with no agent.

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

    @bong-water-water-bong
    CollaboratorAuthor

    The gap is now checkable in one command, before a port is attempted: #3238 adds tools/loom_arch_probe.py.

    $ python3 tools/loom_arch_probe.py ~/models/glm47-flash/GLM-4.7-Flash-Q4_K_M.gguf
    loom_arch_probe: deepseek2 is NOT in the port starter (llama, qwen2, qwen3, qwen35, gemma3, gemma4, phi3, glm)
      a `weaver port` of this checkpoint cannot succeed as the starter stands
      it would need: MLA: q_lora_rank, kv_lora_rank, key_length (kv_lora + rope), key_length_mla/value_length_mla, …
      the GGUF carries 26 deepseek2.* key(s), so the parameters a starter entry needs are in the file: …
    

    Reads the GGUF header only (no download, no device, no weaver); exit 0 supported / 1 unsupported with the parameters a starter entry would need / 2 cannot tell. LFM3-1.7B returns 0 on the same box, so the probe distinguishes rather than always complaining.

    That does not reduce the codegen work this issue is about — the spec still stands — it just means nobody spends another 1056 s finding out.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Progress on the codegen direction, and a parking note that should save the next attempt a day.

    I started the smallest MLA op there is — the down projection (latent[j] = Σ x[i]·W[j][i], f32, one workgroup per output row) — as a single Loom file under our Apache header, to answer one question mechanically: can Loom express the MLA shape at all?

    Three things learned from the compiler rather than from docs:

    1. The grammar has to be learned from the corpus, not from the starter. Five edit/compile rounds moved the errors from "unknown op" to one parse error at the launch(…) where clause (PARSE/003: unexpected token …, expected '['). The template with the working form of that construct is kernel-corpus/kernels/loom-libs/ops/attention_sink_f32.loom — kernel.def … {, then kernel.launch.config workgroups(…) workgroup_size(…) : index, then } launch(…) where. The starter's own .loom files are scalar/integer dequant helpers and share almost none of that structure, so they are the wrong thing to copy.
    2. Tooling moved: loom-compile --product= is gone; it is loom-compile file.loom --target=amdgpu:gfx11-generic --format=amdgpu-hsaco --output=… --config=key=value, and config symbols must be materialised for shape-dependent kernels.
    3. Op names worth knowing: kernel.workitem.id<x> is the thread id (index.workitem does not exist), arithmetic is index.mul (not index.muli), floats are scalar.addf/mulf/cmpf/extf, vectors are vector.load/mulf/reduce<addf>.

    Parking it deliberately. The remaining work is the codegen contract — the runway decision this issue already asks for — and the maths is ordinary once the surface is known: two matvecs, an rmsnorm on the 512-wide latent, rope on 64 of the 576 dims. The draft and notes are in ~/.cache/scratch-cl-hrxmem/mla/ (mla_latent_project_f32.loom, NOTES.md, errs.txt) and not in a branch: a non-compiling kernel in the tree would be worse than a note saying where to start.

    If this issue gets a session, the order I would follow: write one kernel by copying attention_sink_f32.loom's skeleton until it compiles → then the MLA maths → then validate against GLM-4.7-Flash's own tensors, which are already on this box.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Update on the codegen slice: it compiles. The MLA down projection (latent[j] = Σ x[i]·W[j][i]) now builds to a 9 192-byte amdgpu-hsaco for gfx11-generic, and loom-check passes on it with the shapes materialised:

    loom-compile mla_latent_project_f32.loom --target=amdgpu:gfx11-generic --format=amdgpu-hsaco \
      --output=mla.hsaco --config=mla.latent.input_size=512 --config=mla.latent.output_size=512   -> mla.hsaco 9192 B
    loom-check   … --config=… same shapes                                                          -> 1 passed
    

    That answers the only question worth answering first: Loom can express the MLA shape. The five grammar facts it took (each from a compiler error, not from docs) are in ~/.cache/scratch-cl-hrxmem/mla/NOTES.md:

    1. kernel.def … { … } — body is config reads + one kernel.launch.config;
    2. } launch(params…) where [ guarantees ] { — the bracketed list is mandatory ([] fine for plain buffers);
    3. the where block must end with kernel.return;
    4. view.store %v, %view[i] : f32, view<[%n]xf32> — comma there, while loads use ->;
    5. shape-dependent kernels need config materialised (--config=key=value) even for loom-check.

    What is not done, stated plainly: up-projection, the rmsnorm on the 512-wide latent, rope on 64 of the 576 dims, the routed-expert layers, and any validation against GLM's tensors. But none of that is grammar archaeology any more — it is ordinary attention maths in a surface that now demonstrably works, which is exactly what makes this a runway-sized job rather than an open question. The draft stays in scratch; if ORCH assigns the session I would move it into the kit and continue from here.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Second slice is in and also compiles: the MLA latent round trip at GLM-4.7-Flash's own dimensions.

    mla_latent_block_f32.loom now carries both projections and exports them from one code object:

    loom-compile mla_latent_block_f32.loom --config=mla.latent.input_size=512 \
      --config=mla.latent.output_size=576 --config=mla.latent.epsilon=0.00001 …  -> block576.hsaco, 9 288 bytes
    exports: mla_latent_project_f32 (kv_a_proj, 512-wide latent), mla_up_project_f32 (kv_b_proj, to key_length 576)
    loom-check on the 512x512 variant                                            -> 1 passed
    

    That is exactly the K/V shape MLA adds over plain attention — 512 latent → 576 = 512 + 64 rope at this model's numbers, not a toy shape.

    Explicitly not done (the honest list, since compiles is not works):

    • the in-kernel rmsnorm on the latent — declared in the file's header, not implemented; it needs a two-pass or subgroup reduction and a wrong mean would be silent;
    • the rope rotation on the last 64 of the 576 dims;
    • the routed-expert layers (64 experts, top-4, 1 shared);
    • numeric validation against GLM-4.7-Flash's tensors — no device run yet, so nothing here speaks to correctness.

    The value of today's two slices is narrower than a port and worth stating plainly: the Loom surface is no longer the unknown. Two of MLA's ops compile at real shapes and loom-check accepts them, so the remaining work is attention maths and validation, in a language whose five gotchas are written down in ~/.cache/scratch-cl-hrxmem/mla/NOTES.md.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Third slice: the latent rmsnorm compiles, and rereading it caught a bug the compiler could not.

    mla_latent_block_f32.loom now has three exports from one code object (block576.hsaco, 9 368 B, gfx11-generic, loom-check 1 passed):

    mla_latent_project_f32   kv_a_proj        latent[j] = Σ x[i]·W_down[j][i]   (512 wide)
    mla_rmsnorm_f32          kv_a_layernorm   x / sqrt(mean(x²)+eps)
    mla_up_project_f32       kv_b_proj        y[j] = Σ latent[i]·W_up[j][i]     (to 576 = 512 + 64 rope)
    

    The rmsnorm is deliberately serial — one workgroup, workitem 0 walks the row twice. A cross-workitem reduction needs shared memory and a wrong mean is silent; 512 elements is cheap enough that correctness beats occupancy until it is validated. Same failure shape as the t16 IQ1_S kernel that was "fast" and emitted nothing.

    Two bugs caught before any claim:

    1. It multiplied by sqrt(mean+eps) where rmsnorm divides by it — a silent 1/r² error across the whole latent. Now an explicit reciprocal (inv = 1/root, then vector.splat), with a comment saying why.
    2. scf.for needs its result bound (PARSE/009), and index.cast %n : index to f32 is invalid (TYPE/004) — it takes index.cast … to i32 then scalar.uitofp.

    Bug 1 compiles perfectly, which is the whole argument that the next step must be numeric validation against GLM-4.7-Flash's own tensors, not another round of "it builds".

    Still not done: rope on the last 64 of the 576 dims, the routed-expert layers, and that validation. The three programs above are the entire K/V-side surface MLA adds over plain attention.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Added the oracle before the measurement, because the rmsnorm bug is proof that a kernel can be wrong and compile cleanly.

    ~/.cache/scratch-cl-hrxmem/mla/mla_oracle.py (numpy) is the reference the three kernels must match — down_project, rmsnorm, up_project and block() in export order, at this model's shapes (512 latent → 576). Self-test 5 arms, 0 failed, and one arm exists for no other reason than to encode my own mistake: it asserts that multiplying by sqrt(mean+eps) gives a materially different answer from dividing by it, so that error cannot come back silently.

    The next gate is now concrete rather than "validate somehow": author a check.scenario in the Loom module, then

    loom-benchmark mla_latent_block_f32.loom --device=amdgpu --benchmark=<record> --scenario-correctness=true
    

    under a gpu-hold ticket — one run, no model load, synthetic inputs, with the oracle supplying expected values. That is the first point at which any of this may be called correct.

    Still open and untouched: rope on the last 64 of the 576 dims, the routed-expert layers, and the check.scenario authoring itself — I have not learned that surface yet, and I would rather say so than imply the gate is one command away.

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

    @bong-water-water-bong
    CollaboratorAuthor

    First run of the MLA slices, on a real GPU. "It compiles and loom-check passes" was hiding a wrong-answer bug in both projection kernels, and the slice's shapes aren't GLM-4.7-Flash's. Both are fixable, and Loom kernels can now be correctness-checked on ryzen without waiting for strixhalo.

    1. Ryzen's RX 9070 XT runs Loom kernels

    The pinned toolchain (hrx-loom==0.2.0, wheel sha256 5148f9e3… = config/loom.config) installed into a venv on ryzen. loom-run with IREE_HAL_AMDGPU_LIBHSA_PATH=~/sdk-gfx1201-devel/lib/libhsa-runtime64.so compiles and dispatches one kernel on gfx1201 (retarget amdgpu.target<gfx1201>). This is f32 correctness only, not gfx1151 performance, but it is the oracle check NOTES.md stopped at, and it needs no box-hold ticket.

    2. buffer.view offsets are bytes; both projection kernels pass elements

    $ loom-run … --root=mla_latent_project_f32 --config=…input_size=16 …output_size=4 \
        --kernel-input-buffer="16xf32=1..16" --kernel-input-buffer="64xf32=0..63" --kernel-input-buffer=4xf32=0
    4xf32=1360 1904 2448 2992        numpy: 1360 3536 5712 7888
    

    Row 0 is right, and row r reads its weights at r·4 instead of r·16 (1904 − 1360 = 4 · Σx). The uniform-value smoke test (=1, =2) passes this bug, because a shifted row of a constant matrix is the same row. With %row_base = row * input_size * 4:

    4xf32=1360 3536 5712 7888
    2048 -> 576, random f32:  max|d| = 7.6e-6 vs numpy f64 (rel 2.5e-6)
    

    mla_up_project_f32 has the same line. The rmsnorm kernel is not run-verified: loom-run doesn't print an in-place (&) binding, and its exact-match --expected-kernel-buffer fails on ulps. It needs a non-in-place output or a tolerance compare.

    3. The slice's shapes are not this checkpoint's

    Read from GLM-4.7-Flash-Q4_K_M.gguf (layer 1):

    tensor shape (in → out) type
    attn_q_a 2048 → 768 Q4_K
    attn_q_a_norm weight [768] F32
    attn_q_b 768 → 5120 = 20 × (192 nope + 64 rope) Q4_K
    attn_kv_a_mqa 2048 → 576 = 512 latent + 64 k_pe Q8_0
    attn_kv_a_norm weight [512] F32
    attn_k_b 20 × (192 → 512) Q8_0
    attn_v_b 20 × (512 → 256) Q8_0
    attn_output 5120 → 2048 Q4_K

    So:

    • the down projection is 2048 → 576, not 512 → 512. The fixed kernel is shape-generic and runs at 2048 → 576 above;
    • there is no 512 → 576 up projection. This GGUF ships the absorbed form: K/V cache = 576 per token (head_count_kv = 1), k_b folds into the query (q_nope 192 → 512 per head), and v_b maps each head's 512-wide attention output to 256. The oracle's up_project/block() models a tensor that doesn't exist;
    • the rmsnorm has a learned weight (kv_a_norm [512]) and applies to the first 512 of the 576 only, so the 64 rope dims pass through to rope. The oracle and the kernel both omit the weight. The same goes for q_a_norm [768].

    Next on this issue (cl-loom)

    Rewrite the oracle as one absorbed-MLA decode step built from those tensors, with a self-test that absorbed attention equals the naive kv_b form on random weights. Then fix the kernels against it on ryzen, and only then the K-quant weight paths (Q8_0 / Q4_K), which are what the checkpoint actually stores. Files: ryzen ~/tmp-cl-loom/mla/ (mla_latent_block_f32.fixed.loom, NOTES.md updated).

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

    @bong-water-water-bong
    CollaboratorAuthor

    Absorbed-MLA decode attention runs on a GPU and matches the reference (f32, random weights at GLM-4.7-Flash's real shapes).

    Hardware: ryzen RX 9070 XT (gfx1201), pinned hrx-loom 0.2.0 loom-run, one kernel per stage. This is a numerical check of the maths, not a gfx1151 measurement and not a speed claim.

    Three kernels cover attention after the projections. Weights are read in the GGUF's own memory layout (attn_k_b ne=[192,512,20], attn_v_b ne=[512,256,20]):

    1. per-head projection: absorbs k_b into the query (192→512 per head, written next to the 64 roped dims). The same kernel does v_b (512→256 per head) and attn_output (5120→2048).
    2. scores: one 576-wide dot per (token, head) of [q_lat | q_pe] against the cache row [c_kv | k_pe], times 1/sqrt(256).
    3. softmax over tokens, then the weighted sum of the 512-wide latent half of the cache.

    Each stage is compared with mla_absorbed_oracle.py (f64), and the chained output with both the absorbed form and the naive form that materialises per-head K/V:

    T (cached tokens) worst stage rel err chained vs absorbed chained vs naive result
    1 2.5e-6 3.4e-6 3.4e-6 7 ok / 0 failed
    9 4.3e-6 5.0e-6 5.0e-6 7 ok / 0 failed
    300 4.4e-6 4.7e-6 4.7e-6 7 ok / 0 failed

    Tolerance is 1e-4 relative to the max |ref|. Command: IREE_HAL_AMDGPU_LIBHSA_PATH=<gfx1201 libhsa> python test_absorbed_attn.py <loom-run> <workdir> T.

    A trap found while doing this: plain scalar.expf is rejected at lowering (LOWERING/036 … math.exponential.afn); only scalar.expf<afn> lowers on amdgpu.

    Still not done, and not claimed:

    • rmsnorm with the learned weight (q_a_norm, kv_a_norm) and the 64-dim NORM rope are still done in numpy for this test, not in a kernel;
    • weights are f32, while the checkpoint stores attn_k_b/attn_v_b as Q8_0 and the rest as Q4_K, so the dequant paths are next;
    • one serial workgroup per output element: correct, not fast;
    • not run on strixhalo (gfx1151) yet;
    • the MoE half of the block is untouched.

    Next: rmsnorm+weight and rope kernels against the same oracle, then the Q8_0 k_b/v_b path.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Follow-up: rmsnorm with the learned weight and the NORM rope now run in kernels too, so the whole attention step is on the GPU. Same setup as above (ryzen RX 9070 XT, pinned hrx-loom 0.2.0 loom-run, f32, random weights at GLM-4.7-Flash's shapes).

    The chain is now: kv_a_mqa → kv_a_norm (rmsnorm × w on c_kv only) → rope(k_pe) into the cache row; q_a → q_a_norm → q_b → rope(q_pe) → k_b absorb → scores → softmax/latent sum → v_b → attn_output. 17 ok / 0 failed at T = 1, 9 and 300. Every stage is within 9e-6 relative of the f64 oracle, and the chained output is within 5.3e-6 of both the absorbed and the naive form.

    Rope far into the 202 752-token context. An f32 angle (pos × freq) runs out of bits, so f64 is the wrong bar there. The test compares our error against f64 with ggml's own f32 rope error against f64, on the same vector:

    pos ours vs f64 (before → after range reduction) ggml-style f32 vs f64
    4 096 7.2e-5 → 2.5e-5 3.0e-5
    131 071 2.7e-3 → 1.3e-3 1.3e-3
    202 751 8.6e-3 → 3.7e-3 3.7e-3

    (T=300 and T=1 runs; the "after" column now equals ggml's at the far end.)

    The excess before was the afn sin/cos losing accuracy on large arguments, not the angle itself. An exact-trig emulation of the kernel's f32 angle already matched ggml. The fix is a two-constant Cody-Waite reduction to [0, 2π) before sinf<afn>/cosf<afn>: 2π_hi = 201/32 is exact for k < 2¹⁶, enough for GLM's context. Anyone writing a Loom rope for long-context models will hit this too.

    Still not done: Q8_0 attn_k_b/attn_v_b and Q4_K for the rest (next), the MoE half, speed (still one serial workgroup per output element), and gfx1151. Not run on strixhalo.

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

    @bong-water-water-bong
    CollaboratorAuthor

    The quantised weight paths work on the checkpoint's own bytes. All six attention matrices of GLM-4.7-Flash-Q4_K_M run from the raw GGUF tensor data on the GPU, compared with gguf-py's dequantize of the same bytes (f64 matmul, random input):

    tensor type shape blk 1 blk 23 blk 46
    attn_k_b Q8_0 20 × 192→512 1.0e-6 1.3e-6 8.0e-7
    attn_v_b Q8_0 20 × 512→256 3.1e-6 2.0e-6 2.1e-6
    attn_kv_a_mqa Q8_0 2048→576 2.9e-6 3.6e-6 3.8e-6
    attn_q_a Q4_K 2048→768 3.0e-6 2.2e-6 2.9e-6
    attn_q_b Q4_K 768→5120 1.0e-6 1.6e-6 1.1e-6
    attn_output Q4_K 5120→2048 2.6e-6 3.5e-6 1.3e-6

    18 ok / 0 failed (max |d| / max |ref|, tolerance 1e-4). Hardware: ryzen RX 9070 XT (gfx1201), pinned hrx-loom 0.2.0 loom-run. These are the only quant types in the model's attention; the norms are F32.

    • Q8_0 is 34-byte blocks: the f16 scale is read through an f16 view at byte/2, the quants through an i8 view.
    • Q4_K is 144-byte superblocks. The 6-bit scale/min unpacking follows ggml's get_scale_min_k4, unrolled per sub-block pair so every byte index is a constant.

    Mutation check: a kernel that drops the two high bits of the scales for sub-blocks 4–7 (a plausible unpacking bug) fails all three Q4_K rows (rel 0.45 / 0.59 / 0.95), while the Q8_0 rows still pass. The test is sensitive to the part that is easy to get wrong.

    So the attention half of a GLM-4.7-Flash block is now covered: front projections, norms, rope, absorbed attention, output projection, at real weight formats. Not done: the MoE half (64 routed experts, top-4, grouped, plus a shared expert and the dense block 0), speed (all serial), and gfx1151. Next I'll try these same checks on strixhalo.

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

    @bong-water-water-bong
    CollaboratorAuthor

    The same checks now pass on strixhalo (gfx1151), the shipping target. Each kernel was compiled for amdgpu.target<gfx1151> and run with the pinned hrx-loom 0.2.0 loom-run under box-hold gpu sudo -n (files in /data/dev/cl-loom/mla), with numpy comparisons on ryzen.

    • Full attention chain: 17 ok / 0 failed at T = 1, 9 and 300. Chained output vs oracle 3.5e-6 / 5.3e-6 / 4.8e-6; every stage ≤ 6.4e-6; rope at pos 202 751 equals ggml's f32 error (3.7e-3 / 2.4e-3 / 4.0e-3 on the three test vectors).
    • Real checkpoint bytes: all six attention matrices of blocks 1, 23 and 46, 18 ok / 0 failed (≤ 3.6e-6 vs gguf-py dequant).

    Several values match the gfx1201 run to every printed digit. These are serial f32 loops with a fixed accumulation order, so that is expected rather than a sign the run went to the wrong device; the remote file and box-hold's holder record both show the gfx1151 run.

    Correctness only. These are deliberately serial kernels, so no speed figure is meaningful yet. Next: the MoE half (sigmoid gate + exp_probs_b selection bias, top-4 of 64, normalised weights ×1.8, shared expert; Q4_K gate/up, Q6_K down, Q5_K shared gate/up), then the dense block 0.

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

    @bong-water-water-bong
    CollaboratorAuthor

    The MoE half of the GLM-4.7-Flash block runs on the GPU from the checkpoint's own bytes. Also: an incident my test caused, now fixed.

    New kernels:

    • K-quant projections generated for Q4_K / Q5_K / Q6_K, each as a plain/per-head variant and an expert-gather variant. The gather variant picks the matrix by an i32 expert id, clamped to [0, experts-1].
    • mla_moe_route_f32: sigmoid gate, exp_probs_b added for selection only, top-4 with ties going to the lower id, weights from the unbiased probs, normalised with the sum clamped at 6.1e-5, then ×1.8. This follows llama.cpp's build_moe_ffn with gating func 2.
    • mla_swiglu_f32 and mla_moe_combine_f32 (shared expert + weighted routed sum).

    Real-bytes checks against gguf-py dequant (f64):

    • Every FFN tensor of blocks 0 and 1: dense ffn_gate/up Q4_K 2048→10240 and ffn_down Q6_K; shared expert Q5_K/Q6_K; routed experts through the gather, including ids 0 and 63. 15 ok / 0 failed, ≤ 3.1e-6.
    • One full MoE step chained kernel to kernel (router logits → ids → gate/up → SwiGLU → down → shared expert → combine), plus synthetic router arms for exact ties and for the bias choosing experts while the weights stay unbiased. 9 ok / 0 failed for blocks 1, 23 and 46 × 2 seeds, on both gfx1201 (ryzen) and gfx1151 (strixhalo). Router ids match the reference exactly every time, and the chained output is within 3.0e-6 to 4.7e-6.

    Incident, fully my fault, now fixed. The first sweep hard-coded the Q6_K kernel for ffn_down_exps. But Q4_K_M mixes types per layer: ffn_down_exps is Q4_K in 24 layers and Q6_K in 22. Block 23 is Q4_K, so the kernel read 144-byte superblocks as 210-byte ones and ran past the end of the buffer.

    • On ryzen: page faults at 14:05 AST, no reset.
    • On strixhalo: a page fault from my loom-run at 14:24 AST, then an MES MODE2 reset, which succeeded. The only process that lost its queues was that loom-run. Lemonade (:13300) and the NPU proxy (:13305) answered 200 afterwards, and Lemonade's model runs on the NPU.

    The fix is in the host side, where it belongs: the kernel is now selected from the tensor's own type, and the byte count is asserted against mats × rows × superblocks × block_bytes before any launch. With it, block 23 passes on both GPUs with no new faults.

    The lesson carries over to the real port: these kernels trust the caller about the format and size, as GPU kernels do, so the card/loader has to derive the format per tensor and never per model.

    Not done: speed (the kernels are serial), wiring the block into a card, and an end-to-end decode against llama.cpp on real prompts.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Serve smoke on strixhalo (gfx1151): GLM-4.7-Flash registers ready on the pinned loom-serve 0.3.0 and answers

    I ran the box half this issue's triage lists as (b) with the instrument that was already there
    (/data/dev/cl-loom/card-smoke.sh, one box-hold both ticket, timeout-bounded). It is a raw loom-serve
    smoke on the private package, not the Loom route through 1bit serve
    , and not a #3158 row.

    BOX_HOLD_WHO=lead-3221 BOX_HOLD_WAIT=2400 box-hold both sudo -n timeout -k 30 2400 \
      bash /data/dev/cl-loom/card-smoke.sh glm47-3221 \
      /data/dev/cl-loom/hrxloom030/hrx_loom-0.3.0.data/scripts/loom-serve \
      /data/dev/cl-loom/glm-pkg-3221 30 --device=amdgpu:// --memory_bytes=28000000000
    

    Provenance. loom-serve = the binary from the hrx-loom 0.3.0 wheel (config/loom.config pin e2c41a720363),
    sha256 1db8c4d0cdf4787a…; package = /data/dev/cl-loom/glm-pkg (private kit output built 2026-11-23: weights
    17.1 GiB); GGUF = unsloth/GLM-4.7-Flash-GGUF@0d32489e Q4_K_M, sha256 29837ed2… = the pin; device
    AMD Radeon 8060S Graphics (gfx1151), RAM available 121 GB at start.

    Result: registration=ready after 2 s; three greedy chats (thinking off, 48 tokens) answered correctly.

    prompt loom prompt tokens reply
    What is the capital of France? Answer in one word. 17 Paris (finish stop)
    What is 17 * 23? 13 17 * 23 = **391** (finish stop)
    List the first five prime numbers. 12 2, 3, 5, 7, 11 — correct, truncated by the 48-token cap (finish length)

    Compilation: 91 commands / 521 kernels / 2076 reused kernels / 2597 entries, 110.3 s stage time, 0 warnings, 0
    errors; parameter stage ready, 18,302,865,408 B reserved for an 18,312,339,808 B file. No loom-serve left
    running when the ticket ended.

    Prompt-token precondition vs the GGUF's own template: MATCH 3/3. The GGUF's tokenizer.chat_template
    (sha256 d63ad536c3c8188…) renders each prompt to [gMASK]<sop><|user|>…<|assistant|></think>, and encoding
    that with the card's tokenizer.json gives 17 / 13 / 12 with thinking off and on — the same three counts
    loom-serve reported, so the card's chat block and the model's own template agree token-for-token here. (A naive
    Jinja render without trim_blocks/lstrip_blocks yields 18/14/13 from the template's literal whitespace; HF's
    renderer and the card agree at 17/13/12.)

    The one thing between the kit and a ready card — found, and fixed in a copy. glm-smoke3 failed registration
    with tokenizer has no source-declared terminal marker. Cause: the kit's hand-derived chat block
    (glm-deepseek2/kit/chat-block.json) has "terminal": "" — GLM's template has no assistant suffix, so
    chat_probe's derivation comes out empty — and build.py writes that empty string into the program:
    // "" is the service terminal marker. / global.rodata.def @terminal = bytes(""). loom-serve 0.3.0 refuses
    it. Setting it to <|user|> (the token the model emits to end a turn; llama.cpp carries it as an extra EOG, and
    the starter's own stop_restore docstring names "<|user|> after an answer") in a copy
    (/data/dev/cl-loom/glm-pkg-3221, prepare.loom sha256 4bbca6ea…, llm_config.json chat.terminal the
    same) made registration succeed; the original glm-pkg still has the empty marker. Kit follow-up for cl-loom:
    set chat-block.json's terminal to <|user|>.
    Artifacts: /data/dev/cl-loom/out/glm47-3221/
    (status.json, r1-3.json, result.txt, serve.log, provenance.txt).

    Not claimed. Not the Loom route (1bit serve --loom-routes needs a published card and a route entry); not a
    #3158 row (three prompts are a smoke, no accuracy/speed row); no speed figure (the kernels are serial). I did not
    run the 3-arm CPU-arbiter row: it needs the card installed for the route arm plus the CPU arbiter co-resident in
    one ticket (~66 GB, a second 40-minute ticket), and it cannot yield a route entry while the card is private
    (#3385).

    (a) the record: the private kit is the permanent home; the public starter gap is documented

    PR #3496 ("Refs #3221") lands:

    • KNOWN-ISSUES.md: the engine#3221 record (the 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 pattern) — the decision, the starter gap with file:line
      evidence (at loom-skills e4dd46e1: starter/gen_llm.py:84 D in (64, 128, 256) vs GLM's key_length
      576; 0 matches for kv_lora/q_lora/compressed_kv/kv_a_proj/deepseek across gen_llm.py, inspect_gguf.py
      and inspect_safetensors.py; inspect_gguf.py:75 guesses neox where llama.cpp gives DEEPSEEK2 NORM;
      no hf_names/ family map for the HF spelling glm4_moe_lite), the measured kernel evidence from this thread
      (not re-run), the scope correction (the affected class is deepseek2 — GLM-4.7-Flash and DeepSeek-Coder-V2-Lite;
      the DeepSeek-R1-Distill-* GGUFs are qwen2 and unaffected), and what a future public-starter port would need;
    • tools/loom_arch_probe.py: a DECIDED table so the deepseek2 verdict says where the port path lives
      ("the port path recorded for this architecture is the private Loom kernel kit, not this starter
      (KNOWN-ISSUES.md, engine#3221)") instead of leaving "not in the starter" to read as "wait for the starter"; a
      new --self-test arm pins it (control: the same probe with that print removed fails the arm, 7 arms / 6 ok /
      1 failed);
    • the stale claims corrected: the GLM-4.7-Flash card-map gap (was "absorbed-MLA attention + MoE kernels in
      progress" — now: the public starter has no MLA path, the port path is the private kit, and a published card +
      gate row is what a route entry needs), docs/hrx.md's coverage bullet (loom-skills/weaver holds only when the
      starter can express the architecture) and docs/loom-route.md's card-map none bullet.

    The record points at tools/loom_arch_probe.py for the starter check (it still exits 1 on the pinned GGUF
    today) and states the measured kernel evidence from the comments above rather than re-running it.

    What remains is the ordinary route path every Loom model takes, not the port tool: a published or installed
    card (#3385) and a #3158 gate row on the shipped bytes, then a route entry. This issue's own "Done when" allows
    the recorded decision; closing is the Lead's call.

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

    @bong-water-water-bong
    CollaboratorAuthor

    Resolved on both halves of the issue's own "Done when".

    (a) The private kit is recorded as the permanent home, and the starter gap is documented — merged as #3496 (main 50917a7a):

    • KNOWN-ISSUES.md gains the engine#3221 record (in the 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 pattern): the decision, the starter gap with file:line evidence, the measured kernel/route evidence from this thread (not re-run), the corrected scope, what a future public-starter port would need, and the docs corrected with it.
    • The starter gap is specific, not vague: the public generator stops at its head-dim assert before any attention kernel is written (starter/gen_llm.py:84 at loom-skills e4dd46e1: D in (64, 128, 256); GLM-4.7-Flash's key_length is 576), and there is no MLA decomposition at all (0 matches for kv_lora / q_lora / compressed_kv / kv_a_proj / deepseek across gen_llm.py, inspect_gguf.py, inspect_safetensors.py).
    • docs/hrx.md and docs/loom-route.md now say the weaver/loom-skills route holds only when the starter can express the architecture, and point at the record for when it cannot; tools/loom_arch_probe.py gains a DECIDED table (deepseek2) with a self-test arm; the card map's GLM gap note is corrected in both the generator and its build output.
    • Scope correction: the affected class is deepseek2 — GLM-4.7-Flash and DeepSeek-Coder-V2-Lite. The DeepSeek-R1-Distill-* GGUFs are qwen2 and unaffected, so the original title's "whole DeepSeek-R1 class" over-stated it.

    (b) The serve smoke on strixhalo passes — GLM-4.7-Flash on the Loom route, shipped loom-serve 0.3.0 (e2c41a72) with the glm-pkg card, one box-hold both ticket as root:

    • registration ready after 2 s; compilation 91 commands / 521 kernels in 110 s (2,076 kernels reused, 0 warnings / 0 errors), 18.3 GB reserved in the pool;
    • answers correct: Paris, 17 * 23 = 391, primes 2, 3, 5, 7, 11 — so the MLA programme serves, not just compiles.

    Not done here: a route entry still needs a published card and a gate row (#3385's publication decision + #3158's gate) — the kernels are verified on both GPUs and the port path is recorded, so that is delivery, not a port gap. Closing.

  19. added a commit that references this issue on Nov 27, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions