Abliteration HandbookField guide
Technique atlas

MoE & hybrid architecture abliteration

Mixture-of-Experts and linear-attention hybrid models require per-expert and per-layer-type targets. Heretic handles many architectures automatically — manual pipelines must mirror its…

3 min read 2 examples Source-linked

In this chapter
On this page Interactive companion
Personal reading progress

0/8 sections reviewed

View original Markdown
Interactive companion

Explore routing coverage

Use the visual controls alongside the complete source chapter.

Mixture-of-Experts and linear-attention hybrid models require per-expert and per-layer-type targets. Heretic handles many architectures automatically — manual pipelines must mirror its module map.

Source: Heretic directional ablation docs


Architecture → module map#

Model familyAbliteration targets
Dense (Llama, Qwen, Gemma)layer.self_attn.o_proj, layer.mlp.down_proj
Qwen3 MoElayer.mlp.experts[e].down_proj for each expert
Phi-3.5-MoElayer.block_sparse_moe.experts[e].w2
Granite MoE hybrid (attn layer)layer.shared_mlp.output_linear
Granite MoE hybrid (MoE layer)layer.moe.experts[e].output_linear
Qwen3.5 hybrid (linear attn)layer.linear_attn.out_proj

Rule: target output projections that write to the residual stream — not q_proj / gate_proj inputs.


All MoE / hybrid abliteration builds on the projected + norm-preserving technique (T03). See:

  • projected-norm-preserving-abliteration.md — math, orthogonalize_direction, row_normalization modes, recommended production stack, low-VRAM profile.
  • ../docs/advanced-techniques-catalog.md — T03 + T08 table rows (explicitly cross-linked in catalog + dedicated cross-technique guidance), config parameters, recommended MoE config snippet, and "always start MoE by reviewing T03 first" navigation note.

Why pair them?

  • orthogonalize_direction = true removes only the refusal component orthogonal to the harmless centroid per expert (protects "helpful" features inside each routed expert).
  • row_normalization = "full" + small LoRA rank prevents row-norm drift that would otherwise distort expert routing weights and amplify capability loss on hybrid models.
  • Use the same flags for dense models; they become mandatory for stable MoE results (see catalog T03/T08 guidance and low-vram profile).

Heretic applies these per-expert automatically when the targets include experts[*].down_proj etc.


Why experts matter#

Each expert's down_proj can carry refusal writes independently. Abliterating only the shared router or one expert leaves refusal paths in inactive experts.

Heretic: iterates all experts when building the optimization graph.

Manual: loop experts in sharded_ablate.py config or custom script:

python
for layer in model.model.layers:
    if hasattr(layer.mlp, "experts"):
        for expert in layer.mlp.experts:
            expert.down_proj.weight.data = ablate_down_proj(
                expert.down_proj.weight.data, r_layer, alpha
            )

VRAM considerations (MoE)#

IssueMitigation
Many experts × large matricesquantization = bnb_4bit
Router + all experts loadeddevice_map + max_memory CPU offload
Optuna trials slowReduce n_trials; use smaller MoE (e.g. 30B-A3B not 235B)

MoE abliteration on consumer GPU often requires 4-bit + cloud GPU for initial Heretic run, then GGUF for local inference.


Hybrid linear attention (Qwen3.5)#

Some layers use linear_attn instead of standard self_attn. o_proj may be absent — use linear_attn.out_proj for those layer indices only.

Verify in model:

python
for i, layer in enumerate(model.model.layers):
    has_sa = hasattr(layer, "self_attn") and hasattr(layer.self_attn, "o_proj")
    has_la = hasattr(layer, "linear_attn")
    print(i, "self_attn" if has_sa else "", "linear_attn" if has_la else "")

Eval notes#

  • MoE models may show expert routing shift post-abliteration — monitor perplexity on domain prompts.
  • KL eval per Heretic still applies; add expert-load entropy check if available.

Safetensor surgery surface#

MoE expert down_proj / w2 / output_linear tensors live in the same HF *.safetensors shards as dense models. Heretic discovers expert modules automatically; manual edits must touch every expert in each MoE layer.

→ ../methods/safetensor-abliteration-pipeline.md (tensor names, projected math, Heretic save layout)


Trace this chapter to its source.

The complete Markdown remains the editable source. This page adds navigation, typography, and a visual companion.

techniques/moe-hybrid-abliteration.md
Inspect the source fingerprintSHA-256 e32c84eb3b09ebe298677c697a3fc45dd5221d23dd6738a4873388f75085d2c2Source commit 6fba7436a5914cad7c8f0835a14b480a29dac263