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?
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.
results/**/metrics.json. Code is Apache-2.0; the Qwen weights are under the Qwen Research License (non-commercial).
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.
A from-scratch port that keeps the paper's core honest and changes only what the architecture forces.
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:
just calibrate, never guessed.transformer_blocks, injected at every step. The part that actually paints.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.
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.
| stage | question | state |
|---|---|---|
| 00 | throughput & attention backend bake-off | closed |
| 01 | smoke — does the harness work end to end? | closed |
| 02a | coefficient calibration per locus | closed |
| 02 | locus × concept matrix | closed |
| 03 | per-layer ablation — where is the concept? | closed |
| 06 | cross-model transfer (turbo ↔ non-turbo) | closed |
| 04/05 | controls, jailbreak probe, galleries | queued |
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).
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.
probe.evaluate / probe.is_coherent, and it changes how every later result reads.

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.

| locus | 0.005 | 0.01 | 0.02 | 0.04 |
|---|---|---|---|---|
| text encoder | −0.23 | +0.02 | +0.92 | +1.48 |
| denoiser | +0.43 | incoherent | incoherent | −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.

| concept | text encoder | denoiser (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 |
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.
Injecting one layer at a time to localise the concept: at both loci, every single layer is a no-op.

| locus | layers | single-layer Δ range | whole-stack Δ |
|---|---|---|---|
| text encoder | 36 | −0.119 … +0.059 | +0.92 |
| denoiser | 32 | −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.
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:
| locus | cosine(turbo, base) |
|---|---|
| text encoder | 1.000 (all 36 layers) |
| denoiser | 0.983 mean (0.953–0.997) |

| pairing | text 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.
Everything is deterministic given a seed and the configs in the repo.
gfx1151), 128 GB LPDDR5X unified memory. Kernel cmdline sets amdgpu.gttsize=126976 and ttm.pages_limit=32505856; export HSA_ENABLE_SDMA=0 before importing torch.image-repeng kyuz0/amd-strix-halo toolbox — ROCm PyTorch 2.14.0a0+rocm7.15.0, Python 3.13, diffusers 0.42.1, transformers 5.22.0./opt/venv inside the image, not the base interpreter — so uv venv --system-site-packages cannot see it. We chain the project .venv to /opt/venv with a .pth and install the project with pip (uv's resolver insists on a CUDA torch wheel and would shadow the gfx1151 build).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/
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
| path | contents |
|---|---|
experiments/<stage>/config.yaml | the exact config for a stage |
results/<stage>/metrics.json | per-cell margin, luminance, gradient, drift, coherence |
results/<stage>/cv_*.safetensors | the trained control vectors (per locus, per concept) |
results/<stage>/*.png | rendered grids / contact sheets |
results/SUMMARY.md | aggregated table (just report) |
logs/<stage>.log | full run log |
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>
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