1
0
Fork 0
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

Closed
opened 2026-11-01 04:17:39 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @timrohrbaugh on GitHub (Feb 27, 2026).
Original GitHub issue: https://github.com/p-e-w/heretic/issues/197

Image

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.

  1. Add Importer for TemplateError:
    from jinja2 import TemplateError

  2. 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,
),
)

Originally created by @timrohrbaugh on GitHub (Feb 27, 2026). Original GitHub issue: https://github.com/p-e-w/heretic/issues/197 <img width="1362" height="952" alt="Image" src="https://github.com/user-attachments/assets/b85bfc78-9ea3-4c49-b300-ba9608bca92d" /> 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. 1. Add Importer for TemplateError: from jinja2 import TemplateError 2. 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, ), )
Author
Owner

@p-e-w commented on GitHub (Feb 27, 2026):

Please format your issues more carefully.

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.

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.

<!-- gh-comment-id:3970691179 --> @p-e-w commented on GitHub (Feb 27, 2026): Please format your issues more carefully. > 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. 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.
Author
Owner

@erm14254 commented on GitHub (Feb 28, 2026):

Please format your issues more carefully.

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.

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.

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):

  • Initial refusals: 99/100
    ...
    » [Trial 1] Refusals: 99/100, KL divergence: 0.0353

Without thinking suppression (default):

  • Initial refusals: 91/100
    ...
    » [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.

<!-- gh-comment-id:3976584989 --> @erm14254 commented on GitHub (Feb 28, 2026): > Please format your issues more carefully. > > > 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. > > 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. 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): * Initial refusals: 99/100 ... » [Trial 1] Refusals: 99/100, KL divergence: 0.0353 Without thinking suppression (default): * Initial refusals: 91/100 ... » [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.
Author
Owner

@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.

<!-- gh-comment-id:3976651701 --> @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.
Author
Owner

@erm14254 commented on GitHub (Feb 28, 2026):

And several people have now successfully abliterated Qwen3.5-35B-A3B with suppression enabled, so I suspect you ran into a different problem.

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.

<!-- gh-comment-id:3976854574 --> @erm14254 commented on GitHub (Feb 28, 2026): > And several people have now successfully abliterated Qwen3.5-35B-A3B with suppression enabled, so I suspect you ran into a different problem. 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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
p-e-w/heretic#114
No description provided.