Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,107 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
base_model: black-forest-labs/FLUX.1-schnell
|
| 4 |
+
datasets:
|
| 5 |
+
- yvdao/midjourney-v6
|
| 6 |
+
library_name: pytorch
|
| 7 |
+
tags:
|
| 8 |
+
- mechanistic-interpretability
|
| 9 |
+
- sparse-autoencoder
|
| 10 |
+
- transcoder
|
| 11 |
+
- circuit-tracing
|
| 12 |
+
- diffusion
|
| 13 |
+
- flux
|
| 14 |
+
- text-to-image
|
| 15 |
---
|
| 16 |
+
|
| 17 |
+
# DifFRACT: Diffusion Feature Reconstruction and Attribution for Circuit Tracing
|
| 18 |
+
|
| 19 |
+
<a href="https://arxiv.org/abs/2606.15796"><img src="https://img.shields.io/badge/Paper-PDF-b31b1b.svg" height=22.5></a>
|
| 20 |
+
<a href="https://huggingface.co/Artalmaz31/DifFRACT"><img src="https://img.shields.io/badge/🤗-Weights-yellow" height=22.5></a>
|
| 21 |
+
<a href="https://colab.research.google.com/github/Artalmaz31/DifFRACT/blob/main/walkthrough.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" height=22.5></a>
|
| 22 |
+
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-green" height=22.5></a>
|
| 23 |
+
|
| 24 |
+
Trained **timestep-conditioned transcoders** and **SAE baselines** for the [FLUX.1[schnell]](https://huggingface.co/black-forest-labs/FLUX.1-schnell) text-to-image diffusion transformer (MM-DiT), accompanying the paper *DifFRACT: Diffusion Feature Reconstruction and Attribution for Circuit Tracing* ([PDF](https://arxiv.org/abs/2606.15796)).
|
| 25 |
+
|
| 26 |
+
A transcoder decomposes an MLP sublayer into a sparse linear combination of interpretable features; conditioning it on the denoising timestep lets a single transcoder track how a feature behaves across the diffusion trajectory. Substituting these transcoders into a frozen Local Replacement Model yields the attribution graphs and circuit-guided interventions studied in the paper. The code to load and use these weights is at the companion repository ([GitHub](https://github.com/Artalmaz31/DifFRACT)).
|
| 27 |
+
|
| 28 |
+
## Contents
|
| 29 |
+
|
| 30 |
+
40 PyTorch checkpoints in two folders. Every checkpoint is a `state_dict` for a `TemporalAwareTranscoder` module (the SAE baseline shares the identical architecture).
|
| 31 |
+
|
| 32 |
+
| Folder | Files | Naming | Streams | Layers |
|
| 33 |
+
|---|---|---|---|---|
|
| 34 |
+
| `temporal-aware-transcoders/` | 34 | `transcoder_{stream}_{layer}.pt` | `img`, `txt` | 0-15 and 18 |
|
| 35 |
+
| `temporal-aware-saes/` | 6 | `sae_{stream}_{layer}.pt` | `img`, `txt` | 6, 12, 18 |
|
| 36 |
+
|
| 37 |
+
The 32 transcoders for layers 0–15 (both streams) are the set analysed by the Local Replacement Model; layer 18 (and the SAEs at 6/12/18) support the sparsity–faithfulness comparison.
|
| 38 |
+
|
| 39 |
+
## Model architecture
|
| 40 |
+
|
| 41 |
+
Each module maps an MLP **input** `x` to its **output** `ŷ`, conditioned on the diffusion timestep `t`:
|
| 42 |
+
|
| 43 |
+
- a sinusoidal timestep embedding → 2-layer SiLU MLP → linear head producing FiLM `(scale, shift)`;
|
| 44 |
+
- modulation `x_mod = x ⊙ (1 + scale) + shift`;
|
| 45 |
+
- a ReLU encoder `z = ReLU(W_enc x_mod + b_enc)` (sparse code);
|
| 46 |
+
- a unit-norm linear decoder `ŷ = W_dec z + b_dec`.
|
| 47 |
+
|
| 48 |
+
| Hyperparameter | Value |
|
| 49 |
+
|---|---|
|
| 50 |
+
| Base model | FLUX.1[schnell], MM-DiT, `d_model = 3072` |
|
| 51 |
+
| Expansion factor | 16 (`d_feat = 49152`) |
|
| 52 |
+
| Timestep embedding dim | 256 |
|
| 53 |
+
| Sparsity | L1, `λ_img = 3e-4`, `λ_txt = 5e-5` |
|
| 54 |
+
| Reconstruction loss | variance-normalized MSE |
|
| 55 |
+
| Optimizer | AdamW, lr `2e-4`, weight decay `0`, CosineAnnealingLR |
|
| 56 |
+
| Activation buffer / batch | `1e6` / `4096` |
|
| 57 |
+
| Inference steps / guidance / resolution | 4 / 0 / 512×512 |
|
| 58 |
+
| Training prompts | [`yvdao/midjourney-v6`](https://huggingface.co/datasets/yvdao/midjourney-v6) |
|
| 59 |
+
|
| 60 |
+
The **SAE baseline** is architecturally identical but autoencodes the MLP **output** (input = target), so its reconstruction error is directly comparable to a transcoder's.
|
| 61 |
+
|
| 62 |
+
## Usage
|
| 63 |
+
|
| 64 |
+
Install the companion code ([GitHub](https://github.com/Artalmaz31/DifFRACT)), then:
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
from huggingface_hub import snapshot_download
|
| 68 |
+
from transcoder_training.transcoder import load_transcoders
|
| 69 |
+
|
| 70 |
+
transcoders = load_transcoders(
|
| 71 |
+
f"{path}/temporal-aware-transcoders",
|
| 72 |
+
layers=range(16),
|
| 73 |
+
d_model=3072,
|
| 74 |
+
expansion_factor=16,
|
| 75 |
+
time_embed_dim=256,
|
| 76 |
+
)
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
Loading an individual SAE baseline:
|
| 80 |
+
|
| 81 |
+
```python
|
| 82 |
+
import torch
|
| 83 |
+
from transcoder_training.transcoder import TemporalAwareSAE
|
| 84 |
+
|
| 85 |
+
sae = TemporalAwareSAE(d_model=3072, expansion_factor=16, time_embed_dim=256)
|
| 86 |
+
sae.load_state_dict(torch.load(f"{path}/temporal-aware-saes/sae_img_12.pt", map_location="cpu"))
|
| 87 |
+
sae.eval()
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
The end-to-end pipeline (Local Replacement Model, attribution graph, intervention) is demonstrated in `walkthrough.ipynb` in the companion repository.
|
| 91 |
+
|
| 92 |
+
## Citation
|
| 93 |
+
|
| 94 |
+
```bibtex
|
| 95 |
+
@misc{mazur2026diffractdiffusionfeaturereconstruction,
|
| 96 |
+
title={DifFRACT: Diffusion Feature Reconstruction and Attribution for Circuit Tracing},
|
| 97 |
+
author={Artyom Mazur and Nina Konovalova and Aibek Alanov},
|
| 98 |
+
year={2026},
|
| 99 |
+
eprint={2606.15796},
|
| 100 |
+
archivePrefix={arXiv},
|
| 101 |
+
primaryClass={cs.CV},
|
| 102 |
+
url={https://arxiv.org/abs/2606.15796},
|
| 103 |
+
}
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
- Base model: [`black-forest-labs/FLUX.1-schnell`](https://huggingface.co/black-forest-labs/FLUX.1-schnell)
|
| 107 |
+
- License: Apache-2.0
|