File size: 2,953 Bytes
5b5ecae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e97fb70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b5ecae
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
tags:
  - sparse-autoencoder
  - diffusion
  - concept-erasure
base_model:
  - black-forest-labs/FLUX.1-dev
  - CompVis/stable-diffusion-v1-4
---

# Sparse autoencoders of RING

The sparse autoencoders (SAEs) used in *One RING to Unlearn Them All: Concept Erasure from the Consensus of
Unlearned Models*. Code: [github.com/genwro-ai/ring](https://github.com/genwro-ai/ring).

One TopK SAE per block, with k = 256 and 32 times as many features as the block has channels, trained on
activations of the base model for 500 concept prompts and 4,500 COCO captions.

| directory | base model | block | features |
|---|---|---|---|
| `flux/transformer_blocks.18` | FLUX.1-dev | `transformer_blocks.18` | 98,304 |
| `flux/single_transformer_blocks.10` | FLUX.1-dev | `single_transformer_blocks.10` | 98,304 |
| `flux/single_transformer_blocks.20` | FLUX.1-dev | `single_transformer_blocks.20` | 98,304 |
| `sd14/down_blocks.2.attentions.1` | SD v1.4 | `down_blocks.2.attentions.1` | 40,960 |
| `sd14/mid_block.attentions.0` | SD v1.4 | `mid_block.attentions.0` | 40,960 |
| `sd14/up_blocks.1.attentions.1` | SD v1.4 | `up_blocks.1.attentions.1` | 40,960 |

Each directory holds `sae.safetensors` and `cfg.json`. FLUX.1-dev: activations of the image stream at 8 of 28
denoising steps, 512 px. SD v1.4: 8 of 50 DDIM steps.

```python
from huggingface_hub import snapshot_download
from ring.sae.sae import Sae

root = snapshot_download("grrrml/ring-sae")
sae = Sae.load_from_disk(f"{root}/flux/transformer_blocks.18", device="cuda")
```

## Firing rates

`firing_rates/` holds the firing frequency of every feature on the base model and on each voter, the input of
the feature selection (`python -m ring.scripts.select_features`), so the vote can be repeated without the voters:

| directory | models | blocks |
|---|---|---|
| `firing_rates/flux` | `base`, `esd`, `gem`, `eraseflow` | the three blocks above and three more that the paper does not use |
| `firing_rates/sd14_up1` | `base`, `esd`, `mace`, `rece`, `stereo` | `up_blocks.1.attentions.1` and two more that the paper does not use |
| `firing_rates/sd14_down2_mid` | `base`, `esd`, `mace`, `rece`, `stereo` | `down_blocks.2.attentions.1`, `mid_block.attentions.0` |

```bash
python -m ring.scripts.select_features --base firing_rates/flux/base \
    --voter esd=firing_rates/flux/esd gem=firing_rates/flux/gem eraseflow=firing_rates/flux/eraseflow --out_dir features/flux
```

## License

The SAEs for FLUX.1-dev are derived from activations of FLUX.1-dev and are subject to the
[FLUX.1-dev Non-Commercial License](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md).
The SAEs for SD v1.4 follow the CreativeML Open RAIL-M license of Stable Diffusion v1.4.

The scripts of the code repository take these directories as `--sae <block>=<directory>` (FLUX.1-dev) and
`--sae_ckpt <directory>` (SD v1.4). The feature sets that RING scales are in `features/` of the code repository.