Project · Mechanistic Interpretability
Manuscript in preparationCrossCoder steering: multi-layer concept erasure in text-to-image diffusion models. Nudity generation cut from 55% to 5% without changing any model weights
IISER Bhopal
The usual ways of stopping a text-to-image model from producing something all have gaps. Keyword filters get bypassed by rephrasing. Post-hoc classifiers slap a censor bar on an image the model already generated. Fine-tuning methods like ESD[3] and UCE[4] do erase the concept, but they rewrite model weights, need retraining per concept, and risk collateral damage to unrelated generation.
DiffSteer asks a different question: can you find the concept inside the model and subtract it at inference time, with no weight changes at all? The place to look is the CLIP[8] text encoder that conditions Stable Diffusion[1]. If a concept has a direction in that encoder's activation space, removing the direction means the U-Net never receives the concept signal in the first place.
Prior work, Concept Steerers[9], showed this works with a k-sparse autoencoder trained on a single CLIP layer, building on sparse dictionary learning from the language-model interpretability literature[5][6]. My contribution is to extend it to CrossCoders[7]: sparse autoencoders with a shared encoder and separate per-layer decoders, trained across several layers at once, on the hypothesis that concept information is spread across encoder depth rather than concentrated in one layer.
Raw activations are dense and polysemantic, so you cannot cleanly ablate a concept by zeroing coordinates. Sparse dictionary learning re-expresses an activation as a sparse combination of an overcomplete learned basis, whose features are far closer to monosemantic.
Both models were trained on activations harvested by forward-passing I2P[2] benchmark prompts through the frozen CLIP text encoder of Stable Diffusion v1.4, covering 400M+ tokens from I2P and CC3M/LAION captions.
d = 768) with a top-k constraint (k = 48) into a
6144-dimensional latent (8× expansion). Training minimises fraction of variance unexplained plus
an auxiliary loss that revives dead latents.
3 × 768 = 2304-dim vector, encodes it through one shared encoder into a
sparse code, then reconstructs each layer with its own decoder. An entropy term
(α_spec = 0.01) pushes each latent to load on a single layer, which keeps the
features interpretable.
For the SAE, the steering vector is the decoded dense encoding of a concept phrase
("naked, nude, bare, exposed, stripped, topless"), scaled by α = −0.4.
For the CrossCoder, concept latents are found contrastively: the positive part of
Δz = (z_c − z_∅): and the top-32 latents by Δz define a mask. Per-layer
steering vectors are decoded from the masked code at α = −0.5.
At inference, forward hooks apply the steering vectors simultaneously at all three layers. Each hook adds the vector to the conditional embedding and subtracts it from the unconditional one, so the edit is amplified through classifier-free guidance[10] rather than diluted by it.
α, and composable across
concepts.
| SAE | CrossCoder | |
|---|---|---|
| Input | layer 9, d = 768 | layers 4, 8, 9, d = 2304 |
| Latent dim | 6144 | 6144 |
| k / AuxK | 48 / 192 | 48 / 192 |
| αspec | n/a | 0.01 |
| Steering layers | {9} | {4, 8, 9} |
| Steering α | −0.4 | −0.5 |
Both trained on a TPU v4-8 for 400M tokens. Adam, lr 4×10⁻⁴, batch size 4096, no
weight decay.
Evaluated on 80 prompts spanning photorealistic photography, classical painting styles (Klimt, Monet, Schiele), digital art, and indirect phrasings, at a fixed seed with 20 DDIM steps and guidance scale 7.5. Nudity rate is the fraction of images with NudeNet detections (threshold 0.45) across five anatomical classes; CLIP score is image–prompt cosine similarity under CLIP ViT-B/32.
| Method | Nudity Rate ↓ | CLIP Score ↑ |
|---|---|---|
| Unsteered SD 1.4 | 55.0% | 33.94 |
| SAE steered (layer 9) | 11.2% | 31.32 |
| CrossCoder (layers 4, 8, 9) | 5.0% | 30.23 |
CrossCoder steering cuts the nudity rate by 50 percentage points from baseline, versus 43.8 for the single-layer SAE, a 55% relative reduction in residual nudity (11.2% → 5.0%). The cost is 1.09 CLIP points relative to SAE, which is the honest trade-off: removing a concept from the conditioning signal necessarily pulls the generation slightly away from the prompt.
A pattern the binary nudity rate does not capture: SAE steering frequently leaves peripheral skin regions exposed while successfully blocking the most visible anatomy. CrossCoder steering produces complete coverage far more consistently. This is what you would expect if nudity information is spread across encoder depth and a single-layer dictionary only captures part of it.
With no changes to model weights, cross-layer sparse steering reduces nudity generation from 55.0% to 5.0%. Beyond the safety result, this is evidence about representation: the fact that spanning three layers beats a single layer by more than 2× on residual nudity suggests the concept is spread across encoder depth, and that cross-layer sparse dictionaries capture that distribution more completely than single-layer alternatives do.