Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ converted to ExecuTorch's checkpoint layout by `pipeline/convert.py`.
| Qwen2.5 | `Qwen2ForCausalLM` | yes |
| Llama 3.2, SmolLM2 | `LlamaForCausalLM` | yes (q/k un-permuted for Meta RoPE) |
| Gemma 3, SmolLM3 | `Gemma3ForCausalLM`, `SmolLM3ForCausalLM` | not yet: not in `export_llm`'s model list; needs a validated path (optimum-executorch or params support) |
| LFM3 | `Lfm3ForCausalLM` (remote code) | through `pipeline/lfm3_model.py`: ExecuTorch has no definition, and 1.5.1's transformer cannot express windowed layers, two RoPEs, a per-head gate or sandwich norms (finding 42) |

Smoke test: the Linux wheel ships `TextLLMRunner`, the same C++ runner the app calls
through `LlmModule`. Greedy generation of a short prompt must produce non-degenerate text
Expand Down
1 change: 1 addition & 0 deletions docs/research/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ Findings from building and running this pipeline, each kept with its evidence. C
| 39 | 2026-10-04 | MediaTek | At 16k, LFM2.5 built once no chunk held more than one attention layer; a 4-chunk build with two in some chunks did not. LFM2.5-1.2B-Instruct (attention at layers 2, 5, 8, 10, 12, 14 of 16) at 16k in 4 chunks lost MediaTek's local compiler service while compiling chunk 2, after calibration had finished; its heretic finetune, the same architecture, in 8 chunks (two layers, at most one attention layer each) built and was published: 3,235 s, peak 14,361,923,584 B in use on a 16 vCPU runner. LFM2.5-2.6B (attention at 2, 5, 9, 13, 17, 21, 24, 27 of 30) needs 10 chunks for one attention layer each, and its heretic finetune built at 16k that way: 5,891 s, peak 26,554,892,288 B. Two successes and one failure, so one attention layer per chunk is a working heuristic for these architectures; that it is necessary, and why the compiler service died, are not shown. 32k was started for all three LFM2.5 models (8 and 10 chunks) and cancelled mid-calibration for budget. | measured + inference | run 35994412279 (4 chunks, failed at chunk 2), run 37171790063 (8 chunks, published), run 37176914465 (2.6B-heretic, 10 chunks, 16k published, 32k cancelled); `mtk/mt6991/export-report-16k.json` in `experimentalmachines/LFM2.5-1.2B-Instruct-heretic-ExecuTorch` and `…/LFM2.5-2.6B-heretic-ExecuTorch` | Dispatch 16k with `max_chunks` at the smallest count that leaves one attention layer per chunk (8 for the 1.2B, 10 for the 2.6B); `mtk.max_chunks` stays 4 for the windows that build at it. The successful builds peaked at 13.4 and 24.7 GiB; what killed the failed run's compiler service is not known. LFM2.5-2.6B (base) at 16k and every 32k remain unbuilt. |
| 40 | 2026-10-07 | Runner | The Namespace profile `namespace-profile-execupack` has 4 x86_64 CPUs, MemTotal 16,438,740 kB (15.7 GiB), a 101 GB overlay disk shared by / and /mnt, and no swap: `swapon` on a swap file is refused ("Operation not permitted"), so the 24 to 96 GiB the Blacksmith jobs added cannot be had. Against `sizing.host_need_bytes` and `export_mtk.calibration_bytes` that leaves: Vulkan up to 8k for the 0.1B to 1.2B models (Qwen3-0.6B, Qwen2.5-0.5B, SmolLM2, Llama-3.2-1B) and up to 16k for LFM2.5-1.2B, 2k-4k for Qwen2.5-1.5B, Qwen3-1.7B and LFM2.5-2.6B, nothing at 3B and above; XNNPACK up to 8k for the sub-1B models, 2k-4k for Llama-3.2-1B and LFM2.5-1.2B, nothing from 1.5B up; MediaTek Qwen3-0.6B at 512 only, Llama-3.2-1B to 2k, SmolLM2-135M to 4k, and no LFM2.5 at any window by the current estimate (about 17.4 GiB for the 1.2B). Of the windows built before, every 32k window and every 16k except LFM2.5-1.2B's on Vulkan now fall outside it, as do the MediaTek 16k builds of finding 39. That last is the estimate's call, not a measured limit: `calibration_bytes` puts the 1.2B at about 17.4 GiB from the 14.4 to 15.7 bytes per parameter measured on 4-chunk builds, while the 8-chunk 16k build peaked at 13.4 GiB, which this RAM would hold; refitting the estimate for more chunks could bring the 1.2B back. | measured + estimate | CI run 37606922033 (the runner step); `tests/test_namespace_runner.py` pins the tier and the windows; the coverage is the sizing model's, not exports run on the profile | `config/pipeline.yaml` has the one tier with swap_gib 0; `prepare-host.sh` carries on without swap where it is refused; a model no window fits stops at the targets job instead of failing an empty matrix. The wider windows need a larger Namespace profile added as a second tier. QNN has no tier: its export peaked at 15.6 GB of RSS for Qwen3-0.6B (finding 8), at the edge of this profile. |
| 41 | 2026-10-07 | Runner | Modal runs the XNNPACK and Vulkan exports and the solve. A Sandbox may ask for at most 344064 MiB (336 GiB) and 64 physical cores: larger requests are refused at creation with InvalidError ("memory request must be <= 344064 MiB", "CPU request must be <= 64000 mCPU"), so every window ever built fits, Qwen3-4B at 32k (about 134 GiB) included. Inside a Sandbox /proc/meminfo shows the host's memory (680 GiB to 1.3 TiB), not the request, so the export's own memory gate passes there and the request computed from `sizing.host_need_bytes` is what sizes the run; nproc does reflect the request. SmolLM2-135M at 2k: the Vulkan file came out byte-identical to the published one (sha256 0de5a249...), peaking at 1.9 GiB of a 6.1 GiB request; the XNNPACK file exported and passed the smoke test ("The capital of France is Paris") in the same Sandbox. Both were slower than on Blacksmith: 361 s against 145 s for Vulkan and 1,308 s against 348 s for XNNPACK, though the published files were built with ExecuTorch 1.4.0 and these with 1.5.1, so the runner is not the only difference. | measured | `pipeline/remote.py` runs from this workstation, 2026-10-07 (the sandbox limits probed by request; the two exports with their export reports); the published reports in `experimentalmachines/SmolLM2-135M-Instruct-ExecuTorch` | xnnpack and vulkan runner_tiers are one `modal` tier at Modal's ceiling, each window's memory_mib is its need times modal.memory_margin, and the XNNPACK export, smoke test and decision gate share one Sandbox, so the separate verify job is gone. Per-export time is the open cost question: modal.cpu is 8 cores, and whether more cores or a 1.5.1-to-1.4.0 difference explains the gap is not measured. |
| 42 | 2026-10-31 | XNNPACK | LiquidAI's LFM3-1.7B (`Lfm3ForCausalLM`, remote code only: transformers has no LFM3 and ExecuTorch 1.5.1 none either, the newest release on 2026-10-31) cannot be described by ExecuTorch 1.5.1's transformer: of 24 layers 13 are width-7 gated short convolutions (`ShortConvBlock` hard-codes 3), 6 attend globally with a zero-tail partial RoPE (the first quarter of each head rotated at theta 1e6, frequencies over the full head dimension) and 5 attend over a 256-token window with full RoPE at theta 1e4 (one RoPE table per model upstream; `sliding_window` and `local_rope_theta` are declared in `ModelArgs` and never read), every attention output is gated per head by `sigmoid(gate_proj(x))` (hidden to 16; upstream's `use_attn_o_gate` is per element), and each operator and feed-forward is followed by its own RMSNorm (`post_attention_norm` is declared and never read). `pipeline/lfm3_model.py` builds it from ExecuTorch's parts and is applied in every process that builds the model, as the LFM2 state fix is. The windowed layers keep a ring of window + prefill chunk slots on `update_cache_with_indices` and a masked `custom_sdpa` (upstream's `RingKVCache` holds 2 x window and asserts a chunk fits, which a 2,048-token prefill does not), so no layer holds a full-window cache it cannot use and no window-squared mask exists. On the real checkpoint (ac2586a3) against the checkpoint's own `modeling_lfm3.py`, fp32: without a cache, identical logits over a 559-token app prompt and a 17-token one (max difference 0, top-1 100%); with the cache and export_llm's custom-op transforms, 96-token prefill chunks (the ring wraps), 40 decode steps and a second prompt at position zero, max logit difference 1.8e-4, top-1 100%, KL under 4e-7. The remote config does not load under transformers 5.17.0 (`standardize_rope_params` looks up a RoPE block for every layer type, `conv` included: KeyError); 5.22.1 loads it. | measured + source | `lfm3_check.py` harness (HF fp32 vs the module, no cache and cached); `examples/models/llama/{llama_transformer,model_args,attention}.py` and `examples/models/lfm2/short_conv.py` at v1.5.1 | XNNPACK only (Vulkan has no short-convolution kernel; neither vendor path has a definition). The app has no LFM3 chat template, so the family is exported ahead of it (`naming.AHEAD_OF_APP`) and the model card says so; `-Base` stays unpublished under the chat-only rule, LFM3-VL and the audio models are multimodal. The first published reports counted the 5 windowed layers at a full-window KV cache (1,476,395,008 B at 32k); since eba9368 `sizing` counts them as their fixed ring (852,492,288 B at 32k, 47,185,920 B of it the rings), and `correct-reports` rewrote the five published reports, `config.json` and README in Hub commit fd07e07 without touching a `.pte`. The decision gate first failed all three GPTQ windows on quiet rows: it reads one token, and LFM3's template opens a `<think>` block in the generation prompt, so that token is the first word of the reasoning (fp32 'The' at 0.52 to 0.73 against 'We'), which the 4-bit file tipped the other way on two of four rows without calling anything. Qwen3's published gates had the same blind spot (`<think>` at 0.9999 on every row, `measures_tool_calling` false). With `enable_thinking=False` the prompt ends in `<think></think>`, and fp32's first token is `<tool_call>` at 1.000 on all 12 search rows and the answer on the quiet ones (0.98, 0.99, 0.95; 'Who wrote Pride and Prejudice?' undecided at 0.27); the 32k GPTQ file then keeps 12 of 12 calls at 0.9991 against 0.9998 and 3 of 4 quiet rows, `measures_tool_calling` true. `gate.prompts` now renders with the reasoning switched off for every family; templates without the switch are unchanged, and calibration still renders at the template's default. ExecuTorch 1.6.0-rc1 (tagged 2026-10-30, wheel on PyTorch's test channel, torch 2.15.0) has no LFM3 model either, though its `ShortConv` takes a width: under it the same module matches Hugging Face (identical logits without a cache, 2.1e-4 with the custom-op cache and the ring), and a 2k 8da4w export (1,239,187,968 B, 597 s with the base model's solve on the same CPUs) answers the smoke test through 1.6.0's own runner. Nothing was published from it: the apps ship the 1.5.1 runtime, which `EXECUTORCH_VERSION` keeps every export on. LFM3-1.7B-Base (545fc8f4) was published on request (`--allow-base`; the chat-only default stands for the watcher): its fp32 model puts a newline first on all 12 calling rows (0.71 to 0.86) and is undecided on three of four quiet rows, so its gate tracks fp32 without measuring tool calling, and every window kept 12 of 12 (0.9786 against 0.76) and completed the smoke prefix with ' Paris'. Both repos' ten files match their reports' sha256 on the Hub. |
16 changes: 14 additions & 2 deletions pipeline/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import sys
from pathlib import Path

ALLOW_BASE = "a base checkpoint asked for by name: publish it although only chat models are by default"


def _plan(args) -> int:
from pipeline import eligibility, families, hub, settings, sizing
Expand Down Expand Up @@ -82,7 +84,13 @@ def _solve(args) -> int:
from pipeline import solve as solve_module

report = solve_module.run(
args.model, args.revision, Path(args.out), Path(args.work), damp=args.damp, reference_only=args.reference_only
args.model,
args.revision,
Path(args.out),
Path(args.work),
damp=args.damp,
reference_only=args.reference_only,
allow_base=args.allow_base,
)
print(json.dumps(report, indent=2))
return 0
Expand All @@ -102,6 +110,7 @@ def _export_xnnpack(args) -> int:
skip_smoke=args.skip_smoke,
codes=Path(args.codes) if args.codes else None,
qmode=args.qmode or None,
allow_base=args.allow_base,
)
)

Expand Down Expand Up @@ -425,6 +434,7 @@ def main(argv: list[str] | None = None) -> int:
help="codes.pt from `solve`; without it the int4 weights are rounded to nearest",
)
export.add_argument("--qmode", default="", help="recipe: 8da4w (config default) or fp32 (linears not quantized)")
export.add_argument("--allow-base", action="store_true", help=ALLOW_BASE)
export.set_defaults(func=_export_xnnpack)

verify = commands.add_parser("verify", help="smoke-test an exported .pte on a host whose runner works")
Expand Down Expand Up @@ -456,6 +466,7 @@ def main(argv: list[str] | None = None) -> int:
action="store_true",
help="write only the gate's fp32 reference (gate.json), no codes: for a recipe that is not solved",
)
solve.add_argument("--allow-base", action="store_true", help=ALLOW_BASE)
solve.set_defaults(func=_solve)

vulkan = commands.add_parser("export-vulkan", help="download, convert, export a Vulkan (GPU) .pte")
Expand Down Expand Up @@ -563,7 +574,8 @@ def main(argv: list[str] | None = None) -> int:
watch.set_defaults(func=_watch)

fix = commands.add_parser(
"correct-reports", help="rewrite fp32 reports' recipe and sizing fields on the Hub; never touches a .pte"
"correct-reports",
help="rewrite fp32 reports' recipe fields and windowed models' KV sizing on the Hub; never touches a .pte",
)
fix.add_argument(
"repos", nargs="+", help="output repos, e.g. experimentalmachines/SmolLM2-360M-Instruct-ExecuTorch"
Expand Down
13 changes: 10 additions & 3 deletions pipeline/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,17 @@ def render(tokenizer, prompt: str) -> str:
)


def render_app(tokenizer, user_turn: str) -> str:
"""The same, under the app's system text, tool schema and opening exchange."""
def render_app(tokenizer, user_turn: str, thinking: bool = True) -> str:
"""The same, under the app's system text, tool schema and opening exchange.

``thinking=False`` asks a reasoning template to close its think block in the generation
prompt (``enable_thinking``, which Qwen3's and LFM3's templates read and the others
ignore), so the next token is the answer or the tool call itself. Calibration leaves it
at the template's default and renders exactly as before.
"""
messages = [{"role": "system", "content": APP_SYSTEM}, *APP_PRIMER, {"role": "user", "content": user_turn}]
return tokenizer.apply_chat_template(messages, tools=APP_TOOLS, tokenize=False, add_generation_prompt=True)
extra = {} if thinking else {"enable_thinking": False}
return tokenizer.apply_chat_template(messages, tools=APP_TOOLS, tokenize=False, add_generation_prompt=True, **extra)


def app_head(tokenizer) -> str:
Expand Down
32 changes: 28 additions & 4 deletions pipeline/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,32 @@
"conv.out_proj.weight": "conv.out_proj.weight",
"conv.in_proj.weight": "conv.in_proj.weight",
}
# LFM3 (pipeline/lfm3_model.py): LFM2's operator and feed-forward names, Llama's attention
# names, plus a per-head output gate and the sandwich norms after each operator and each
# feed-forward. HF's post_operator_norm is post_attention_norm here for both layer kinds.
_LFM3_LAYER_KEYS = {
"self_attn.q_proj.weight": "attention.wq.weight",
"self_attn.k_proj.weight": "attention.wk.weight",
"self_attn.v_proj.weight": "attention.wv.weight",
"self_attn.o_proj.weight": "attention.wo.weight",
"self_attn.q_norm.weight": "attention.q_norm_fn.weight",
"self_attn.k_norm.weight": "attention.k_norm_fn.weight",
"self_attn.gate_proj.weight": "attention.gate_proj.weight",
"operator_norm.weight": "attention_norm.weight",
"post_operator_norm.weight": "post_attention_norm.weight",
"ffn_norm.weight": "ffn_norm.weight",
"post_ffn_norm.weight": "post_ffn_norm.weight",
"feed_forward.w1.weight": "feed_forward.w1.weight",
"feed_forward.w2.weight": "feed_forward.w2.weight",
"feed_forward.w3.weight": "feed_forward.w3.weight",
"conv.conv.weight": "conv.conv.weight",
"conv.out_proj.weight": "conv.out_proj.weight",
"conv.in_proj.weight": "conv.in_proj.weight",
}
# One HF tensor that becomes three: the short convolution's fused input projection is stored
# as B, C and x stacked on dim 0, and ExecuTorch's ShortConv reads them apart.
SPLIT_THREE = {"lfm2": ("conv.in_proj.weight", ("conv.B_proj.weight", "conv.C_proj.weight", "conv.x_proj.weight"))}
_IN_PROJ = ("conv.in_proj.weight", ("conv.B_proj.weight", "conv.C_proj.weight", "conv.x_proj.weight"))
SPLIT_THREE = {"lfm2": _IN_PROJ, "lfm3": _IN_PROJ}
# Buffers some checkpoints carry that the model recomputes.
_IGNORED = re.compile(r"(rotary_emb\.inv_freq|\.masked_bias|\.attn\.bias)$")

Expand All @@ -83,12 +106,13 @@
# LFM2 shares none of the per-layer names, so its map replaces rather than extends the
# common one; every layer is a short convolution or an attention block, never both.
"lfm2": (_LFM2_LAYER_KEYS, False),
"lfm3": (_LFM3_LAYER_KEYS, False),
}
# Converters whose per-layer map stands alone instead of extending _LAYER_KEYS.
_STANDALONE = {"lfm2"}
_STANDALONE = {"lfm2", "lfm3"}
# A conv layer and an attention layer carry different tensors, so the per-layer count that
# the other families check cannot apply; LFM2 is checked by total instead.
_MIXED_LAYERS = {"lfm2"}
_MIXED_LAYERS = {"lfm2", "lfm3"}


def unpermute(weight, n_heads: int):
Expand Down Expand Up @@ -118,7 +142,7 @@ def _shards(model_dir: Path) -> list[Path]:
def map_key(hf_key: str, converter: str) -> str | None:
"""ExecuTorch name for an HF tensor, None for ignorable buffers, KeyError if unknown."""
extra, _ = CONVERTERS[converter]
top = _LFM2_TOP_KEYS if converter == "lfm2" else _TOP_KEYS
top = _LFM2_TOP_KEYS if converter in ("lfm2", "lfm3") else _TOP_KEYS
if hf_key in top:
return top[hf_key]
if _IGNORED.search(hf_key):
Expand Down
Loading
Loading