Skip to content

engine: compiled LFM3 support, and LFM3's tool decisions measured on the GGUF and the compiled file - #4

Open
mr-jones123 wants to merge 2 commits into
mainfrom
feat/lfm3-compiled
Open

mr-jones123 wants to merge 2 commits into
mainfrom
feat/lfm3-compiled

Conversation

@mr-jones123

@mr-jones123 mr-jones123 commented Nov 17, 2026 •

Copy link
Copy Markdown

What changed

The app can open a compiled LFM3 (.pte). The compiled path renders its own prompt and had no LFM3 template, so it refused the file.

  • Lfm3Prompt transcribes LiquidAI/LFM3-1.7B's chat_template.jinja. Fixtures rendered from the real template by tools/executorch/render_reference.py hold it byte for byte. The GGUF carries the same template file.
  • PromptTemplate picks LFM3 with a working thinking toggle, and excludes omni builds like the vision ones.
  • PromptJson.asBareToolJson lists a tool as the bare function object, as LFM3's template does.
  • ExecuTorchEngine.underOpener accepts a think opener with no trailing newline, which is how LFM3 writes it (Qwen3.5 writes one).

The findings: docs/research/lfm3-compiled-and-gate.md, with four new result files under tools/eval/results/decisions/.

All 160 questions, one SM8850 unit per run, thinking on, one tool:

Searched when needed, of 75 Searched when not, of 60 Correct, of 117
GGUF, model alone 59 23 60
GGUF, intent rule 74 34 65
GGUF, intent rule and doubt gate 74 34 67
.pte, round to nearest 74 55 71
.pte, GPTQ 74 52 75
  • The compiled LFM3 keeps tool calling where LFM2.5's lost it, without GPTQ, and makes no fabricated search claims.
  • Its failure flips to over-searching.
  • The intent rule closes the GGUF's gap; the doubt gate adds nothing measurable on LFM3.

Checks

  • ktlintCheck detekt test jvmTest pass after the rebase onto main.
  • The compiled files were exercised through the decision suite's instrumented test on QDC, not the chat screen.

Limits

  • One run per arm, and QDC units differ, so gaps of a few questions are not established.
  • The compiled times were taken throttled and are not compared.

🤖 Generated with Claude Code


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

mr-jones123 and others added 2 commits November 17, 2026 11:11
… compiled path had no LFM3 template and refused the file

Lfm3Prompt transcribes LiquidAI/LFM3-1.7B's chat_template.jinja: tools as bare function
objects inside <tools> at the foot of the system turn, XML call parameters, results in
<tool_response> under a tool role, and a think tag on every assistant opener. Fixtures from
render_reference.py hold it to the real template byte for byte; the GGUF carries the same
file. underOpener now accepts an opener with no trailing newline, which is how LFM3 writes
it. "omni" builds are excluded like the vision ones.

On an SM8850 through the decision suite, both published 8da4w files opened and called the
tool on 74 of 75 questions that need a search; see docs/research/lfm3-compiled-and-gate.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st it and searches too often instead, and the app's intent rule closes the GGUF's gap, because the shipped search rules and the compiled file were unmeasured on LFM3

All 160 questions, one SM8850 unit per run, thinking on. Searched when needed, of 75: GGUF
alone 59, with the intent rule 74, with the doubt gate too 74; compiled round to nearest
74, GPTQ 74. Searched when not needed, of 60: 23, 34, 34, 55, 52. No fabricated search
claims in any run. Correct of 117: 60, 65, 67, 71, 75. One run each; compiled times were
taken throttled and are not compared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alpharomercoma alpharomercoma self-assigned this Nov 17, 2026
@alpharomercoma alpharomercoma added the enhancement New feature or request label Nov 19, 2026

@alpharomercoma alpharomercoma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this. The code side is in good shape. The fixture tests match the reference renders byte for byte for the cases they cover, the branch merges cleanly onto main 81734de, and ktlintCheck detekt test jvmTest pass on the merge. I also ran the debug build on a 16 KB Android 16 emulator through the chat screen, which the PR notes was not done: the GPTQ export answered "What is the capital of France?" and the follow-up "And of Italy?" in the same chat.

The changes I'm asking for are all in the research note. The engine problems this turned up are mine to fix, listed at the end.

1. The accuracy comparison credits unfinished thinking

grade_decisions.py credits an alias anywhere in answer. On the compiled path, a final pass that hits the 600-token cap while still thinking has no </think>, so answer is the reasoning itself, and an alias it mentions along the way counts as correct.

In each compiled run, 69 of 160 final passes stopped at the cap, and 60 of those were still inside the think block. In the GGUF intent and gate runs, one final pass hit the cap; it had already closed its thinking and is outside the 117 graded questions because of stale risk. Among the 117 graded:

Run Correct as published Final pass cut at the cap Of those, credited
GGUF, model alone 60 10 4
.pte, round to nearest 71 42 14
.pte, GPTQ 75 44 19

Here a reply counts as unfinished when its last pass stopped at MAX_TOKENS and raw has no </think>. Unfinished replies get no credit but stay in the denominator. Every other reply keeps the grader's result, and "known" is need == false. This is a mechanical correction, not a hand audit of the answers:

GGUF alone .pte RTN .pte GPTQ
Correct, of 117 57 58 59
Correct where it was known, of 60 45 44 43

Grading every cut-off as wrong instead gives 56, 57 and 56 (known: 45, 43, 42). Under either rule, the compiled lead of 11 to 15 shrinks to between 0 and 2, and the known-question gap of 53 against 45 goes away. One run per arm cannot show an advantage or equivalence either way, and the GGUF baseline also ran on an earlier build with a different system prompt (its system_sha1 differs from the compiled runs'). So "Correct on those known questions did not drop (53 against 45), so the cost is time and egress, not accuracy" does not hold.

In the note, could you:

  • regrade with unfinished thinking getting no credit, and update the Results table and the paragraph under it;
  • add a row for final passes cut at the cap, per arm.

This is a change to the note's analysis only, not to grade_decisions.py.

The regrade script
"""Regrade decision rows three ways. A reply is unfinished when its last pass stopped at
MAX_TOKENS and `raw` has no </think>. Rows with stale_risk are left out, as the note does."""
import sys, json, os, importlib.util
spec = importlib.util.spec_from_file_location("g", sys.argv[1])
g = importlib.util.module_from_spec(spec); spec.loader.exec_module(g)
for f in sys.argv[2:]:
    rows = [json.loads(l) for l in open(f) if l.strip()][1:]
    t = {"published": [0, 0], "unfinished gets no credit": [0, 0], "every cut-off wrong": [0, 0]}
    n = [0, 0]
    for r in rows:
        ok = g.grade_row(r)["correct"]
        if ok is None or r.get("stale_risk"): continue
        cut = bool(r["passes"]) and r["passes"][-1]["stop"] == "MAX_TOKENS"
        unfinished = cut and "</think>" not in r["raw"]
        for i in (0, 1):
            if i == 1 and r.get("need") is not False: continue
            n[i] += 1
            t["published"][i] += bool(ok)
            t["unfinished gets no credit"][i] += bool(ok) and not unfinished
            t["every cut-off wrong"][i] += bool(ok) and not cut
    print(f"{os.path.basename(f)}, of {n[0]} (known, of {n[1]}):")
    for k, v in t.items(): print(f"  {k}: {v[0]} ({v[1]})")

python3 -I regrade.py tools/eval/bench/grade_decisions.py tools/eval/results/decisions/qdc-full-decisions-LFM3-1.7B-Q4_K_M-driven-search-think.jsonl tools/eval/results/decisions/qdc-sm8850-pte-decisions-*

2. Report the generation errors

The GPTQ run has 2 generation errors out of 160, both ExecutorchInvalidArgumentException: [ExecuTorch Error 0x12] Invalid argument: Failed to generate after three searches: "Who won the gold medal for the men's super heavyweight boxing?" and "What is the youngest age eligible for COVID-19 vaccination in the United States?". The first counts as a failure among the 117 graded; the second is excluded for stale risk. grade_decisions.py already flags errors, and the note just doesn't show the count. Could you report it separately, keeping the existing denominator?

The same visible error came up on the emulator. With default settings and the 4k GPTQ file, I asked three questions from your rows that had run out of tokens while thinking. This table records what happened, not whether the answers were right:

Question .pte GPTQ, 4k GGUF Q4_K_M, 32k LFM2.5 .pte, 4k
In what country is Malay? replied about the language after 1 search and 2 page fetches; context shown 100% not run not run
What genre is Inna? Error 0x12 during the sixth generation pass; context shown 97% replied; 8% replied; 34%
In what country is Home? Error 0x12 during the sixth generation pass, after 4 searches and a skipped fetch; context shown 91% asked for clarification; 4% replied; 24%

In both failures the runtime log reads start_pos: 4096 must be less than cache size at dim 1: 4096: the 4k cache was full, whatever the percentage on screen said. The Inna run showed its unfinished reasoning above the raw error. The benchmark rows only hold the generic exception, so they don't show whether those two failures had the same cause. A line under Limits would cover it: on the emulator, the 4k export overran its cache on two of three multi-search questions. Larger exports were not tried in this check.

Optional

The new omni substring exclusion rejects names such as Qwen3-1.7B-OmniQuant.pte. Consider narrowing it while still refusing the Omni variants it is meant for.

On my side

I'll handle the engine work in a separate PR:

  • the compiled path ignores the reasoning budget;
  • generation can overrun the remaining cache and surface the raw Error 0x12, as these runs show;
  • a thought that never closes is shown as the answer when the template supplies the thinking opener, as LFM3 and Qwen3.5 do.

None of it is caused by this PR. For this review, the requested changes are the two above.

@mr-jones123

Copy link
Copy Markdown
Author

Thanks, and every one of your three points stands. I could not do the note-only change, because the note and the engine bug are the same fact: what the .pte arms scored was the reasoning budget they did not have, so regrading would have described a strawman from then on. The branch below has the mechanism and a rerun.

The engine change (fb6184a2, on fix/executorch-budget-lfm3, stacked on this branch). ThinkingGate counts tokens while a thinking block is open, opening from the template's opener or from a tag the model writes, closing on the close tag, never resetting, so a reopened block trips on its first token. At the budget TurnRunner.deciding() already sets (128), closeThinkingBlock writes the C++ session's note and </think> into the cache and into the reply, re-feeding the last fragment first because a sampled token only enters the cache when it is fed back, and hands the close to the next pass as its prompt. Your three items are all in it: the budget is honoured; a block the engine closed parses as an answer, so a thought cannot land in the reply field; and each pass is clamped to the room the window has left, which is the start_pos: 4096 error by name, now a context-full the turn loop can act on rather than a raw failure.

Your regrade, on the old rows, your script and your rule: GPTQ 75 to 59 of 117, RTN 71 to 58, GGUF alone 60 to 57. Every cut-off wrong gives 56, 57 and 56. Same conclusion as yours.

The rerun, with the fix. 160 questions per arm, driven-search-think, one SM8850 unit, same sha1(system) 2113d0bdcd0b as the published compiled rows, identical question ids.

GPTQ before GPTQ after RTN before RTN after
rows where the engine wrote the close 0 109 0 114
final pass at the cap 69 1 69 4
cut mid-thought 60 0 60 0
generation errors 2 0 0 0
correct, as published 75 69 71 67
correct, unfinished gets no credit 59 69 58 67
correct where the answer was known, of 60 43 52 44 51
replies that quoted the instructions 8 0 9 0
median seconds a row 45.3 16.1 36.4 14.7
median thermal status 5 3 5 5

Your two errors are gone: the boxing and the COVID vaccination rows now close their block and answer (359 and 584 characters). "What genre is Inna?", which returned Error 0x12 twice on your emulator check, closes at the budget and answers in four passes.

What this does not settle. The GGUF arms are not rerun, and you were right about the baseline: its header carries sha1(system) 8b39106a against 2113d0bd on all four other arms, and its prompt is the older "You already know the answer to most questions" text. So the table above is compiled-only, and I would rather rerun GGUF on this build than publish a two-engine claim through a stale prompt. One run per arm, one unit. The GPTQ timing is not comparable (thermal 5 before, 3 after); RTN's is (5 and 5). One GPTQ row and four RTN rows still end at the output cap, turns where the block never opened, so there was nothing to interrupt. The omni exclusion is untouched, that is template routing and not the engine.

For this PR: I would take the note rewrite here in the shape you asked for (regraded table, cut-at-cap row, errors reported separately), and leave the engine change as its own PR against main. The branch is pushed and I will open that PR when you say so.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants