patch-template: a template from before the lean level keeps no choice

Since v1.18.7 a run that does not set LEAN_DEFAULT keeps the default the
installed template has, so that a box installed with LEAN_DEFAULT=0
stays on xhigh. It read that choice from default('xhigh') alone. A
template written before v1.13 has no lean level and defaults to xhigh,
the one default there was: it chose nothing, and a box updated from
there to v1.18.7 or later stayed on xhigh without anyone asking for it.
A user's box did (2026-10-05), and every bench.sh probe measured other
text than the reference box's, 10 to 16% slower on code and reasoning.

Only a template that offers the lean level and still defaults to xhigh
is a kept choice now; one without the level gets the current default,
and the run says so. Reproduced with the patch-template.py of v1.12.1 on
the reference box's checkpoint (edp1096 abliterated NVFP4 @21565d38):
its template, then the script of v1.22.6, gave xhigh (md5 f6c09ac8);
with this one, lean (md5 30454bff, the reference box's own), then
unchanged on the next run. A template written with LEAN_DEFAULT=0 still
keeps xhigh, and the reference box's lean template is left as it is.

On a box that had such a template, the update rewrites it, so the
engine that reads it restarts once to serve lean. Three tests in
test_patch_template_default_kept.py, and five mutants of the new lines
are each caught. LEAN.md says what is kept, and what is not a choice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hasan BasbunarandClaude Opus 5.5 committed 2026-10-05 13:19:41 +02:00
1 parent a74e0a78fa
commit dbe7cfa9ad
3 files changed
+54 -5

No files matched your search

+4 -1
View File
@@ -185,4 +185,7 @@ context, temperature 0.7, top_p 0.95, max_tokens 16,000. 7,008 runs in total.
`LEAN_DEFAULT=0 ./install.sh` installs the level without making it the default,
for a box that would rather keep Qwen's shipped behaviour until it has run its
own numbers.
own numbers. The choice is kept: a later `./install.sh` or switch that does not name
it leaves the default as it is, and `LEAN_DEFAULT=1 ./install.sh` moves it back. A
template written before v1.13, which had no lean level and defaulted to xhigh, made no
choice: since v1.22.7 the next run gives it lean.
+16 -4
View File
@@ -60,6 +60,8 @@ EFFORT_PATCHED = (
# DEFAULT moves, which is what every client that sends nothing receives.
# LEAN_DEFAULT=0 keeps Qwen's xhigh default while still offering the level.
LEAN_INSTRUCTIONS = "Answer immediately, with no reasoning, whenever the request asks for something you can simply write down: a rename, a reformat, a definition, a lookup, a single concrete edit. Reason only when producing the answer needs steps you cannot skip.\n\nIf the request is underspecified, pick the most common sensible interpretation, state it in one line, and proceed. If you notice yourself checking something twice, or weighing the same options again, stop there and commit."
# What a template that offers the lean level holds, and one written before v1.13 does not.
LEAN_MARKER = "'lean' %}"
LEAN_ANCHOR = " {%- if resolved_reasoning_effort == 'xhigh' %}\n"
LEAN_PATCHED = (
" {%- if resolved_reasoning_effort == 'lean' %}\n"
@@ -128,7 +130,14 @@ def main() -> None:
# every run, so a box installed with LEAN_DEFAULT=0 went back to lean at its next
# ./install.sh or cockpit Switch, neither of which passes it (found in review,
# 2026-09-24). LEAN.md presents it as a kept choice.
# A template can only keep a choice it was able to make: one written before v1.13 has
# no lean level and defaults to xhigh, the one default there was, so it chose nothing,
# and read as LEAN_DEFAULT=0 it kept a box updated from there on xhigh without anyone
# asking for it (a user's box, 2026-10-05: every bench.sh probe measured other text).
# Only a template that offers lean and still defaults to xhigh was installed with
# LEAN_DEFAULT=0.
asked = os.environ.get("LEAN_DEFAULT")
installed, why = "", ""
if asked is not None:
lean_default = asked != "0"
else:
@@ -137,15 +146,18 @@ def main() -> None:
installed = f.read()
except OSError:
installed = ""
lean_default = "reasoning_effort|default('xhigh')" not in installed
has_lean = LEAN_MARKER in installed
lean_default = not (has_lean and "reasoning_effort|default('xhigh')" in installed)
if installed:
why = (" (kept from the installed template)" if has_lean
else " (the installed template predates the lean level and chose nothing)")
effort_patched = EFFORT_PATCHED.replace("@@DEF@@", "lean" if lean_default else "xhigh")
msg_patched = MSG_PATCHED.replace("@@LEVELS@@", MSG_LEVELS[lean_default])
print(f"default reasoning effort: {'lean' if lean_default else 'xhigh'}"
+ ("" if asked is not None else " (kept from the installed template)" if installed else ""))
print(f"default reasoning effort: {'lean' if lean_default else 'xhigh'}{why}")
for name, anchor, patched, marker in (
("reasoning_effort", EFFORT_ANCHOR, effort_patched, "'minimal'"),
("lean", LEAN_ANCHOR, LEAN_PATCHED, "'lean' %}"),
("lean", LEAN_ANCHOR, LEAN_PATCHED, LEAN_MARKER),
("effort-message", MSG_ANCHOR, msg_patched, "Supported types are lean"),
("system-reminder", SYSTEM_ANCHOR, SYSTEM_PATCHED, "<system-reminder>"),
):
+34
View File
@@ -6,6 +6,10 @@ read the choice from the environment of each run, and neither a plain ./install.
the cockpit's Switch passes it, so a box installed with LEAN_DEFAULT=0 went back to lean at
the next of either; LEAN.md presents it as a kept choice. And the refusal of an unknown
level said "lean (default)" whatever the default was (found in review, 2026-09-24).
A template written before v1.13 has no lean level and defaults to xhigh, the one default
there was: read as a kept LEAN_DEFAULT=0, it held a box updated from there on xhigh without
anyone asking for it (a user's box, 2026-10-05). It chose nothing, and gets the default.
"""
import importlib.util
import os
@@ -40,8 +44,19 @@ class TheDefaultIsKept(unittest.TestCase):
r = subprocess.run([sys.executable, str(SCRIPT), str(self.base), str(self.out), SHA, REPO_ID],
capture_output=True, text=True, env=env, timeout=30)
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
self.log = r.stdout
return self.out.read_text()
def before_the_lean_level(self):
"""What the patcher wrote before v1.13: the effort and system fixes, default xhigh,
and no lean level."""
old = (self.base / "hub" / "models--org--model" / "snapshots" / SHA / "chat_template.jinja").read_text()
old = old.replace(pt.EFFORT_ANCHOR, pt.EFFORT_PATCHED.replace("@@DEF@@", "xhigh"), 1)
old = old.replace(pt.SYSTEM_ANCHOR, pt.SYSTEM_PATCHED, 1)
self.assertIn("reasoning_effort|default('xhigh')", old)
self.assertNotIn(pt.LEAN_MARKER, old)
return old
def test_a_run_without_the_variable_keeps_xhigh(self):
self.assertIn("reasoning_effort|default('xhigh')", self.run_patch("0"))
kept = self.run_patch()
@@ -56,6 +71,25 @@ class TheDefaultIsKept(unittest.TestCase):
self.run_patch("0")
self.assertIn("reasoning_effort|default('lean')", self.run_patch("1"))
def test_a_template_from_before_the_lean_level_chose_nothing(self):
self.out.write_text(self.before_the_lean_level())
text = self.run_patch()
self.assertIn("reasoning_effort|default('lean')", text, "it kept xhigh, which nobody chose")
self.assertIn("lean (default), xhigh, medium, and low", text)
self.assertIn("predates the lean level", self.log)
self.assertNotIn("kept from the installed template", self.log)
def test_it_says_lean_kept_on_the_run_after(self):
self.out.write_text(self.before_the_lean_level())
first = self.run_patch()
self.assertEqual(self.run_patch(), first)
self.assertIn("lean (kept from the installed template)", self.log)
def test_naming_xhigh_on_such_a_box_still_keeps_it(self):
self.out.write_text(self.before_the_lean_level())
self.run_patch("0")
self.assertIn("reasoning_effort|default('xhigh')", self.run_patch(), "the choice made then was lost")
def test_a_fresh_install_defaults_to_lean(self):
text = self.run_patch()
self.assertIn("reasoning_effort|default('lean')", text)