# thrillcrazyer/loopus architecture

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

- Interactive diagram: https://gitdiagram.com/thrillcrazyer/loopus
- Repository: https://github.com/thrillcrazyer/loopus

## Overview

LoopUS converts pretrained language models into latent-refinement models, then trains, evaluates, generates from, and chats with those models. The main workflow runs through training configuration and streaming data, the LDS model’s encoder/recursive reasoning/decoder, and checkpointing; inference loads saved models for evaluation or generation. README-described capabilities include selective gating, random deep supervision, confidence-based early exit, SFT, and lm-eval. Some links reflect documented workflows because the relevant source excerpts are incomplete.

Main entry points: [`training_runtime.py`](https://github.com/thrillcrazyer/loopus/blob/main/training_runtime.py) (Training runtime), [`models/modeling_lds.py`](https://github.com/thrillcrazyer/loopus/blob/main/models/modeling_lds.py) (Looped reasoning), [`utils/inference.py`](https://github.com/thrillcrazyer/loopus/blob/main/utils/inference.py) (Model loading), [`training_cli.py`](https://github.com/thrillcrazyer/loopus/blob/main/training_cli.py) (Training CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["LDS model"]
  node_config["LDS configuration"]
  node_encoder["Encoder<br/>[modeling_lds.py]"]
  node_reasoning["Looped reasoning<br/>[modeling_lds.py]"]
  node_gate["Selective gate<br/>[modeling_lds.py]"]
  node_decoder["Decoder and confidence<br/>[modeling_lds.py]"]
end

subgraph group_train["Training"]
  node_traincli["Training CLI<br/>[training_cli.py]"]
  node_pretrain["Pretraining<br/>[train.py]"]
  node_sft["Supervised fine-tuning<br/>[train_sft.py]"]
  node_streamdata["Streaming datasets<br/>[data.py]"]
  node_trainruntime["Training runtime"]
  node_checkpoints["Checkpoint handling"]
end

subgraph group_infer["Inference and evaluation"]
  node_inference["Model loading<br/>[inference.py]"]
  node_evaluation["Benchmark evaluation<br/>[evaluate.py]"]
  node_lmharness["LM-eval adapter<br/>[lm_eval_harness.py]"]
  node_generation["Text generation<br/>[generate.py]"]
  node_chat["Interactive chat<br/>[chat.py]"]
end

subgraph group_support["Shared runtime"]
  node_common["Config and seeding<br/>[common.py]"]
  node_metrics["Training metrics<br/>[metrics.py]"]
  node_distributed["Distributed helpers<br/>[ddp_helper.py]"]
end

node_user(("User"))
node_pretrained(("Pretrained model"))
node_datasets[("Datasets")]
node_evaltasks(("Eval tasks"))

node_user -->|"configures"| node_traincli
node_traincli -->|"configures"| node_pretrain
node_traincli -->|"configures"| node_sft
node_pretrained -->|"initializes from"| node_config
node_datasets -->|"streams examples"| node_streamdata
node_pretrain -->|"runs training"| node_trainruntime
node_sft -->|"runs training"| node_trainruntime
node_pretrain -.->|"uses data"| node_streamdata
node_sft -.->|"uses data"| node_streamdata
node_trainruntime -->|"configures model"| node_config
node_trainruntime -->|"trains refinement"| node_reasoning
node_reasoning -->|"uses gate"| node_gate
node_encoder -.->|"passes hidden states"| node_reasoning
node_reasoning -.->|"passes refined states"| node_decoder
node_trainruntime -->|"tracks metrics"| node_metrics
node_trainruntime -->|"uses helpers"| node_distributed
node_trainruntime -->|"runs evaluation"| node_lmharness
node_trainruntime -->|"saves and resumes"| node_checkpoints
node_checkpoints -->|"loads legacy weights"| node_inference
node_user -->|"requests benchmarks"| node_evaluation
node_evaluation -->|"loads model"| node_inference
node_evaluation -->|"runs tasks"| node_lmharness
node_evaltasks -->|"supplies tasks"| node_lmharness
node_user -->|"provides prompt"| node_generation
node_generation -->|"loads model"| node_inference
node_user -->|"chats"| node_chat
node_chat -->|"generates with model"| node_reasoning
node_inference -->|"builds configuration"| node_config
node_inference -->|"loads model"| node_reasoning
node_common -->|"parses layer indices"| node_inference
node_common -->|"provides settings"| node_trainruntime

click node_traincli "https://github.com/thrillcrazyer/loopus/blob/main/training_cli.py"
click node_pretrain "https://github.com/thrillcrazyer/loopus/blob/main/train.py"
click node_sft "https://github.com/thrillcrazyer/loopus/blob/main/train_sft.py"
click node_streamdata "https://github.com/thrillcrazyer/loopus/blob/main/utils/data.py"
click node_trainruntime "https://github.com/thrillcrazyer/loopus/blob/main/training_runtime.py"
click node_checkpoints "https://github.com/thrillcrazyer/loopus/blob/main/training_runtime.py"
click node_config "https://github.com/thrillcrazyer/loopus/blob/main/models/configuration_lds.py"
click node_encoder "https://github.com/thrillcrazyer/loopus/blob/main/models/modeling_lds.py"
click node_reasoning "https://github.com/thrillcrazyer/loopus/blob/main/models/modeling_lds.py"
click node_gate "https://github.com/thrillcrazyer/loopus/blob/main/models/modeling_lds.py"
click node_decoder "https://github.com/thrillcrazyer/loopus/blob/main/models/modeling_lds.py"
click node_inference "https://github.com/thrillcrazyer/loopus/blob/main/utils/inference.py"
click node_evaluation "https://github.com/thrillcrazyer/loopus/blob/main/evaluate.py"
click node_lmharness "https://github.com/thrillcrazyer/loopus/blob/main/utils/lm_eval_harness.py"
click node_generation "https://github.com/thrillcrazyer/loopus/blob/main/generate.py"
click node_chat "https://github.com/thrillcrazyer/loopus/blob/main/chat.py"
click node_common "https://github.com/thrillcrazyer/loopus/blob/main/utils/common.py"
click node_metrics "https://github.com/thrillcrazyer/loopus/blob/main/utils/metrics.py"
click node_distributed "https://github.com/thrillcrazyer/loopus/blob/main/utils/ddp_helper.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_config,node_encoder,node_reasoning,node_gate,node_decoder,node_user toneBlue
class node_traincli,node_pretrain,node_sft,node_streamdata,node_trainruntime,node_checkpoints,node_datasets toneAmber
class node_inference,node_evaluation,node_lmharness,node_generation,node_chat toneMint
class node_common,node_metrics,node_distributed,node_evaltasks toneRose
class node_pretrained toneIndigo
```

## Components

### LDS model

- [LDS configuration](https://github.com/thrillcrazyer/loopus/blob/main/models/configuration_lds.py): `models/configuration_lds.py`
- [Encoder](https://github.com/thrillcrazyer/loopus/blob/main/models/modeling_lds.py): `models/modeling_lds.py`
- [Looped reasoning](https://github.com/thrillcrazyer/loopus/blob/main/models/modeling_lds.py): `models/modeling_lds.py`
- [Selective gate](https://github.com/thrillcrazyer/loopus/blob/main/models/modeling_lds.py): `models/modeling_lds.py`
- [Decoder and confidence](https://github.com/thrillcrazyer/loopus/blob/main/models/modeling_lds.py): `models/modeling_lds.py`

### Training

- [Training CLI](https://github.com/thrillcrazyer/loopus/blob/main/training_cli.py): `training_cli.py`
- [Pretraining](https://github.com/thrillcrazyer/loopus/blob/main/train.py): `train.py`
- [Supervised fine-tuning](https://github.com/thrillcrazyer/loopus/blob/main/train_sft.py): `train_sft.py`
- [Streaming datasets](https://github.com/thrillcrazyer/loopus/blob/main/utils/data.py): `utils/data.py`
- [Training runtime](https://github.com/thrillcrazyer/loopus/blob/main/training_runtime.py): `training_runtime.py`
- [Checkpoint handling](https://github.com/thrillcrazyer/loopus/blob/main/training_runtime.py): `training_runtime.py`

### Inference and evaluation

- [Model loading](https://github.com/thrillcrazyer/loopus/blob/main/utils/inference.py): `utils/inference.py`
- [Benchmark evaluation](https://github.com/thrillcrazyer/loopus/blob/main/evaluate.py): `evaluate.py`
- [LM-eval adapter](https://github.com/thrillcrazyer/loopus/blob/main/utils/lm_eval_harness.py): `utils/lm_eval_harness.py`
- [Text generation](https://github.com/thrillcrazyer/loopus/blob/main/generate.py): `generate.py`
- [Interactive chat](https://github.com/thrillcrazyer/loopus/blob/main/chat.py): `chat.py`

### Shared runtime

- [Config and seeding](https://github.com/thrillcrazyer/loopus/blob/main/utils/common.py): `utils/common.py`
- [Training metrics](https://github.com/thrillcrazyer/loopus/blob/main/utils/metrics.py): `utils/metrics.py`
- [Distributed helpers](https://github.com/thrillcrazyer/loopus/blob/main/utils/ddp_helper.py): `utils/ddp_helper.py`

### Other components

- **User**
- **Pretrained model**
- **Datasets**
- **Eval tasks**

## Connections

- User → Training CLI: configures (evidence: `README.md`)
- Training CLI → Pretraining: configures (evidence: `train.py`)
- Training CLI → Supervised fine-tuning: configures (evidence: `train_sft.py`)
- Pretrained model → LDS configuration: initializes from (evidence: `README.md`)
- Datasets → Streaming datasets: streams examples (evidence: `README.md`)
- Pretraining → Training runtime: runs training (evidence: `train.py`)
- Supervised fine-tuning → Training runtime: runs training (evidence: `train_sft.py`)
- Pretraining → Streaming datasets: uses data (evidence: `train.py`)
- Supervised fine-tuning → Streaming datasets: uses data (evidence: `train_sft.py`)
- Training runtime → LDS configuration: configures model (evidence: `training_runtime.py`)
- Training runtime → Looped reasoning: trains refinement (evidence: `training_runtime.py`)
- Looped reasoning → Selective gate: uses gate (evidence: `models/modeling_lds.py`)
- Encoder → Looped reasoning: passes hidden states (evidence: `models/modeling_lds.py`)
- Looped reasoning → Decoder and confidence: passes refined states (evidence: `models/modeling_lds.py`)
- Training runtime → Training metrics: tracks metrics (evidence: `training_runtime.py`)
- Training runtime → Distributed helpers: uses helpers (evidence: `training_runtime.py`)
- Training runtime → LM-eval adapter: runs evaluation (evidence: `training_runtime.py`)
- Training runtime → Checkpoint handling: saves and resumes (evidence: `README.md`)
- Checkpoint handling → Model loading: loads legacy weights (evidence: `utils/inference.py`)
- User → Benchmark evaluation: requests benchmarks (evidence: `README.md`)
- Benchmark evaluation → Model loading: loads model (evidence: `evaluate.py`)
- Benchmark evaluation → LM-eval adapter: runs tasks (evidence: `evaluate.py`)
- Eval tasks → LM-eval adapter: supplies tasks (evidence: `README.md`)
- User → Text generation: provides prompt (evidence: `README.md`)
- Text generation → Model loading: loads model (evidence: `generate.py`)
- User → Interactive chat: chats (evidence: `README.md`)
- Interactive chat → Looped reasoning: generates with model (evidence: `chat.py`)
- Model loading → LDS configuration: builds configuration (evidence: `utils/inference.py`)
- Model loading → Looped reasoning: loads model (evidence: `utils/inference.py`)
- Config and seeding → Model loading: parses layer indices (evidence: `utils/inference.py`)
- Config and seeding → Training runtime: provides settings (evidence: `training_runtime.py`)
