# p0rt/platos-key-small-models architecture

> Architecture diagram of the GitHub repository p0rt/platos-key-small-models, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/p0rt/platos-key-small-models
- Repository: https://github.com/p0rt/platos-key-small-models

## Overview

This repository runs a CPU-based experiment that tests whether hidden-state keys can be transplanted between frozen language models. The workflow prepares CounterFact facts, extracts recall status and layer keys for each model, fits and evaluates donor-to-recipient transfers, then aggregates pair results. The swap stage also compares self-swaps, controls, ridge fits, and mutual-nearest-neighbor layer choices. Edges reflect the README workflow and shown imports/calls; the pair runner and some swap internals were not fully sampled.

Main entry points: [`src/swap.py`](https://github.com/p0rt/platos-key-small-models/blob/main/src/swap.py) (Fit and evaluate swaps), [`src/extract.py`](https://github.com/p0rt/platos-key-small-models/blob/main/src/extract.py) (Extract model keys), [`src/common.py`](https://github.com/p0rt/platos-key-small-models/blob/main/src/common.py) (Model and patch utilities), [`src/prepare_facts.py`](https://github.com/p0rt/platos-key-small-models/blob/main/src/prepare_facts.py) (Prepare facts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Fact preparation"]
  node_prepare["Prepare facts<br/>[prepare_facts.py]"]
  node_facts["Fact list"]
end

subgraph group_runtime["Model representations"]
  node_extract["Extract model keys<br/>[extract.py]"]
  node_common["Model and patch utilities<br/>[common.py]"]
  node_keys["Per-model key archives"]
end

subgraph group_experiment["Transfer experiments"]
  node_swap["Fit and evaluate swaps<br/>[swap.py]"]
  node_pair_results["Pair results"]
end

subgraph group_reporting["Results reporting"]
  node_summarize["Summarize pairs<br/>[summarize.py]"]
  node_summary["Aggregate results"]
end

node_researcher(("Experimenter"))
node_counterfact[("CounterFact dataset")]
node_model_hub["Pretrained models"]

node_researcher -->|"runs workflow"| node_prepare
node_counterfact -->|"provides facts"| node_prepare
node_prepare -->|"writes list"| node_facts
node_researcher -->|"runs per model"| node_extract
node_facts -->|"supplies facts"| node_extract
node_extract -->|"calls utilities"| node_common
node_common -->|"loads checkpoints"| node_model_hub
node_extract -->|"writes archives"| node_keys
node_researcher -->|"runs model pairs"| node_swap
node_facts -->|"supplies facts"| node_swap
node_keys -->|"provides layer keys"| node_swap
node_swap -->|"calls utilities"| node_common
node_common -->|"loads checkpoints"| node_model_hub
node_swap -->|"writes pair metrics"| node_pair_results
node_researcher -->|"runs summary"| node_summarize
node_pair_results -->|"reads pair files"| node_summarize
node_summarize -->|"writes aggregate"| node_summary

click node_prepare "https://github.com/p0rt/platos-key-small-models/blob/main/src/prepare_facts.py"
click node_extract "https://github.com/p0rt/platos-key-small-models/blob/main/src/extract.py"
click node_common "https://github.com/p0rt/platos-key-small-models/blob/main/src/common.py"
click node_swap "https://github.com/p0rt/platos-key-small-models/blob/main/src/swap.py"
click node_pair_results "https://github.com/p0rt/platos-key-small-models/tree/main/results"
click node_summarize "https://github.com/p0rt/platos-key-small-models/blob/main/src/summarize.py"
click node_summary "https://github.com/p0rt/platos-key-small-models/tree/main/results"

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_prepare,node_facts toneBlue
class node_extract,node_common,node_keys,node_counterfact toneAmber
class node_swap,node_pair_results toneMint
class node_summarize,node_summary toneRose
class node_researcher,node_model_hub toneIndigo
```

## Components

### Fact preparation

- [Prepare facts](https://github.com/p0rt/platos-key-small-models/blob/main/src/prepare_facts.py): `src/prepare_facts.py`
- **Fact list**

### Model representations

- [Extract model keys](https://github.com/p0rt/platos-key-small-models/blob/main/src/extract.py): `src/extract.py`
- [Model and patch utilities](https://github.com/p0rt/platos-key-small-models/blob/main/src/common.py): `src/common.py`
- **Per-model key archives**

### Transfer experiments

- [Fit and evaluate swaps](https://github.com/p0rt/platos-key-small-models/blob/main/src/swap.py): `src/swap.py`
- [Pair results](https://github.com/p0rt/platos-key-small-models/tree/main/results): `results`

### Results reporting

- [Summarize pairs](https://github.com/p0rt/platos-key-small-models/blob/main/src/summarize.py): `src/summarize.py`
- [Aggregate results](https://github.com/p0rt/platos-key-small-models/tree/main/results): `results`

### Other components

- **Experimenter**
- **CounterFact dataset**
- **Pretrained models**

## Connections

- Experimenter → Prepare facts: runs workflow (evidence: `README.md`)
- CounterFact dataset → Prepare facts: provides facts (evidence: `README.md`)
- Prepare facts → Fact list: writes list (evidence: `README.md`)
- Experimenter → Extract model keys: runs per model (evidence: `README.md`)
- Fact list → Extract model keys: supplies facts (evidence: `README.md`)
- Extract model keys → Model and patch utilities: calls utilities (evidence: `src/extract.py`)
- Model and patch utilities → Pretrained models: loads checkpoints (evidence: `src/common.py`)
- Extract model keys → Per-model key archives: writes archives (evidence: `README.md`)
- Experimenter → Fit and evaluate swaps: runs model pairs (evidence: `README.md`)
- Fact list → Fit and evaluate swaps: supplies facts (evidence: `README.md`)
- Per-model key archives → Fit and evaluate swaps: provides layer keys (evidence: `README.md`)
- Fit and evaluate swaps → Model and patch utilities: calls utilities (evidence: `src/swap.py`)
- Model and patch utilities → Pretrained models: loads checkpoints (evidence: `src/common.py`)
- Fit and evaluate swaps → Pair results: writes pair metrics (evidence: `README.md`)
- Experimenter → Summarize pairs: runs summary (evidence: `README.md`)
- Pair results → Summarize pairs: reads pair files (evidence: `README.md`)
- Summarize pairs → Aggregate results: writes aggregate (evidence: `src/summarize.py`)
