mirror of
https://github.com/p-e-w/heretic.git
synced 2026-12-03 18:42:57 +07:00
[GH-ISSUE #197] Qwen3.5 models require thinking suppression by modifying api parameters only. System message does not work #114
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#114
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 @timrohrbaugh on GitHub (Feb 27, 2026).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/197
Thinking models like Qwen3.5 generate thinking content by default before producing their actual response. When Heretic evaluates responses for refusal detection, this thinking content contains safety-related language like "illegal," "harmful," and "I should not help" — all of which match Heretic's refusal markers. This makes abliteration appear ineffective because even a successfully abliterated model's thinking content triggers refusal detection.
The existing commonprefix-based thinking suppression in main.py fails for Qwen3.5 because the content of thinking varies per prompt (each prompt produces different reasoning), so there is no common prefix beyond the first few characters. Qwen3.5's official mechanism for disabling thinking is the enable_thinking=False parameter passed to the chat template
This PR adds automatic detection and suppression of thinking content by testing whether the tokenizer's chat template accepts enable_thinking=False. The detection is done once per generate() call using a lightweight test on a single chat, with a broad except Exception fallback to preserve backward compatibility with all existing models.
Add Importer for TemplateError:
from jinja2 import TemplateError
generate() — Try enable_thinking=False on the chat template:
Replace the existing apply_chat_template call:
chat_prompts = cast(
list[str],
self.tokenizer.apply_chat_template(
chats,
add_generation_prompt=True,
tokenize=False,
),
)
With:
Try to suppress thinking for models that support it (e.g. Qwen3.5).
This prevents thinking content from polluting refusal detection,
since thinking content typically contains safety-related language
("illegal", "harmful", etc.) that matches refusal markers.
template_kwargs: dict[str, Any] = {}
try:
self.tokenizer.apply_chat_template(
chats[:1],
add_generation_prompt=True,
tokenize=False,
enable_thinking=False,
)
template_kwargs["enable_thinking"] = False
except Exception:
pass
chat_prompts = cast(
list[str],
self.tokenizer.apply_chat_template(
chats,
add_generation_prompt=True,
tokenize=False,
**template_kwargs,
),
)
3. stream_chat_response() — Apply the same thinking suppression for consistency:
Replace the existing apply_chat_template call:
chat_prompt = cast(
str,
self.tokenizer.apply_chat_template(
chat,
add_generation_prompt=True,
tokenize=False,
),
)
With:
Suppress thinking content for models that support it.
template_kwargs: dict[str, Any] = {}
try:
self.tokenizer.apply_chat_template(
[chat[:2]],
add_generation_prompt=True,
tokenize=False,
enable_thinking=False,
)
template_kwargs["enable_thinking"] = False
except Exception:
pass
chat_prompt = cast(
str,
self.tokenizer.apply_chat_template(
chat,
add_generation_prompt=True,
tokenize=False,
**template_kwargs,
),
)
@p-e-w commented on GitHub (Feb 27, 2026):
Please format your issues more carefully.
I think you misunderstood how the common prefix mechanism works. Of course the CoT isn't identical for all prompts, and our system doesn't require it to be. Please check the code for details.
@erm14254 commented on GitHub (Feb 28, 2026):
Hello,
Tested thinking suppression on Qwen3.5-35B-A3B. It causes baseline refusals to jump from 91/100 to 99/100, making abliteration ineffective.
With thinking suppression (enable_thinking=False):
...
» [Trial 1] Refusals: 99/100, KL divergence: 0.0353
Without thinking suppression (default):
...
» [Trial 1] Refusals: 89/100, KL divergence: 0.0071
Same model, same config, only difference is enable_thinking=False.
Why this happens: The model uses the "< think >" phase to reason toward compliance. Disabling it forces snap judgments, which default to refusal.
Recommend NOT including thinking suppression in any future PR.
@p-e-w commented on GitHub (Feb 28, 2026):
@erm14254
Thinking suppression is required for many reasoning models to abliterate correctly.
And several people have now successfully abliterated Qwen3.5-35B-A3B with suppression enabled, so I suspect you ran into a different problem.
@erm14254 commented on GitHub (Feb 28, 2026):
I abliterated Qwen3.5-35B-A3B myself yesterday and there was no issues, I did not use what the OP posted at the time and I got low refusal with low KL divergence, however as soon as I added what the OP posted issues started as you can see from the logs.