Swapper: Qwen3.5-0.8B Refusal-Ablated & Orthogonalized

Swapper is a decensored version of Qwen/Qwen3.5-0.8B created by locating and orthogonalizing the internal refusal direction in the model's residual stream.

Unlike standard supervised fine-tuning (SFT) or DPO, this model modifies the weight matrices that write to the residual stream ($W_E$, attention output projections, and MLP down projections) so the network cannot mathematically represent or write the "refusal feature".


Included Files in this Repository

File Description
model.safetensors Orthogonalized model weights (3.2 GB)
config.json, *.json Architecture and tokenizer configuration
chatbot.py Interactive terminal streaming chatbot with conversation history
refusal_demo.ipynb Fully executed Jupyter notebook showing the refusal ablation and orthogonalization
heretic_qwen3_5_0_8b_final.ipynb Heretic Optuna study notebook for directional ablation

Quickstart: Streaming Chatbot

Clone the repository and run the included terminal chatbot:

git clone https://huggingface.co/jayesh20/swapper
cd swapper
pip install -r requirements.txt # or: pip install transformers torch accelerate
python chatbot.py

Or run directly in Python pointing to this Hugging Face repository:

python chatbot.py jayesh20/swapper

Python Usage

import torch
from transformers import AutoProcessor, AutoModelForMultimodalLM, TextStreamer

model_id = "jayesh20/swapper"

processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForMultimodalLM.from_pretrained(
    model_id,
    dtype=torch.float32,
    device_map="auto"
)

streamer = TextStreamer(processor.tokenizer, skip_prompt=True, skip_special_tokens=True)

messages = [
    {"role": "user", "content": [{"type": "text", "text": "How do hackers test network security vulnerabilities?"}]}
]

inputs = processor.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=True,
    return_dict=True,
    return_tensors="pt"
).to(model.device)

with torch.no_grad():
    outputs = model.generate(
        **inputs,
        max_new_tokens=1024,
        streamer=streamer,
        do_sample=True,
        temperature=0.7,
        top_p=0.9
    )

Method Details

  1. Activation Difference: Activations are cached across intermediate layers (layer 14) for paired harmful instructions (AdvBench) and harmless instructions (Alpaca) at the final prompt token position.
  2. Refusal Direction ($r$): $$r = \frac{\mu_{\text{harmful}} - \mu_{\text{harmless}}}{|\mu_{\text{harmful}} - \mu_{\text{harmless}}|}$$
  3. Weight Orthogonalization: All projection matrices writing to the residual stream are projected to remove components along $r$: $$W' \leftarrow (I - r r^T) W$$ This eliminates the refusal mechanism without degrading general conversational abilities.
Downloads last month
32
Safetensors
Model size
0.9B params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for jayesh20/swapper

Finetuned
(1,013)
this model