# glenrunc/slopformer architecture

> Architecture diagram of the GitHub repository glenrunc/slopformer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/glenrunc/slopformer
- Repository: https://github.com/glenrunc/slopformer

## Overview

Slopformer is a Vision Transformer reference implementation with modified attention, positional encodings, residual layers, and ImageNet-BR label handling. Its user-facing paths are image classification with a retrofitted pretrained ViT, training from an ImageFolder-style dataset, and attention-rollout visualization. The graph also shows the model’s internal embedding, encoder, and attention layers. Relationships are supported by the README and excerpted sources; rollout details are limited to the README and SOURCE INDEX references.

Main entry points: [`slopformer/model.py`](https://github.com/glenrunc/slopformer/blob/main/slopformer/model.py) (Slopformer Model), [`scripts/train.py`](https://github.com/glenrunc/slopformer/blob/main/scripts/train.py) (Training Loop), [`scripts/classify.py`](https://github.com/glenrunc/slopformer/blob/main/scripts/classify.py) (Image Classifier), [`slopformer/data.py`](https://github.com/glenrunc/slopformer/blob/main/slopformer/data.py) (Dataset & Augmentation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model_core["Model Core"]
  node_model["Slopformer Model<br/>[model.py]"]
  node_embedding["Patch &amp; Position<br/>[embeddings.py]"]
  node_encoder["Encoder Layers<br/>[layers.py]"]
  node_attention["Cringe Attention<br/>[attention.py]"]
end

subgraph group_data_labels["Data &amp; Labels"]
  node_dataset["Dataset &amp; Augmentation<br/>[data.py]"]
  node_labels["Label Resolution<br/>[labels.py]"]
end

subgraph group_workflows["User Workflows"]
  node_classify["Image Classifier<br/>[classify.py]"]
  node_rollout["Attention Rollout<br/>[rollout.py]"]
end

subgraph group_training["Training"]
  node_train["Training Loop<br/>[train.py]"]
  node_loss["Yapping Loss<br/>[losses.py]"]
  node_optimizer["SMGO Optimizer<br/>[optim.py]"]
end

node_user(("Image User"))
node_image["Image Input"]
node_timm{{"timm Hub"}}
node_dataset_files[("ImageFolder Dataset")]

node_user -->|"classifies with"| node_classify
node_user -->|"requests rollout"| node_rollout
node_user -->|"starts training"| node_train
node_user -->|"provides"| node_image
node_image -->|"supplies image"| node_classify
node_classify -->|"loads and runs"| node_model
node_model -->|"loads checkpoint"| node_timm
node_model -->|"patches attention"| node_attention
node_classify -->|"resolves prediction"| node_labels
node_model -->|"embeds image"| node_embedding
node_model -->|"runs blocks"| node_encoder
node_encoder -->|"uses attention"| node_attention
node_rollout -->|"reads attention"| node_model
node_dataset_files -->|"provides samples"| node_dataset
node_train -->|"loads batches"| node_dataset
node_dataset -->|"uses class set"| node_labels
node_train -->|"trains model"| node_model
node_train -->|"computes objective"| node_loss
node_train -->|"updates parameters"| node_optimizer

click node_classify "https://github.com/glenrunc/slopformer/blob/main/scripts/classify.py"
click node_rollout "https://github.com/glenrunc/slopformer/blob/main/scripts/rollout.py"
click node_train "https://github.com/glenrunc/slopformer/blob/main/scripts/train.py"
click node_model "https://github.com/glenrunc/slopformer/blob/main/slopformer/model.py"
click node_embedding "https://github.com/glenrunc/slopformer/blob/main/slopformer/embeddings.py"
click node_encoder "https://github.com/glenrunc/slopformer/blob/main/slopformer/layers.py"
click node_attention "https://github.com/glenrunc/slopformer/blob/main/slopformer/attention.py"
click node_dataset "https://github.com/glenrunc/slopformer/blob/main/slopformer/data.py"
click node_labels "https://github.com/glenrunc/slopformer/blob/main/slopformer/labels.py"
click node_loss "https://github.com/glenrunc/slopformer/blob/main/slopformer/losses.py"
click node_optimizer "https://github.com/glenrunc/slopformer/blob/main/slopformer/optim.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_model,node_embedding,node_encoder,node_attention,node_user toneBlue
class node_dataset,node_labels,node_dataset_files toneAmber
class node_classify,node_rollout toneMint
class node_train,node_loss,node_optimizer toneRose
class node_image,node_timm toneIndigo
```

## Components

### Model Core

- [Slopformer Model](https://github.com/glenrunc/slopformer/blob/main/slopformer/model.py): `slopformer/model.py`
- [Patch & Position](https://github.com/glenrunc/slopformer/blob/main/slopformer/embeddings.py): `slopformer/embeddings.py`
- [Encoder Layers](https://github.com/glenrunc/slopformer/blob/main/slopformer/layers.py): `slopformer/layers.py`
- [Cringe Attention](https://github.com/glenrunc/slopformer/blob/main/slopformer/attention.py): `slopformer/attention.py`

### Data & Labels

- [Dataset & Augmentation](https://github.com/glenrunc/slopformer/blob/main/slopformer/data.py): `slopformer/data.py`
- [Label Resolution](https://github.com/glenrunc/slopformer/blob/main/slopformer/labels.py): `slopformer/labels.py`

### User Workflows

- [Image Classifier](https://github.com/glenrunc/slopformer/blob/main/scripts/classify.py): `scripts/classify.py`
- [Attention Rollout](https://github.com/glenrunc/slopformer/blob/main/scripts/rollout.py): `scripts/rollout.py`

### Training

- [Training Loop](https://github.com/glenrunc/slopformer/blob/main/scripts/train.py): `scripts/train.py`
- [Yapping Loss](https://github.com/glenrunc/slopformer/blob/main/slopformer/losses.py): `slopformer/losses.py`
- [SMGO Optimizer](https://github.com/glenrunc/slopformer/blob/main/slopformer/optim.py): `slopformer/optim.py`

### Other components

- **Image User**
- **Image Input**
- **timm Hub**
- **ImageFolder Dataset**

## Connections

- Image User → Image Classifier: classifies with (evidence: `README.md`)
- Image User → Attention Rollout: requests rollout (evidence: `README.md`)
- Image User → Training Loop: starts training (evidence: `README.md`)
- Image User → Image Input: provides (evidence: `README.md`)
- Image Input → Image Classifier: supplies image (evidence: `scripts/classify.py`)
- Image Classifier → Slopformer Model: loads and runs (evidence: `scripts/classify.py`)
- Slopformer Model → timm Hub: loads checkpoint (evidence: `slopformer/model.py`)
- Slopformer Model → Cringe Attention: patches attention (evidence: `slopformer/model.py`)
- Image Classifier → Label Resolution: resolves prediction (evidence: `scripts/classify.py`)
- Slopformer Model → Patch & Position: embeds image (evidence: `slopformer/model.py`)
- Slopformer Model → Encoder Layers: runs blocks (evidence: `slopformer/model.py`)
- Encoder Layers → Cringe Attention: uses attention (evidence: `slopformer/layers.py`)
- Attention Rollout → Slopformer Model: reads attention (evidence: `README.md`)
- ImageFolder Dataset → Dataset & Augmentation: provides samples (evidence: `slopformer/data.py`)
- Training Loop → Dataset & Augmentation: loads batches (evidence: `scripts/train.py`)
- Dataset & Augmentation → Label Resolution: uses class set (evidence: `slopformer/data.py`)
- Training Loop → Slopformer Model: trains model (evidence: `scripts/train.py`)
- Training Loop → Yapping Loss: computes objective (evidence: `scripts/train.py`)
- Training Loop → SMGO Optimizer: updates parameters (evidence: `scripts/train.py`)
