Repository navigation
engine: compiled LFM3 support, and LFM3's tool decisions measured on the GGUF and the compiled file - #4
engine: compiled LFM3 support, and LFM3's tool decisions measured on the GGUF and the compiled file#4mr-jones123 wants to merge 2 commits into
Conversation
… 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
left a comment
There was a problem hiding this comment.
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.
|
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 The engine change ( 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,
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 What this does not settle. The GGUF arms are not rerun, and you were right about the baseline: its header carries 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 |
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.Lfm3PrompttranscribesLiquidAI/LFM3-1.7B'schat_template.jinja. Fixtures rendered from the real template bytools/executorch/render_reference.pyhold it byte for byte. The GGUF carries the same template file.PromptTemplatepicks LFM3 with a working thinking toggle, and excludesomnibuilds like the vision ones.PromptJson.asBareToolJsonlists a tool as the bare function object, as LFM3's template does.ExecuTorchEngine.underOpeneraccepts 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 undertools/eval/results/decisions/.All 160 questions, one SM8850 unit per run, thinking on, one tool:
.pte, round to nearest.pte, GPTQChecks
ktlintCheck detekt test jvmTestpass after the rebase onto main.Limits
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is enabled.