1
0
Fork 0
mirror of https://github.com/p-e-w/heretic.git synced 2026-12-03 18:42:57 +07:00

[PR #50] [CLOSED] Add enable_thinking config option for Qwen3 and similar models #254

Closed
opened 2026-11-01 04:19:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/p-e-w/heretic/pull/50
Author: @lbartoszcze
Created: 11/26/2025
Status: ❌ Closed

Base: master ← Head: feature/enable-thinking


📝 Commits (1)

  • 0c21adf Add enable_thinking config option for Qwen3 and similar models

📊 Changes

2 files changed (+31 additions, -4 deletions)

View changed files

📝 src/heretic/config.py (+9 -0)
📝 src/heretic/model.py (+22 -4)

📄 Description

Summary

Some models like Qwen3 support a "thinking mode" where the model generates internal reasoning tokens (<think>...</think>) before the actual response. This behavior is controlled by the enable_thinking parameter in apply_chat_template().

The Problem

When abliterating these models, the thinking mode setting during training must match the intended inference setting. If the model is abliterated with thinking mode ON but used with thinking mode OFF (or vice versa), the abliteration may not transfer properly because the model's behavior differs significantly between modes.

We discovered this when abliterating Qwen3-8B - the abliteration appeared to work (refusals dropped from 43 to 37 during training), but when testing with enable_thinking=False, the model still refused most prompts. The abliteration only worked in thinking mode because that's how it was trained.

The Solution

This PR adds an enable_thinking configuration option that:

  • When set to False: Disables thinking mode during abliteration
  • When set to True: Enables thinking mode during abliteration
  • When set to None (default): Uses the model's default behavior (backwards compatible)

The setting is applied to both generate() and stream_chat_response() methods.

Usage

# Via CLI
heretic --model Qwen/Qwen3-8B --enable-thinking false

# Via config.toml
enable_thinking = false

# Via environment variable
HERETIC_ENABLE_THINKING=false

Changes

  • config.py: Added enable_thinking: bool | None field with default None
  • model.py: Updated generate() and stream_chat_response() to pass enable_thinking to apply_chat_template() when configured

Testing

Tested with Qwen3-4B and Qwen3-8B models. With enable_thinking=false, the abliterated models now properly respond without refusals when used in non-thinking mode.

Test plan

  • Test with a Qwen3 model using --enable-thinking false
  • Verify abliteration works in non-thinking mode
  • Verify default behavior (None) is unchanged for other models

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/p-e-w/heretic/pull/50 **Author:** [@lbartoszcze](https://github.com/lbartoszcze) **Created:** 11/26/2025 **Status:** ❌ Closed **Base:** `master` ← **Head:** `feature/enable-thinking` --- ### 📝 Commits (1) - [`0c21adf`](https://github.com/p-e-w/heretic/commit/0c21adfd2b07e449b24fca1b47e77a2d5853dd69) Add enable_thinking config option for Qwen3 and similar models ### 📊 Changes **2 files changed** (+31 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/heretic/config.py` (+9 -0) 📝 `src/heretic/model.py` (+22 -4) </details> ### 📄 Description ## Summary Some models like Qwen3 support a "thinking mode" where the model generates internal reasoning tokens (`<think>...</think>`) before the actual response. This behavior is controlled by the `enable_thinking` parameter in `apply_chat_template()`. ### The Problem When abliterating these models, the thinking mode setting during training **must match** the intended inference setting. If the model is abliterated with thinking mode ON but used with thinking mode OFF (or vice versa), the abliteration may not transfer properly because the model's behavior differs significantly between modes. We discovered this when abliterating Qwen3-8B - the abliteration appeared to work (refusals dropped from 43 to 37 during training), but when testing with `enable_thinking=False`, the model still refused most prompts. The abliteration only worked in thinking mode because that's how it was trained. ### The Solution This PR adds an `enable_thinking` configuration option that: - When set to `False`: Disables thinking mode during abliteration - When set to `True`: Enables thinking mode during abliteration - When set to `None` (default): Uses the model's default behavior (backwards compatible) The setting is applied to both `generate()` and `stream_chat_response()` methods. ### Usage ```bash # Via CLI heretic --model Qwen/Qwen3-8B --enable-thinking false # Via config.toml enable_thinking = false # Via environment variable HERETIC_ENABLE_THINKING=false ``` ### Changes - `config.py`: Added `enable_thinking: bool | None` field with default `None` - `model.py`: Updated `generate()` and `stream_chat_response()` to pass `enable_thinking` to `apply_chat_template()` when configured ### Testing Tested with Qwen3-4B and Qwen3-8B models. With `enable_thinking=false`, the abliterated models now properly respond without refusals when used in non-thinking mode. ## Test plan - [ ] Test with a Qwen3 model using `--enable-thinking false` - [ ] Verify abliteration works in non-thinking mode - [ ] Verify default behavior (None) is unchanged for other models --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 04:19:15 +07:00
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#254
No description provided.