[Model] Add opt-in runtime abliteration for Qwen3.5/Qwen3.8

Project a unit refusal direction out of the residual-stream writes
(attention, linear-attention and MLP outputs, and token embeddings) at
runtime, enabled by VLLM_ABLITERATION pointing to a JSON or safetensors
file with a refusal_direction vector. A bare name resolves to
VLLM_ABLITERATION_DIR, default /opt/vllm/abliteration. For one direction
this equals the weight edit W' = W - r(r^T W), so a base checkpoint
reproduces its abliterated release with no extra weights. Unset, the
path loads nothing and adds no work.

Co-Authored-By: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
2026-10-14 07:57:59 +00:00
co-authored by Hinata
parent ac305c44cb
commit 8151c7b158
6 changed files with 301 additions and 2 deletions
+2
View File
@@ -66,6 +66,7 @@ from vllm.multimodal.inputs import MultiModalFeatureSpec
from vllm.sequence import IntermediateTensors
from vllm.tokenizers.registry import cached_tokenizer_from_config
from .abliteration import projector
from .interfaces import (
HasInnerState,
IsHybrid,
@@ -191,6 +192,7 @@ class Qwen3_5DecoderLayer(Qwen3NextDecoderLayer):
)
self.layer_scale = getattr(config, "layer_scale", False)
self.abliterate = projector(config.hidden_size)
if self.layer_scale:
self.attn_layer_scale = torch.nn.Parameter(
torch.zeros(