ring-sae / README.md
grrrml's picture
Upload README.md with huggingface_hub
e97fb70 verified
|
Raw History Blame Contribute Delete
2.95 kB
---
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.