Repository navigation
metal/model-hf: LFM3 MLX folder map, pins, and the Metal kernels (M0+M1) - #932
Conversation
…el (true,false,true) and LFM3's extra config keys minimax_encode's every_pre_row_has_a_hugging_face_reading stays red until crates/tokenizer gives lfm2 a reading. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
… the shared tie rule Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
… output gate, and the gate-only lfm3_attn row (head 128, group 4) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
…f64 oracle, and their mutants Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
…rm(out)) on the weighted RMS norm's body Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
…r slot), its f64 oracle, clauses and mutants Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
…ernel; each norm and sandwich mutant edits the kernel its clause tests Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
…more line, for the kernel gate's LFM3 attention row Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
…it (redundant_clone) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
… its map makes none Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
… clone (redundant_clone, now deny) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
…uts into the bad copies (redundant_clone) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
There was a problem hiding this comment.
Verdict: MUST_FIX: the encode path now allocates per launch, and helper sets are copied inside the metal gate crate.
Must fix
1. The host encode path allocates a Vec per launch (R39)
norm.rs:137, attention.rs:329, shortconv.rs:222. Before this PR the argument words were stack arrays (args_bytes, pack). Now with_window does words.to_vec() on every flash, rows and prefill launch, even with no window. encode_norm builds two Vecs per norm_rows call. shortconv_step collects pos into a Vec. Term: attention_flash is the decode launch (arch/qwen3moe/ops.rs:316), so qwen3moe decode gains 1 allocation per layer per token; norm_rows gains 2 per call. R39: a step does not allocate. The fix is cheaper now, before M2 wires the session on these functions.
Fix: keep fixed arrays and send a prefix. For the norm:
let words = [
word(what, "cols", p.cols)?,
p.layer,
p.eps.to_bits(),
word(what, "the x stride", p.x_stride)?,
word(what, "the y stride", p.y_stride)?,
add.map_or(0, f32::to_bits),
];
let args = words.map(u32::to_ne_bytes);
let sent = &args[..5 + usize::from(add.is_some())];
// ...
slot.set(Binding::bytes(sent.as_flattened())?)?;For attention, make with_window return a fixed array and a count, and bind &words[..len].as_flattened(). For shortconv_step, fill a [u8; 4 * MAX_SLOTS] and bind its first 4 * slots bytes.
2. Copied helpers in the metal gate (one owner per fact)
Ev,Ev::zero,Ev::exact,mul,fma: oracle_shortconv.rs:51 copiesoracle_delta.rs:56-105line for line. They are the error-bound arithmetic of the f64 referee. If one copy is corrected, the other keeps the old bound and its gate stays green. Fix: move the five items toshared/oracle.rs(it ownsU) aspub(crate), anduse super::oracle::{Ev, fma, mul}in both.ratio: clauses_window.rs:646 equalsclauses_rows.rs:1085. Keep one incommon.rs.strided: clauses_shortconv.rs:813 isstrided_rows(clauses_rows.rs:1371) with apadargument. Keep thepadform incommon.rs, passf32::NANfrom rows.
Non-blocking
⚠ Future-dated pin: model-tax.tsv:140 adds PIN(2026-10-29) for the lfm instance row. The other rows added in this PR say 2026-10-28. Use the date the pin is made.
⚠ The widened post_processor list at vocab.rs:220 (byte_level!(true, false, true)) is a loosened gate. The PIN(2026-10-28) line in the test names ignore_merges and extra_special_tokens only. Name the post-processor there, with the evidence that LFM3's file spells it so.
Checked
- Duplicates: about 40 new items checked. Dryer pairs: the three in finding 2 are real.
Kind::labelandheadershare a shape only. - Complexity: crapper's large functions are all new; case tables, old bodies with a layer argument, or even growth. No split asked.
- Silent failure: 9 sites followed (
tied,check_head,ignore_merges,partial_rotary_factor,planned_constant, the squeeze check, window 0, head-gate length, ring rows). Each reaches a named error or the fault word. - Kernels: the window clauses hold; a prefill tile before the first live key has
factor0, so no NaN. - Tests: three planted mutants (
check_head,ignore_merges, constant collision) turn red. The Metal clauses were not run here. - Gates:
ignore_merges, the post-processor andextra_special_tokensare widened (⚠ above). No band moved. - Escape catalog: no match.
Notes
- The PR body has no
nvidia-smiline and nojust gate-*output from a CUDA card. The PR touches no CUDA crate.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
…ck array, so no launch allocates Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
…ner in oracle.rs; ratio and strided one in the kernel gate's common.rs Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
…ocessor LFM3's tokenizer.json spells Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd
|
Review fixes:
Evidence on the second Mac:
|
There was a problem hiding this comment.
Verdict: CLEAN: both earlier must-fix items are fixed in the new commits, and the new lines hold on every input I built.
Since the last review:
- Must fix 1 (a
Vecper launch, R39): fixed.LaunchArgsin attention.rs:328 is a fixed array plus a length.encode_normin norm.rs:141 sends a prefix of a stack array.shortconv_stepin shortconv.rs:222 fills a stack array and bindspos[..slots]. - Must fix 2 (copied helpers): fixed.
Ev,mul,fmalive inoracle.rs;ratioandstridedlive incommon.rs. Grep finds one definition of each. - ⚠ Future-dated pin: still open, model-tax.tsv:140 still says
PIN(2026-10-29). The other rows say 2026-10-28. Use the date the pin is made. - ⚠ Post-processor pin: answered. The
PIN(2026-10-28)comment invocab.rsnow names the(true, false, true)post-processor and why it acts on no text.
Checked
- Duplicates: 4 new items checked (
LaunchArgs,MAX_ARG_WORDS,SHARED_WORDS, the moved helpers). No duplicate remains.Evispub(crate)inoracle.rs, and both probe bins that include it already carryallow(dead_code). - Complexity: no function in the new commits grew by branches.
bind_flashgrowth is the earlier even growth, and the new commits only change the argument type. - Silent failure: 3 sites followed.
with_windowhas a const assert thatN < 12, so a 12th word cannot overflow. Inshortconv_step,slots > MAX_SLOTSis refused beforepos[..slots], and the zip cannot truncate becauseslots = p.pos.len(). In the norm,add: Nonesends 5 words as before, andSomesends 6. - Performance: the decode launch no longer allocates. The shortconv step zeroes a 4 KiB stack array per call (
MAX_SLOTS= 4096 / 4 words) and binds4 · slotsbytes. No heap term. - Tests: no test changed in these commits except call-site moves to
common::stridedandcommon::ratio. Mutant: a wrongpadat a call site would still turn the NaN-poison clauses red. - Gates: no band, tolerance or lint level moved in the new commits.
- Escape catalog: no match.
Notes
- The PR body has no
nvidia-smiline and no CUDAjust gate-*output. The PR touches no CUDA crate. The Metal gate runs on the author's Mac were not run here.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
LFM3-1.7B on Metal, first two steps (M0 and M1 of the LFM3 plan). The leader's C0 (#924) and C1 (#930) are the CUDA and common side. Metal opens MLX folders only.
M0: the MLX folder and the HF tokenizer path
model-hf/src/arch/lfm3.rs: a new folder map forLiquidAI/LFM3-1.7B-MLX-4bit.[2048,7,1]become[7,2048].rope_freqs.weightis made with the converter's exact values (32 × 1.0, then 32 × 1e30).folder.rsandpart.rsgain made constant tensors (Make::Constant).trunk.rsgets a shared tie rule.tie_word_embeddingsis held against the absence oflm_head, and either mismatch is a named error. qwen35moe and minimaxm3 still refusetrue.hf/src/vocab.rs:lfm2pre-tokenizer row (llama3 regex,ignore_mergesheld to the row);(true,false,true)post-processor;tools/mlx-logits.pydumps an lfm3 folder through mlx-vlm'slfm3(mlx-lm has none yet). The pin starts at BOS 124894: id 0 makes this model degenerate in mlx-vlm itself.M1: Metal kernels, against an f64 oracle with mutants
shortconv.metal:C ⊙ conv(B ⊙ x)for any number of taps (7 for LFM3, 3 for LFM2.5), with a ring ofuper slot. It has decode, rows and a ring commit.norm_add_rows: the sandwich residualx += add · gain ⊙ rms_norm(out), with the norm's sum order.[p−w+1, p]) on decode, rows and prefill;OutGate::ProjHead);lfm3_attn(head 128, group 4,opens: false) carries the kernel clauses until M2 wires the session.Program identity. Existing programs are unchanged: a metal-compare against the base gives pipelines
added=4 removed=0 changed=0 same=195, and the encode traces and generated ids at depth ~0 and 600 are identical.Evidence
cargo test -p bloomery-hf -p bloomery-model-hf: all ok;gate_metal_qwen35moe_kernels: 6 instances PASS;--mutants-all: every mutant red on its clause (qwen35moe_a3b 187, qwen3moe_a3b 83, lfm3_attn 18, and the rest);just remote-static origin/main: every step rc 0.affectedselected 19 gates; 8 ran, red 0. Seven were deferred to the real tier and four for an env.gate-hf-minimaxandgate-minimax31-folderwith/models/MiniMax-M3.1-Flash: both green.gate-hf-vocab-qwen38andgate-prepare-corpusstay deferred: the box has no Qwen3.8 NVFP4 HF folder.Also here:
metal_scan.rs:567was red on main under the Mac's clippy sinceredundant_clonebecame deny (lints: seven lints the mac crates cleared become deny #922). The Linux cross lint does not build the metal crate. Nowcargo clippy -p bloomery-metal --all-targetsis 0 on the second Mac.nemotron_h.rstests get theMake::Constantarm;tools/model-tax.tsvgets an lfm row for the Metal instance table.AI use: written and checked with Claude Code.
🤖 Generated with Claude Code
https://claude.ai/code/session_01X1hsQfNpqr2jqmpYe8SFXd