representation engineering · diffusion · first cut

steering an image model with control vectors

paul m. english  /  2026-11  /  work in progress  /  v0.1

can the top-down interpretability method of representation engineering — proven on language models — be ported to a modern diffusion image generator, and where in the network does the concept actually live?

abstract

We port Representation Engineering (Zou et al., arXiv:2310.01405) and its reference implementation vgel/repeng to Qwen-Image-2.1-Turbo, a 20B-class flow-matching diffusion model with a Qwen3-VL text encoder and a 32-block MMDiT denoiser. We train per-concept control vectors by contrast-pair PCA on activations at two loci — the text encoder (36 layers) and the denoiser (32 blocks) — and inject them additively at inference.

Three findings so far: (1) the natural evaluation metric (a zero-shot CLIP margin) is gameable and must ship with a coherence guard; (2) the concept is distributed — no single layer carries it, so whole-stack injection is the only thing that works; and (3) the locus that steers is concept-dependent — brightness lives in the text encoder, warmth in the denoiser, painting only in the encoder (the denoiser steers it the wrong way). The same contrast pairs trained on the turbo and non-turbo checkpoints converge on essentially the same direction (cosine 1.000 / 0.983), so the vector is a property of the concept and the data, not the weights. Controls, a jailbreak-resistance probe, and qualitative galleries are still to come.

status. This is a first cut, updated as the experiments close. Everything below is reproducible from the repo; raw numbers live in results/**/metrics.json. Code is Apache-2.0; the Qwen weights are under the Qwen Research License (non-commercial).

background

Representation engineering (RepE) reads a concept out of a model's internal state and writes it back in. For a concept $c$, you present matched contrast pairs — the same scene with and without the concept — record the hidden state $h$ at some layer for each, and take the first principal component of the difference vectors $h^{+} - h^{-}$. That unit vector $d_c$ is the concept, linearly: adding $d_c$ back at inference shifts the output along the concept with no fine-tuning. The paper calls the read-out Linear Artificial Tomography (LAT); the artefact is a control vector.

On language models this is a settled technique with a small, faithful reference implementation. On diffusion models the read-out is not obvious — there is no autoregressive residual stream, no single "last token", and two very different network halves (a text encoder and a denoiser) where the concept could live. Related work exists (Concept Sliders, Activation Steering for diffusion, h-space steering, prompt-to-prompt, data-driven activation maps), but the field has no default recipe the way RepE does for LLMs. That gap is what this project probes. See docs/PRIOR_ART.md for the survey.

method

A from-scratch port that keeps the paper's core honest and changes only what the architecture forces.

Contrast pairs, PCA-1, injection

For each concept we hold 150 matched positive/negative prompt pairs and 50 held-out pairs. Activations are captured at the first denoising step (where the prompt still dominates) via forward hooks. Per layer, we form the mean difference, take the top singular vector of the centred difference matrix, and normalise:

$$ d_c^{(l)} = \frac{\mathrm{SVD}_1\!\left(h^{+ (l)} - h^{- (l)}\right)}{\left\lVert \cdot \right\rVert} \qquad h^{(l)} \leftarrow h^{(l)} + \alpha\, \lVert h^{(l)} \rVert\, d_c^{(l)} $$

Injection is additive on the layer's output, as in repeng. Two corrections were necessary and are the difference between a working vector and a plausible-looking no-op:

The two loci (and both at once)

  1. text encoder — the 36 Qwen3-VL decoder layers, i.e. steer the representation of the prompt. The pipeline consumes only the encoder's final hidden state, so a whole-stack vector is manipulating information the model would otherwise discard.
  2. denoiser (DiT) — the 32 transformer_blocks, injected at every step. The part that actually paints.
  3. both — encoder and denoiser together, to see whether the effects compose, cancel, or are redundant.

Reading: which step, which token

Capture fires on the first forward pass (step 0). The residual stream is (batch, seq, hidden), so the sequence must be pooled; the default is the last token (the point the pipeline actually consumes downstream), with mean kept for comparison. Stage 1 used mean and the encoder vector was unstable — a read-point problem, not a method problem.

Measuring — and the coherence rule

The primary metric is a zero-shot CLIP margin: score the image against the concept's positive and negative probe sentences, report $\mathrm{logit}(pos) - \mathrm{logit}(neg)$. Direction and monotonicity in $\alpha$ are the evidence. A plain image statistic (mean luminance) is an independent check for the calibration concepts, and drift (cosine similarity to the unsteered image) separates "steered the concept" from "destroyed the image".

The margin alone rewards destroying the picture. A bright noise field scores "bright" higher than any real image. So no margin is ever reported without a coherence guard.

Every measurement therefore goes through probe.evaluate, returning margin plus luminance, contrast, gradient and drift, with probe.is_coherent flagging collapse. A result that is incoherent is a null result, not a win.

Controls

  1. prompt-engineering baseline — ask for the concept in words; RE has to beat it, or beat it on robustness;
  2. placebo vector — trained on shuffled pairs; should do nothing;
  3. zero vector — non-zero coefficient, zero direction; should be a no-op.

the ladder so far

experimental stages
stagequestionstate
00throughput & attention backend bake-offclosed
01smoke — does the harness work end to end?closed
02acoefficient calibration per locusclosed
02locus × concept matrixclosed
03per-layer ablation — where is the concept?closed
06cross-model transfer (turbo ↔ non-turbo)closed
04/05controls, jailbreak probe, galleriesqueued

results

stage 0 — throughput & the attention gate

The flash-enabled SDPA backend (default) is 1.4–2.2× faster than forced math SDPA on ROCm 7.15 for this stack, and the gap grows with resolution. A correctness gate compared the two at identical seed before adopting it: byte-identical on repeat runs, sub-perceptual FP reordering versus math, deterministic. Decision: default for sweeps, math for anything published. Baseline throughput is ≈14 s/image at 512², 8 steps, turbo (the earlier Krea-era "VAE on CPU" workaround is not needed on this stack).

stage 1 — the metric is gameable

The harness worked end to end on both loci, but the two behaved very differently — and the encoder's failure was informative. At coefficient 8 the image collapsed into a bright noise field (lum 126, gradient 5.2) yet the CLIP margin climbed to +0.57.

key finding. The CLIP margin is gameable. It rewards destroying the picture. Every margin must ship with a coherence guard — fixed by routing all measurements through probe.evaluate / probe.is_coherent, and it changes how every later result reads.
text-encoder smoke grid
fig 1a. text-encoder smoke — baseline, and coeff 2/4/8. The last is a noise field that still scores "bright".
denoiser smoke grid
fig 1b. denoiser smoke — clean and monotone, the expected signal.

stage 2a — calibration & the coherent windows

With the sign fix and activation-relative scaling, brightness rises monotonically at the text encoder within a coherent window; the denoiser blows out past α 0.005. The two loci therefore get different coefficient grids.

stage 2a calibration sweep
fig 2. brightness, per locus, α ∈ {0, .002, .005, .01, .02, .04} (turbo, 16 pairs). top: text encoder — a scene change (dusk → daylight) at essentially unchanged texture. bottom: denoiser — a global exposure wash to white.
stage 2a — margin vs α (baseline +2.142)
locus0.0050.010.020.04
text encoder−0.23+0.02+0.92+1.48
denoiser+0.43incoherentincoherent−0.67

Coherent windows: text encoder 0.02–0.04; denoiser ≤ 0.005. The ~8× gap is real and drives the per-locus grids used from here on.

stage 2 — the locus is concept-dependent

locus by concept matrix
fig 3. the locus × concept matrix — four concepts, each sampled on its own per-locus window.
best coherent effect per cell (Δ margin, ×base = gradient ratio)
concepttext encoderdenoiser (DiT)who wins
brightness+1.50 (×1.00)+0.27 (×0.81)encoder
warmth+1.05 (×0.65)+4.85 (×0.70)DiT (4.6×)
night+0.83 (×0.60)+1.28 (×0.67)both / DiT cleaner
painting+2.13 (×0.41) ⚠−0.20 (wrong way)encoder only
key finding. There is no universal steering surface. Stage 2a's "encoder good, DiT bad" was a brightness artifact. Across four concepts the winning locus moves: brightness is encoder-only, warmth is denoiser-dominant, night works at both, and painting exists only at the encoder — the denoiser steers painting the wrong way. A concept is steerable only at the locus where it is linearly separable.

Caveat — the guard penalises style. The coherence guard is gradient-based, so it false-negatives painting: the encoder-at-0.04 output is a clean, deliberately painterly illustration (visually the best result in the sweep) but reads as collapse because a painting legitimately has lower pixel gradient. It simultaneously reads "night @ 0.04" as incoherent — correctly, there it is washed out. Any style-ish concept needs a concept-calibrated threshold or a subjective check, not one global floor.

stage 3 — the concept is distributed

Injecting one layer at a time to localise the concept: at both loci, every single layer is a no-op.

per-layer ablation margins
fig 4. margin vs layer index for one-at-a-time injection (brightness). All 36 encoder layers and all 32 DiT blocks stay inside ±0.14 of baseline; the whole-stack markers sit far outside.
stage 3 — per-layer deltas vs whole-stack
locuslayerssingle-layer Δ rangewhole-stack Δ
text encoder36−0.119 … +0.059+0.92
denoiser32−0.141 … +0.091+0.43

The largest single-layer move is ~8× smaller than the whole-stack effect at the same coefficient, and its sign is often opposite. The per-layer deltas are anti-aligned on average (encoder mean −0.049, DiT −0.023) while both whole-stack effects are positive. The steering signal is not a sum of independent per-layer nudges — it emerges from the stack acting together. There is no "steer layer 7" shortcut at either locus.

stage 6 — cross-model transfer

Training the same contrast pairs independently on turbo (8 steps, CFG=1) and the non-turbo base (40 steps, true CFG) yields nearly identical directions:

cosine between independently-trained vectors
locuscosine(turbo, base)
text encoder1.000 (all 36 layers)
denoiser0.983 mean (0.953–0.997)
cross-model transfer grid
fig 5. each model's vector applied to the other model. rows: pairing × locus; columns: coefficient. both directions move the margin the right way.
cross-application, native render regime per model
pairingtext encoder Δdenoiser Δ
turbo-trained → base+0.765+0.225
base-trained → turbo+1.498+0.368

A first pass looked asymmetric (the denoiser went the wrong way for turbo→base), but that was a confound: base was being rendered in turbo's regime (8 steps, CFG=1), which is off-distribution for it. Giving each model its native render settings removes the artifact entirely. The direction is a property of the concept and the contrast data, not the weights.

caveats & open questions

reproducing this

Everything is deterministic given a seed and the configs in the repo.

hardware & environment

get the code & the models

git clone <repo> image-repeng && cd image-repeng
just box          # enter the toolbox container
just venv         # chain .venv -> /opt/venv, pip-install the project
just doctor-venv  # verify ROCm torch is the gfx1151 build
just download     # Qwen/Qwen-Image-2.1-Turbo + Qwen/Qwen-Image-2.1 into the shared HF cache
just pairs        # build the contrast-pair datasets into data/pairs/

run the ladder

just smoke                        # harness proof (brightness, both loci)
just calibrate                    # measure the coherent coefficient window per locus
just matrix                       # locus x concept matrix
just ablate                       # per-layer ablation
just transfer                     # cross-model transfer
just report                       # regenerate results/SUMMARY.md from metrics.json

# long runs go through the guarded launcher (absolute paths, drift-proof):
bin/run_stage.sh 02_locus_matrix  # -> logs/02_locus_matrix.log

what to expect

artifacts per stage
pathcontents
experiments/<stage>/config.yamlthe exact config for a stage
results/<stage>/metrics.jsonper-cell margin, luminance, gradient, drift, coherence
results/<stage>/cv_*.safetensorsthe trained control vectors (per locus, per concept)
results/<stage>/*.pngrendered grids / contact sheets
results/SUMMARY.mdaggregated table (just report)
logs/<stage>.logfull run log

repo layout

src/image_repeng/    steering.py (hooks, PCA-1 train, injection) · stages.py · probe.py
                     models.py (gfx1151 env, load_pipeline) · datasets.py · report.py · cli.py
experiments/<stage>/ one config.yaml per stage
data/pairs/          contrast-pair datasets (150 train / 50 held-out per concept)
results/<stage>/     metrics.json · cv_*.safetensors · figures
docs/                METHOD.md · FINDINGS.md · PRIOR_ART.md
bin/run_stage.sh     guarded launcher for long GPU runs
justfile             box · venv · doctor-venv · download · pairs · smoke · calibrate ·
                     matrix · ablate · transfer · report · run <exp>

licence & citation

Code: Apache-2.0. Weights: Qwen Research License (non-commercial) — derived control vectors are redistributed with attribution and the "Built with Qwen" notice. Method after Zou et al., Representation Engineering (arXiv:2310.01405); reference implementation vgel/repeng (MIT).

@misc{english2026imagerepeng,
  title  = {Steering an image model with control vectors: a first cut},
  author = {English, Paul M.},
  year   = {2026},
  note   = {Representation engineering for a diffusion image generator; v0.1},
  url    = {https://0-f.io/image-repeng/}
}

first cut · numbers regenerate from results/**/metrics.json · comments and corrections welcome