# koushiksrivats/robust-concept-erasing architecture

> Architecture diagram of the GitHub repository koushiksrivats/robust-concept-erasing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/koushiksrivats/robust-concept-erasing
- Repository: https://github.com/koushiksrivats/robust-concept-erasing

## Overview

STEREO is a research implementation for adversarially robust concept erasure in text-to-image diffusion models. Its main workflow trains Stage 1 to iteratively erase and attack a concept, then trains Stage 2 on anchor concepts and adversarial prompts; a separate attack mode evaluates robustness. Gallery images can be prepared and generated images used for evaluation. Training and inference share a Stable Diffusion wrapper, while textual-inversion training uses an image-and-prompt dataset. Stage descriptions and links are documented in the README; detailed internal calls are omitted where excerpts do not establish them.

Main entry points: [`train.py`](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/train.py) (Training CLI), [`utils/stereo.py`](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/stereo.py) (Robust erasure), [`generate_images.py`](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/generate_images.py) (Image generation), [`utils/dataset.py`](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/dataset.py) (Gallery dataset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Training workflow"]
  node_training_cli["Training CLI<br/>[train.py]"]
  node_search_stage["Adversarial search<br/>[stereo.py]"]
  node_inversion["Concept inversion<br/>[stereo.py]"]
  node_gallery_dataset["Gallery dataset<br/>[dataset.py]"]
  node_robust_erase["Robust erasure<br/>[stereo.py]"]
  node_guidance["Guidance methods<br/>[apg.py]"]
  node_attack_eval["Attack evaluation<br/>[stereo.py]"]
end

subgraph group_runtime["Diffusion runtime"]
  node_diffuser["Diffusion runtime<br/>[utils.py]"]
  node_erased_weights["Erased weights"]
end

subgraph group_generation["Image generation and evaluation"]
  node_image_cli["Image generation<br/>[generate_images.py]"]
  node_pretrained_model["Pretrained diffusion model"]
  node_attack_suites["External attack suites"]
end

node_researcher(("Researcher"))

node_researcher -->|"configures training"| node_training_cli
node_training_cli -->|"runs Stage 1"| node_search_stage
node_training_cli -->|"runs Stage 2"| node_robust_erase
node_search_stage -->|"includes inversion attacks"| node_inversion
node_search_stage -->|"provides adversarial prompts"| node_robust_erase
node_gallery_dataset -.->|"supplies training examples"| node_inversion
node_researcher -->|"requests images"| node_image_cli
node_image_cli -->|"loads model"| node_pretrained_model
node_image_cli -->|"loads checkpoint"| node_erased_weights
node_robust_erase -->|"saves model weights"| node_erased_weights
node_training_cli -->|"runs attack mode"| node_attack_eval
node_attack_eval -->|"evaluated with"| node_attack_suites
node_robust_erase -.->|"uses guidance methods"| node_guidance
node_training_cli -->|"initializes runtime"| node_diffuser

click node_training_cli "https://github.com/koushiksrivats/robust-concept-erasing/blob/main/train.py"
click node_search_stage "https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/stereo.py"
click node_inversion "https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/stereo.py"
click node_gallery_dataset "https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/dataset.py"
click node_robust_erase "https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/stereo.py"
click node_guidance "https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/apg.py"
click node_attack_eval "https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/stereo.py"
click node_diffuser "https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/utils.py"
click node_image_cli "https://github.com/koushiksrivats/robust-concept-erasing/blob/main/generate_images.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_training_cli,node_search_stage,node_inversion,node_gallery_dataset,node_robust_erase,node_guidance,node_attack_eval toneBlue
class node_diffuser,node_erased_weights toneAmber
class node_image_cli,node_pretrained_model,node_attack_suites toneMint
class node_researcher toneIndigo
```

## Components

### Training workflow

- [Training CLI](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/train.py): `train.py`
- [Adversarial search](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/stereo.py): `utils/stereo.py`
- [Concept inversion](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/stereo.py): `utils/stereo.py`
- [Gallery dataset](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/dataset.py): `utils/dataset.py`
- [Robust erasure](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/stereo.py): `utils/stereo.py`
- [Guidance methods](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/apg.py): `utils/apg.py`
- [Attack evaluation](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/stereo.py): `utils/stereo.py`

### Diffusion runtime

- [Diffusion runtime](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/utils/utils.py): `utils/utils.py`
- **Erased weights**

### Image generation and evaluation

- [Image generation](https://github.com/koushiksrivats/robust-concept-erasing/blob/main/generate_images.py): `generate_images.py`
- **Pretrained diffusion model**
- **External attack suites**

### Other components

- **Researcher**

## Connections

- Researcher → Training CLI: configures training (evidence: `README.md`)
- Training CLI → Adversarial search: runs Stage 1 (evidence: `train.py`)
- Training CLI → Robust erasure: runs Stage 2 (evidence: `README.md`)
- Adversarial search → Concept inversion: includes inversion attacks (evidence: `README.md`)
- Adversarial search → Robust erasure: provides adversarial prompts (evidence: `README.md`)
- Gallery dataset → Concept inversion: supplies training examples (evidence: `utils/stereo.py`)
- Researcher → Image generation: requests images (evidence: `README.md`)
- Image generation → Pretrained diffusion model: loads model (evidence: `generate_images.py`)
- Image generation → Erased weights: loads checkpoint (evidence: `generate_images.py`)
- Robust erasure → Erased weights: saves model weights (evidence: `utils/stereo.py`)
- Training CLI → Attack evaluation: runs attack mode (evidence: `train.py`)
- Attack evaluation → External attack suites: evaluated with (evidence: `README.md`)
- Robust erasure → Guidance methods: uses guidance methods (evidence: `utils/stereo.py`)
- Training CLI → Diffusion runtime: initializes runtime (evidence: `train.py`)
