mirror of
https://github.com/p-e-w/heretic.git
synced 2026-12-03 18:42:57 +07:00
[GH-ISSUE #487] Auto-detected response prefix keeps thinking models in CoT mode - ablation direction degenerates, model destroyed (Qwen3) #217
Labels
No labels
bug
enhancement
enhancement
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
p-e-w/heretic#217
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @haddock-development on GitHub (Oct 8, 2026).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/487
Summary
On thinking models whose chat template does not pre-append
<think>to thegeneration prompt (Qwen3, DeepSeek-R1, ...), the automatic response-prefix
detection produces a prefix that keeps the model in reasoning mode while it
writes what heretic treats as its final answer. Consequences we measured:
abliteration direction is essentially noise,
output degenerates to token salad.
With an explicitly set prefix that closes the think block before any reasoning
text, the same model, same command otherwise: baseline refusals 4/25, best-trial
KL 0.0943, 0/25 refusals after ablation, and no capability losses across 7
lm-eval tasks. Details and numbers below.
Environment
49b56e5(installed from git)Qwen/Qwen3-0.6Bchain_of_thought_skips, default datasets,n_trials2 and 20 in different runsWhat happens
Run
heretic Qwen/Qwen3-0.6Bwith defaults. Qwen3's template ends the promptwith
<|im_start|>assistant\n— no<think>tag — so the first CoT-skip loopin
main.py(the "LiquidAI's LFM models do this" branch) does not match.The fallback branch then infers the prefix from commonprefix of sample responses:
Qwen3 begins its reasoning near-identically for every prompt ("
Okay,"), sothe common prefix reaches into the reasoning text. After substituting the
closed block, the recheck step appends that reasoning text ("
Okay,") to theprefix. The comment in the code says:
That assumption (remainder = whitespace) does not hold for models that
self-generate
<think>and start their reasoning with common filler. The modelis forced to begin its "answer" with reasoning-style tokens and simply continues
the reasoning monologue:
Measured consequences (Qwen3-0.6B)
UCE القدم القدم ...,madeemadeemadee ...With the auto-detected prefix the optimization is worse than useless: the
refusal scorer reads reasoning text, finds no refusal markers, reports the
maximum score, and the optimizer is free to pick ablation parameters that
maximally damage the model. lm-eval on the model produced with the explicit
prefix (7 tasks, 0-shot loglikelihood) showed no capability losses
(PIQA/HellaSwag/WinoGrande/ARC-E/OpenBookQA/BoolQ identical, MMLU +3.5, n=171).
Workaround
Set
response_prefixexplicitly, with real newlines, e.g. the same bytesQwen3's template emits for
enable_thinking=False:Two traps worth documenting, we hit both:
'
keeps\nas backslash-n character pairs. That prefix is out-of-distribution for the tokenizer and made Qwen3-0.6B degenerate into literal\n\n\n ...output on roughly a third of prompts - silently, with healthy-looking scores. Only real newlines are stable. 2.max_response_length` below ~100 never sees a refusal even with a correctprefix, which again flatters the refusal score.
Suggested fix
In the
cot_skip_appliedrecheck branch, only extend the prefix while theadditional common prefix is whitespace - or do not re-extend after a CoT
substitution at all. For models that self-generate
<think>, detecting theactual end of the CoT (
</think>) in the generated text would be more robustthan substituting a closed block and hoping the remainder is whitespace.
Happy to provide full logs or test a patch on Qwen3-0.6B (and a 4 GB GPU
constraint makes for a good regression target - the whole repro runs in
~15 minutes).
@p-e-w commented on GitHub (Oct 9, 2026):
I'm aware of this issue, though fixing it properly is very difficult. Your proposal
sounds reasonable, but suppressing thinking with template variables doesn't work reliably in my experience, and if the model still generates some (even short) CoT trace, we get all kinds of problems such as non-common traces and having to decide which one to use as the default prefix to prepend to responses.
Happy to see any concrete improvements in this area though. If you can come up with something that actually works, feel free to submit a PR, but please keep it simple as the relevant code is already very complex.
@elementmerc commented on GitHub (Oct 9, 2026):
Same failure here on Qwen3, and what held was not inferring a prefix at all. Split the generated text on the last
</think>and read the verdict from what follows, treating a block that never closed as unscorable rather than scoring the reasoning. It cost us every published number I had at the time@Vinay-Umrethe commented on GitHub (Oct 9, 2026):
Qwen/Qwen3-0.6Bis simply an unreliable model for such test cases. The gibberish is already evidentUCE القدم القدم ..., madeemadeemadee ...I suppose
Qwen/Qwen3-4Bis the minimal ideal size of a model for testing.@p-e-w commented on GitHub (Oct 12, 2026):
Wait, I only now notice that the issue description only gives stats for 2 and 20 trials.
That is way too few to draw any conclusions, and in fact, unless
n_startup_trialswas also lowered, it is fully expected to produce garbage as no optimization happens at all.@haddock-development Have you taken this into account?
@akushonkamen commented on GitHub (Oct 17, 2026):
Confirmed on current master (
66a952b): the fallback prefix inference atsrc/heretic/main.py:541(commonprefix(responses)) reaches into Qwen3-style reasoning text ('<think>\nOkay,'), and while the closed-block substitution is fine, the "Rechecking with prefix" step atsrc/heretic/main.py:567unconditionally appendscommonprefix(recheck_responses).rstrip(" ")— which is the reasoning continuation ('\nOkay,') — so the final prefix becomes'<think></think>\nOkay,'and every generation prompt is poisoned viasrc/heretic/model.py:489-493.I'm working on a minimal fix along the keep-it-simple guidance: at the recheck step, never extend the prefix across the
</think>boundary (split each recheck response on the last</think>; responses whose think block never closes are dropped from the inference set), so the prefix stops at'<think></think>'while the whitespace-continuation case this step exists for still works as before. Will include a regression test.Heads-up: this contribution is prepared with AI assistance (Claude Code agent), posted and maintained under this account.
@akushonkamen commented on GitHub (Oct 17, 2026):
Opened PR #501 with the fix (whitespace-only prefix extension per the suggestion in this issue).