Skip to content

metal: LFM3-1.7B from its MLX folder (short conv, gated windowed attention, sandwich joins) - #943

Merged
midagedev merged 9 commits into
mainfrom
mac-lfm3m2
Oct 29, 2026
Merged

midagedev merged 9 commits into
mainfrom
mac-lfm3m2

Conversation

@midagedev

@midagedev midagedev commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Metal runs LFM3-1.7B from its MLX folder (LiquidAI/LFM3-1.7B-MLX-4bit).

The qwen3moe session takes the plan's short conv layers, windowed attention with a per-head gate, the sandwich joins, two rope tables and a tied head. An instance key selects its attention from Metal's own rows (shape::select_gqa_in). Checkpoints and a cut hold the conv rings. A marked prompt call on a file with a conv layer splits its passes at the marks.

Evidence (Apple M1 Pro, this branch on main fdc0cca):

  • gate_metal_qwen35moe_e2e --row lfm3: PASS. It checks mlx-vlm's BOS pin (ids 124894,597,4104,10299, argmax [11, 2719, 368, 35886]) and the logits within LFM3_LOGIT_ABS 0.06 (PIN with derivation; measured 3.07e-3). It also checks a cut that restores the conv rings (red without them).
  • e2e rows qwen35moe, qwen3moe, qwen38d: PASS. gate_metal_qwen35moe_kernels: PASS, and --mutants-all PASS on all 6 instances.
  • Existing programs are unchanged: metal_scan --compare against main gives added=0 removed=0 changed=0. Encode traces and ids at depth 0 and 600 are identical.
  • Deep pin: m_logits_deep holds steps 255, 256, 257, 300, 302, 357 and 599 of a 600-id walk (past the 256-key window) to mlx-vlm in f32.
    • Band 0.02, with a PIN derivation. Measured worst is 6.0e-3; all seven argmax ids match.
    • --row lfm3 --mutants-all: PASS (window 255, window 257, ring without wrap, each red).
    • Ignoring the rope factors is red at step 256: argmax 20 → 34, 0.34 off.
  • Review fix: one conv_bufs owner for a layer's short conv buffers (the macro and the rows copy are gone).
  • clippy 0, just remote-static origin/main rc 0 (rerun after the review fix).

Speed on the M1 Pro, 3 rotated rounds against mlx-vlm 0.7.11 / mlx 0.32.4:

  • pp512: 1058.6 vs 900.6 tok/s.
  • pp4096: 961.4 vs 909.9 tok/s.
  • tg128: 90.9 vs 121.1 tok/s. The decode work is a separate change.

AI use: written and checked with Claude Code.

🤖 Generated with Claude Code

https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd

midagedev and others added 5 commits October 29, 2026 08:08
…d per-head gated attention, the sandwich joins, two rope tables, a tied head, and checkpoints that hold the conv rings

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
@midagedev
midagedev enabled auto-merge (rebase) October 28, 2026 23:46
@github-actions github-actions Bot added documentation Improvements or additions to documentation model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo 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: the short conv buffers have three accessors in this diff, two of them the same code; the behavior paths I built are blocked.

Must fix

1. One owner for "layer l's ConvBufs": the conv_of! macro and conv_of_rows are copies

ops.rs:288 is a 21-line macro that matches MixerBufs::ShortConv and refuses the other two variants by name. rows.rs:64 conv_of_rows does the same match with a different message. Both are new in this diff, and the macro has two callers (ops.rs:660, ops.rs:695), the function two (rows.rs:472, rows.rs:512). The macro only needs to be a macro because mod rows; sits above it. A function removes the reason.
Cost: the next mixer variant or message change must be made in both places. The fix removes the macro (net fewer elements).
Fix: in ops.rs, delete macro_rules! conv_of, add this function, and add ConvBufs to the super::arena import. Use conv_bufs(layers, l)? at ops.rs:660 and conv_bufs(layers, l.layer)? at ops.rs:695. Delete conv_of_rows from rows.rs, import conv_bufs from super, and use it at rows.rs:472 and rows.rs:512. Drop the imports that become unused (ConvBufs in rows.rs).

/// Layer `l`'s short conv buffers, or the named refusal for a layer of another
/// mixer.
fn conv_bufs(layers: &mut [LayerBufs], l: usize) -> Result<&mut ConvBufs, SessionError> {
    match &mut layers[l].mixer {
        MixerBufs::ShortConv(c) => Ok(c),
        MixerBufs::Delta(_) | MixerBufs::Attention(_) => Err(refuse(format!(
            "layer {l}: a short conv op on a layer of another mixer"
        ))),
    }
}

Non-blocking

⚠ PIN date is in the future: row.rs:115 says PIN(2026-10-29). The review ran on 2026-10-28, and the Qwen pin beside it is 2026-10-28. Use the date the band was measured.

⚠ The lfm3 row has Mutants::None (row.rs:227). --mutants-all is not run for it in just lab-metal-e2e. The body says the cut is red without the conv rings, but only a planted mutant proves it. Name the one mutant run, or add the PR body line that shows it.

⚠ The LFM3_ATTN row is only exercised up to position 3 in the e2e gate, and docs/mac.md says so. The window cut (256 keys) and the rope factors on full layers are not reached by m_logits. A gate row past 256 keys is the next piece of work, not this PR.

Checked

  • Duplicates: about 40 new functions, types and constants checked. One hit (finding 1). The dryer pairs are read: ops.rs:329-348 and the attn_of/delta_of/conv_of accessors in arena.rs share a shape, not knowledge (different variants and buffers). The two half_out functions take different buffer and mode types. The select_gqa_in fallback replaced gqa_row_v with the already filtered width; gqa_row_v keeps its other callers.
  • Complexity: rows_p1 20 → 39 is a branch added to an existing function (the gate split); each branch is a named refusal, and the split to a helper is its own piece of work. select_gqa_in, cut_marked_pass, read_spec are new and complex on their own; I read them for correctness only.
  • Silent failure: 14 sites followed (rope_of, post_gain, no_join, no_conv_y, no_gate_rows, take_point, cut, has_recurrent_store, copies_in_pass, the Key::of refusals, check_strided, argmax_of, parse_pin, the marks branch in target.rs). Each bad input gets a named refusal. A file with conv rings and no checkpoints is refused, not skipped (session.rs no_checkpoints).
  • Hot path: the decode step adds no allocation and no host copy; every format! is on an error path, and check_strided now builds its message on the error path only. The new launches are the sandwich joins (one group per half on a sandwich layer). No kernel file changed, and the body shows metal_scan --compare at added=0 removed=0 changed=0.
  • Tests: mutant checked in words for store_lens_of (drop Held::Conv turns the first test red), extents (drop the offset turns the P1 test red), strided_len (rows * stride turns its test red), select_gqa_in (read GQA instead of table turns its test red), check_strided (delete the u32 refusal turns its test red).
  • Gates: QWEN_LOGIT_ABS 0.01 moved unchanged with its PIN; LFM3_LOGIT_ABS 0.06 is new, with its derivation. No gate removed.
  • Escape catalog: no match (one shell file changed: the justfile recipe adds a --row lfm3 line).

Notes

  • No CUDA evidence applies: this PR changes only the Metal backend and the models shape table. The body gives an Apple M1 Pro run with the gate commands, which I could not re-run.

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

@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 earlier must-fix is fixed, and the new commits (deep pin, LFM3 mutants, pin tooling) leave no failure path I could not block.

Since the last review:

  • Must-fix 1 (conv_of! and conv_of_rows): fixed. One conv_bufs at ops.rs:290, four callers, the macro and the rows copy are gone, and the imports match.
  • ⚠ PIN date: fixed. Both PINs in row.rs say 2026-10-29, the run date.
  • ⚠ lfm3 had Mutants::None: fixed. Mutants::Lfm3 holds three mutants, and the justfile runs --row lfm3 --mutants-all.
  • ⚠ No gate past the 256-key window: fixed. m_logits_deep reads seven steps of a 600-id walk.

Checked

  • Duplicates: 9 new items checked (hold, DEEP_DIR, pin_of(sub), LFM3 table, Mutants::Lfm3, deep_logit_abs, the walk and positions helpers in mlx-logits.py). None duplicated. m_logits is now a thin call into hold, so the two clauses share one loop. The dryer pairs are old code or short same-shape copies from the first review.
  • Complexity: no function the new commits touch is in the crapper list. parse_pin 21 → 31 grew two branches in the first review, and the positions branch added here is a named error for each bad input.
  • Silent failure: 5 sites followed. parse_pin refuses positions that are not increasing, reach past the steps, or disagree with the byte count. The argmax line is checked against the held rows, not the steps. hold skips a step only when the pin names no row for it. dump refuses a non-finite logit and an id outside the vocabulary. --ids with --ids-walk and an empty position list are named errors.
  • Tests (mutation, in words): swa_window_short and swa_window_long protect attention.metal's window start. A 255 or 257 window moves the reference logits by 0.11 to 0.15, above the 0.02 band at steps 256 to 599. shortconv_ring_no_wrap protects shortconv.metal:140. A wrong slot from position 15 turns m_logits_deep red. All three edit strings exist once in the kernel sources. The rope-factors host edit matches arena.rs:394. LFM3_DEEP_LOGIT_ABS equals its cap by assertion, and the measured worst is 6.0e-3.
  • Gates: LFM3_DEEP_LOGIT_ABS 0.02 is new, with a dated PIN and derivation. No gate moved or removed.
  • Hot path: none touched in these commits. The change is a function move, tests and tools.
  • Escape catalog: no match. The justfile adds one recipe line.

Notes

  • No CUDA evidence applies: the PR changes only Metal and the models shape table. The body gives an Apple M1 Pro run, which I could not re-run.

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

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

Labels

documentation Improvements or additions to documentation model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant