Skip to content

LFM3: XNNPACK exports through an LFM3 definition ExecuTorch 1.5.1 lacks - #23

Merged
alpharomercoma merged 8 commits into
mainfrom
lfm3
Oct 31, 2026
Merged

alpharomercoma merged 8 commits into
mainfrom
lfm3

Conversation

@alpharomercoma

@alpharomercoma alpharomercoma commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Why

LiquidAI released LFM3-1.7B on 2026-10-23. Neither transformers nor ExecuTorch 1.5.1, still the newest release, implements it, and 1.5.1's transformer can't express it:

  • 5 of its 24 layers attend over a 256-token window.
  • It uses two RoPEs: a zero-tail partial RoPE at theta 1e6, and full RoPE at theta 1e4.
  • Every attention output gets a per-head sigmoid gate.
  • Every operator and feed-forward is wrapped in sandwich norms.
  • Its convolution is 7 wide, where upstream's ShortConvBlock is fixed at 3.

What

  • pipeline/lfm3_model.py: the LFM3 model, built from ExecuTorch's own RMSNorm, FeedForward, KV cache and SDPA modules, which export_llm swaps for its custom ops. The windowed layers keep a ring of window + prefill-chunk slots on update_cache_with_indices and a masked custom_sdpa. It is applied in every process that builds the model (export_with_codes --lfm3, the solve), the same way as the LFM2 state fix.
  • families, convert: the lfm3 family (XNNPACK only) and its tensor names.
  • naming, eligibility: families exported ahead of the app's chat template (AHEAD_OF_APP). Neither app has an LFM3 template yet, so they refuse these files by name, and the model card says so. The Kotlin port itself is unchanged.
  • solve, hub: the fp32 teacher runs remote code only from LiquidAI's own repos, only with auto_map entries that point at local modules, and only with local_files_only.
  • transformers 5.22.1: LFM3's remote config fails to load under 5.17.0 (KeyError: 'conv').

Evidence (finding 42)

On the real checkpoint (ac2586a3), fp32, compared with the checkpoint's own modeling_lfm3.py:

Path Max logit difference Top-1 agreement
No cache (what the solve sees), 559- and 17-token prompts 0 100%
KV cache with the custom-op transforms; 96-token chunks that wrap the ring, 40 decode steps, reset to a new prompt 1.8e-4 100%
fp32 .pte through the C++ runtime (int8 embedding) max KL 0.006 100% at every position, reset included

The fp32 2k .pte passed the smoke test through TextLLMRunner: it reasoned, then answered "Paris".

Tests

327 passed. The new tests are in tests/test_lfm3.py. ruff is clean.

The GPTQ builds at 2k to 32k run on an EC2 box and publish to experimentalmachines/LFM3-1.7B-ExecuTorch.

🤖 Generated with Claude Code


View with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is enabled.

alpharomercoma and others added 4 commits October 31, 2026 14:01
…finition and its transformer cannot express one

LiquidAI's LFM3-1.7B keeps LFM2's gated short convolutions and adds windowed attention
layers, a second RoPE (theta 1e6 zero-tail partial on the global layers, 1e4 full on the
windowed ones), a per-head sigmoid output gate, sandwich norms and a width-7 convolution.
pipeline/lfm3_model.py builds it from ExecuTorch's own parts (RMSNorm, FeedForward, the KV
cache and SDPA that export_llm swaps for its custom ops) and keeps the windowed layers' keys
in a ring of window + prefill chunk slots. On the real checkpoint it matches the remote
modeling_lfm3.py exactly on fp32 logits without a cache, and to 1.8e-4 with the custom ops,
chunked prefill over the ring, 40 decode steps and a reset.

- families/convert: the lfm3 family (XNNPACK only) and its tensor names
- naming/eligibility: families exported ahead of the app's chat template (the app has none
  for LFM3 yet and refuses such files by name); the Kotlin port is unchanged
- solve/hub: the fp32 teacher loads remote code for LFM3, downloaded at the pinned revision
- transformers 5.22.1: LFM3's remote config does not load under 5.17.0 (KeyError: 'conv')

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…definition as finding 42

A finetune with LFM3's auto_map would otherwise have its own modeling code executed by the
solve's fp32 teacher. remote_code_allowed admits a trusted publisher whose every auto_map
entry is a module in the pinned snapshot (no repo--module references), and the teacher
loads with local_files_only. PLAN's XNNPACK table and research finding 42 carry the
measurements against modeling_lfm3.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… first token is not its decision

The gate reads one token. LFM3's template opens <think> in the generation prompt, so that
token was the first word of the reasoning ("The" or "We", fp32 at 0.52 to 0.73), and the
4-bit LFM3 files failed on quiet rows where they opened the reasoning with the other word
and called nothing. Qwen3's gates were blind the other way: <think> at 0.9999 on every row.
With enable_thinking=False the prompt ends in <think></think> and the next token is the
answer or <tool_call> (LFM3 fp32: <tool_call> at 1.000 on all 12 search rows). Templates
without the switch render as before; calibration is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing, not eleven full caches

LFM3's five sliding-window layers keep window + prefill chunk slots (pipeline/lfm3_model.py)
at any context, so the first reports put the 32k cache at 1.48 GB where it is 0.85. The
per-token figure now counts the six full caches (24,576 B), the ring is its own report field
(kv_cache_ring_bytes, 47 MB), and the card states both. Only LFM3 is sized this way: Gemma 3's
configs name sliding layers too, and nothing here rings them. correct-reports fixes the
published reports' figures in place, refusing any it cannot reproduce from the old sizing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alpharomercoma

Copy link
Copy Markdown
Member Author

Results

Built on an EC2 r7i.4xlarge (16 vCPU, 123 GiB) that published to Hugging Face itself and then stopped. All five windows are in experimentalmachines/LFM3-1.7B-ExecuTorch, and every file's sha256 on the Hub matches its export report.

Window .pte Export Peak RSS Smoke Gate (tool calls kept) Decode on the host
2k 1,239,210,240 B 485 s 9.0 GiB passed 12/12, 0.9991 against fp32's 0.9998 21.8 tok/s
4k 1,241,307,392 B 484 s 9.1 GiB passed 12/12 37.9 tok/s
8k 1,245,501,696 B 498 s 9.3 GiB passed 12/12 35.2 tok/s
16k 1,253,890,304 B 493 s 9.3 GiB passed 12/12 25.0 tok/s
32k 1,270,668,160 B 493 s 9.7 GiB passed 12/12 43.2 tok/s

The GPTQ solve covered 180 linears in 644 s.

Two further commits on this branch came out of the run:

  • 6ee6b36, the gate: it now renders its prompts with reasoning switched off. As written it graded a thinking model's first reasoning word ("We" against "The"), which failed all three GPTQ windows on quiet rows where nothing was called. Qwen3's published gates were uninformative for the same reason. With <think></think> in the prompt, LFM3's fp32 puts <tool_call> first at 1.000 on every search row, and measures_tool_calling is now true.
  • eba9368, sizing: the five sliding-window layers are counted as their fixed ring. The 32k KV cache is 852,492,288 B, not 1,476,395,008 B. correct-reports --apply fixed the five published reports, config.json and the README in Hub commit fd07e07, with no .pte changed.

Tests: 330 passed. ruff is clean.

🤖 Generated with Claude Code

alpharomercoma and others added 4 commits October 31, 2026 14:57
…which superseded its full-cache caveat

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…let a named base checkpoint through on request

Quiet rows now follow the rule the calling rows already had: a row fp32 itself splits says
nothing about a regression (LFM3-1.7B on Pride and Prejudice at 0.27; LFM3-1.7B-Base on three
of four at 0.09 to 0.39). verify marks a base checkpoint's gate as not measuring tool calling:
LFM3-1.7B-Base puts a newline, not a call, first on every calling row.

--allow-base on solve and export-xnnpack publishes a base checkpoint someone asked for by
name; the watcher never passes it, so the chat-only default stands for everything it finds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion matches and exports but nothing ships until the apps move

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… finding 42 records LFM3-1.7B-Base

The card told a reader of LFM3-1.7B-Base to render prompts with its chat template, which is
the wrong advice for a model not trained on chat turns. It now opens by saying what a base
checkpoint is; the published card was regenerated from its reports (Hub commit c2e3f94).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alpharomercoma
alpharomercoma merged commit 9836623 into main Oct 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant