Skip to content

chain, gpu, runtime: LFM3 C1 — the conv ring's length, rope factors, and the short-conv, per-head gate and sandwich host twins - #930

Merged
midagedev merged 2 commits into
mainfrom
lfm3c1-v2
Oct 28, 2026
Merged

midagedev merged 2 commits into
mainfrom
lfm3c1-v2

Conversation

@midagedev

@midagedev midagedev commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

What and why

LFM3 step C1: the common host owners the next kernels read, with no kernel change. The conv ring's length is named by its taps (chain::linear::Ring{taps}, stores::conv_ring_bytes; the CUDA ring_input keeps its fixed ring until C2's short-conv kernel, its first other user, adds the length), RoPE takes ggml's freq_factors (RopeSpec.factors, from rope_freqs.weight), and the short conv, the per-head output gate (OutGate::ProjHead) and the sandwich residual get host twins in chain, each tested against hand-derived cases.

Release notes: internal — LFM3 does not run yet (C2 kernels and C3 body follow).

Code shape

  • No second copy. One ring owner for delta, Mamba2 and the short conv; one rope table with optional factors.
  • Model code holds only architecture facts. lfm3/hparams.rs reads the factors; lfm3/place.rs sizes the ring through stores::conv_ring_bytes.
  • Dead code is gone.
  • No silent failure. A factors table of the wrong length, a NaN conv output and a position gap are named errors.
  • Comments state what is true now.
  • No relaxed gate.
  • cargo fmt and cargo clippy are clean on what I touched.

Duplication found or removed: none. One line outside the LFM3 files: gpu-deepseek41/src/params.rs names factors: None.

What I ran

  • After review: no crates/gpu change remains (only gpu-deepseek41/src/params.rs names factors: None), so the PTX is main's.
  • cargo test --lib: chain 43 passed, runtime 297 passed, model 592 passed; clippy on chain, runtime, model and gpu-deepseek41: 0 warnings.

What holds the host twins to a kernel

Each twin is the reference of a C2 gate clause (gate_lfm3_kernels, C2): shortconv::short_conv for the short-conv kernel, out_gate::out_gate (ProjHead) for the per-head gate argument of attn_out_gate_sigmoid, residual::sandwich_add for the sandwich residual node, and RopeSpec::with_factors with Hparams::rope_factor_values for the factored rope table.

Hardware

Host code only; the canon-check ran on the maintainer's box (sm_86).

🤖 Generated with Claude Code

…and the short-conv, per-head gate and sandwich host twins

- `chain::linear::Ring { taps }`: rows = taps − 1 + the pass (14 at 7 taps), through `stores::conv_ring_rows`; the
  delta and Mamba2 convs keep 4 taps through `DELTA_RING`. `ring_input` takes the ring's rows; its five callers pass
  `RING_ROWS`, a move for every existing kernel.
- `RopeSpec.factors` (ggml's freq_factors, from `rope_freqs.weight`): the table and the reference cache divide theta
  by factor i in ggml's order. A model without factors builds the same bits.
- Host twins in chain: `shortconv::short_conv` (C ⊙ conv(B ⊙ x) over the ring), `out_gate::out_gate` (Proj and
  ProjHead), `residual::sandwich_add`, each with hand-derived cases.
- `stores::conv_ring_bytes`, used by the recurrent sizing and LFM3's place.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 28, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MUST_FIX: ring_input gains a rows parameter that every caller sets to RING_ROWS, which is an element the change does not use now.

Must fix

1. ring_input takes rows, and no caller passes anything but RING_ROWS

crates/gpu/src/linear/mod.rs:108 adds the parameter. All 5 call sites pass RING_ROWS: conv.rs:147, mamba2.rs:311-313 and mamba2.rs:1113. The only other reader of a different ring size is the short-conv kernel, which is not in this diff (C2). The change edits three kernel bodies and widens an unsafe contract (rows > d >= 1) for a caller that does not exist yet.
Cost: C2 adds the parameter in the same commit as its first user, with its own gate. Until then the kernels stay as they were and the ptx-scan risk is zero.
Fix: revert the crates/gpu hunks (linear/mod.rs, linear/conv.rs, mamba2.rs) in this PR. ring_input keeps its 5 arguments and RING_ROWS.

Non-blocking

⚠ Host twins have no caller yet: crates/chain/src/shortconv.rs:29, out_gate.rs:22, residual.rs:21, RopeSpec::with_factors and Hparams::rope_factor_values are used by their own tests only. I read this as the stated staging (C2 gates compare against them), so I did not block. Name the C2 gate that calls each one in the PR body, or the twins have nothing that holds them to a kernel.

⚠ Second owner of the Proj gate rule: crates/chain/src/out_gate.rs:68 computes attn · sigmoid(g) with a finite check for Proj, as out_gate_host already does at crates/gpu/src/linear/out_gate.rs:158. They differ in the sigmoid (device polynomial vs libm) and in the failure (NaN value vs Err), so I did not call it a duplicate. State in the module doc which gate uses which, so the Proj kernel is not compared with two rules.

⚠ Tests pin the delta ring size three times: linear.rs:224-233 asserts RING_ROWS == 11 and CONV_ROWS == 3, and stores.rs:318 tests conv_ring_rows(4) == 11. gpu/src/arch/hybrid.rs:55 also asserts it at compile time. One owner of the number is enough; drop the delta constants from the Ring test.

Checked

  • Duplicates: 14 new items checked. Hits: out_gate_host (see ⚠ above); Metal's ring_rows at crates/metal/src/kernels/delta_geom.rs:17 and PASS_ROWS at :11 are an older second owner, outside this diff. dryer: 0 pairs.
  • Complexity: crapper flagged nothing.
  • Silent failure: 9 sites followed (factors length and value, Ring::new(0), non-consecutive pos, non-finite conv output, gate kind and length, non-finite sandwich input, eps range, factor bytes count, absent table). Each is a named error or panic. A refused short_conv or sandwich_add leaves its state as it was.
  • Tests: mutation check done for Ring::before, Ring::rows, rope factor order and the YaRN blend, the per-head gate index, the conv tap order and the ring write range. Each has an assertion that turns red.
  • Rope: the division is theta / ff before freq_scale, as in ggml's rope_cache_init. RopeSpec lost Copy; every caller takes &RopeSpec, so none breaks.
  • Gates: no pin moved. Escape catalog: no match.

Notes

  • The PR body has no nvidia-smi line or just gate-* output. Only canon-check is named, on the maintainer's box.

Card check: needs-gpu. This pull request changes crates/gpu-deepseek41/src/params.rs, crates/gpu/src/linear/conv.rs, crates/gpu/src/linear/mod.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

…ds another; one owner pins the delta ring

`ring_input`'s length argument had no caller passing anything but `RING_ROWS`,
so the gpu hunks go back to main's; the short-conv kernel adds it with its first
user. The `Ring` test no longer re-pins the delta constants `stores` and
`hybrid.rs` already pin, and `out_gate`'s module doc names which gates read
which host rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: the new commit reverts the ring_input change, and the earlier must-fix and ⚠ items are fixed or answered.

Since the last review

  • Must fix 1 (ring_input takes rows): fixed. crates/gpu/src/linear/mod.rs:107 has its 5 arguments again, and the 4 call sites in conv.rs and mamba2.rs pass no rows. The only crates/gpu* change left is factors: None in gpu-deepseek41/src/params.rs.
  • ⚠ Host twins have no caller yet: answered. The PR body names the C2 gate clause that uses each twin.
  • ⚠ Second owner of the Proj gate rule: fixed. The module doc of out_gate.rs:9-11 now says out_gate_host keeps the Proj kernels and this rule is the LFM3 reference.
  • ⚠ Delta ring size pinned three times: fixed. The constants assertion is gone from the Ring test; gpu/src/arch/hybrid.rs keeps its compile-time check.

Checked

  • Duplicates: the new commit adds no item. Its one new text is a doc paragraph naming out_gate_host.
  • Complexity: crapper flagged nothing. dryer: 0 pairs.
  • Silent failure: no new site in the new commit. The earlier 9 sites stay named errors or panics.
  • Tests: the removed assertion pinned constants that the compile-time check in hybrid.rs still holds. The Ring rows case [(1, 0, 8), (3, 2, 10), (4, 3, 11), (7, 6, 14)] still turns red on a taps + PASS_ROWS mutant.
  • Gates: no pin moved. Escape catalog: no match.

Notes

  • The PR body has no nvidia-smi line or just gate-* output. The change is host code only, and the crates/gpu kernels are unchanged, so no card run is needed for this verdict.

Card check: needs-gpu. This pull request changes crates/gpu-deepseek41/src/params.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@midagedev
midagedev merged commit 5011dad into main Oct 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant