# pranav1237/minillm architecture

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

- Interactive diagram: https://gitdiagram.com/pranav1237/minillm
- Repository: https://github.com/pranav1237/minillm

## Overview

MiniLLM is a small decoder-only Transformer project with two related paths: a documented character-level demo and a newer dialogue-model workflow. The main product flow processes dialogue CSVs, trains a tokenizer and Transformer, saves artifacts, then generates replies through a CLI or HTTP endpoint. The README also describes the standalone character-level path, and the model implementations are distinct. Edges reflect explicit README statements or shown calls; unsampled UI and deployment wiring is omitted.

Main entry points: [`src/mini_llm/train.py`](https://github.com/pranav1237/minillm/blob/main/src/mini_llm/train.py) (Training loop), [`src/mini_llm/infer.py`](https://github.com/pranav1237/minillm/blob/main/src/mini_llm/infer.py) (Reply generation), [`api/chat.py`](https://github.com/pranav1237/minillm/blob/main/api/chat.py) (HTTP chat API), [`src/mini_llm/data_pipeline.py`](https://github.com/pranav1237/minillm/blob/main/src/mini_llm/data_pipeline.py) (Dialogue preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Dialogue data"]
  node_dialogue_csv["Dialogue CSVs"]
  node_preprocess["Dialogue preprocessing<br/>[data_pipeline.py]"]
  node_processed["Processed splits"]
  node_char_text["Character training text<br/>[random.txt]"]
end

subgraph group_training["Model training"]
  node_tokenizer["SentencePiece tokenizer<br/>[tokenizer_utils.py]"]
  node_trainer["Training loop<br/>[train.py]"]
  node_checkpoints["Model artifacts"]
  node_device["Device selection<br/>[runtime.py]"]
  node_char_trainer["Character LM training<br/>[train_char_lm.py]"]
end

subgraph group_inference["Generation"]
  node_infer["Reply generation<br/>[infer.py]"]
  node_cli["Chat CLI<br/>[chat.py]"]
  node_api["HTTP chat API<br/>[chat.py]"]
  node_char_generator["Character generation<br/>[generate.py]"]
end

subgraph group_model["Transformer models"]
  node_dialogue_model["Dialogue Transformer<br/>[model.py]"]
  node_char_model["Standalone Transformer"]
end

node_user(("User"))
node_web_client(("Web client"))

node_dialogue_csv -->|"reads"| node_preprocess
node_preprocess -->|"writes"| node_processed
node_trainer -->|"processes splits"| node_preprocess
node_trainer -->|"reads"| node_processed
node_trainer -->|"trains and encodes"| node_tokenizer
node_trainer -->|"builds and trains"| node_dialogue_model
node_trainer -->|"selects device"| node_device
node_trainer -->|"saves weights"| node_checkpoints
node_infer -->|"loads weights"| node_checkpoints
node_infer -->|"loads and uses"| node_tokenizer
node_infer -->|"runs generation"| node_dialogue_model
node_infer -->|"selects device"| node_device
node_user -->|"enters prompts"| node_cli
node_cli -->|"requests replies"| node_infer
node_web_client -.->|"sends prompts"| node_api
node_api -->|"loads bundled artifacts"| node_checkpoints
node_api -->|"loads tokenizer"| node_tokenizer
node_api -->|"builds and runs"| node_dialogue_model
node_char_text -->|"trains from"| node_char_trainer
node_char_trainer -.->|"trains"| node_char_model
node_char_generator -->|"loads model"| node_char_model
node_user -->|"provides prompt"| node_char_generator

click node_dialogue_csv "https://github.com/pranav1237/minillm/tree/main/data"
click node_preprocess "https://github.com/pranav1237/minillm/blob/main/src/mini_llm/data_pipeline.py"
click node_processed "https://github.com/pranav1237/minillm/tree/main/data"
click node_tokenizer "https://github.com/pranav1237/minillm/blob/main/src/mini_llm/tokenizer_utils.py"
click node_trainer "https://github.com/pranav1237/minillm/blob/main/src/mini_llm/train.py"
click node_device "https://github.com/pranav1237/minillm/blob/main/src/mini_llm/runtime.py"
click node_dialogue_model "https://github.com/pranav1237/minillm/blob/main/src/mini_llm/model.py"
click node_infer "https://github.com/pranav1237/minillm/blob/main/src/mini_llm/infer.py"
click node_cli "https://github.com/pranav1237/minillm/blob/main/scripts/chat.py"
click node_api "https://github.com/pranav1237/minillm/blob/main/api/chat.py"
click node_char_text "https://github.com/pranav1237/minillm/blob/main/data/random.txt"
click node_char_trainer "https://github.com/pranav1237/minillm/blob/main/train_char_lm.py"
click node_char_model "https://github.com/pranav1237/minillm/blob/main/mini_transformer.py"
click node_char_generator "https://github.com/pranav1237/minillm/blob/main/generate.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_dialogue_csv,node_preprocess,node_processed,node_char_text,node_user,node_web_client toneBlue
class node_tokenizer,node_trainer,node_checkpoints,node_device,node_char_trainer toneAmber
class node_infer,node_cli,node_api,node_char_generator toneMint
class node_dialogue_model,node_char_model toneRose
```

## Components

### Dialogue data

- [Dialogue CSVs](https://github.com/pranav1237/minillm/tree/main/data): `data`
- [Dialogue preprocessing](https://github.com/pranav1237/minillm/blob/main/src/mini_llm/data_pipeline.py): `src/mini_llm/data_pipeline.py`
- [Processed splits](https://github.com/pranav1237/minillm/tree/main/data): `data`
- [Character training text](https://github.com/pranav1237/minillm/blob/main/data/random.txt): `data/random.txt`

### Model training

- [SentencePiece tokenizer](https://github.com/pranav1237/minillm/blob/main/src/mini_llm/tokenizer_utils.py): `src/mini_llm/tokenizer_utils.py`
- [Training loop](https://github.com/pranav1237/minillm/blob/main/src/mini_llm/train.py): `src/mini_llm/train.py`
- **Model artifacts**
- [Device selection](https://github.com/pranav1237/minillm/blob/main/src/mini_llm/runtime.py): `src/mini_llm/runtime.py`
- [Character LM training](https://github.com/pranav1237/minillm/blob/main/train_char_lm.py): `train_char_lm.py`

### Generation

- [Reply generation](https://github.com/pranav1237/minillm/blob/main/src/mini_llm/infer.py): `src/mini_llm/infer.py`
- [Chat CLI](https://github.com/pranav1237/minillm/blob/main/scripts/chat.py): `scripts/chat.py`
- [HTTP chat API](https://github.com/pranav1237/minillm/blob/main/api/chat.py): `api/chat.py`
- [Character generation](https://github.com/pranav1237/minillm/blob/main/generate.py): `generate.py`

### Transformer models

- [Dialogue Transformer](https://github.com/pranav1237/minillm/blob/main/src/mini_llm/model.py): `src/mini_llm/model.py`
- [Standalone Transformer](https://github.com/pranav1237/minillm/blob/main/mini_transformer.py): `mini_transformer.py`

### Other components

- **User**
- **Web client**

## Connections

- Dialogue CSVs → Dialogue preprocessing: reads (evidence: `src/mini_llm/data_pipeline.py`)
- Dialogue preprocessing → Processed splits: writes (evidence: `src/mini_llm/data_pipeline.py`)
- Training loop → Dialogue preprocessing: processes splits (evidence: `src/mini_llm/train.py`)
- Training loop → Processed splits: reads (evidence: `src/mini_llm/train.py`)
- Training loop → SentencePiece tokenizer: trains and encodes (evidence: `src/mini_llm/train.py`)
- Training loop → Dialogue Transformer: builds and trains (evidence: `src/mini_llm/train.py`)
- Training loop → Device selection: selects device (evidence: `src/mini_llm/train.py`)
- Training loop → Model artifacts: saves weights (evidence: `src/mini_llm/train.py`)
- Reply generation → Model artifacts: loads weights (evidence: `src/mini_llm/infer.py`)
- Reply generation → SentencePiece tokenizer: loads and uses (evidence: `src/mini_llm/infer.py`)
- Reply generation → Dialogue Transformer: runs generation (evidence: `src/mini_llm/infer.py`)
- Reply generation → Device selection: selects device (evidence: `src/mini_llm/infer.py`)
- User → Chat CLI: enters prompts (evidence: `scripts/chat.py`)
- Chat CLI → Reply generation: requests replies (evidence: `scripts/chat.py`)
- Web client → HTTP chat API: sends prompts
- HTTP chat API → Model artifacts: loads bundled artifacts (evidence: `api/chat.py`)
- HTTP chat API → SentencePiece tokenizer: loads tokenizer (evidence: `api/chat.py`)
- HTTP chat API → Dialogue Transformer: builds and runs (evidence: `api/chat.py`)
- Character training text → Character LM training: trains from (evidence: `readme.md`)
- Character LM training → Standalone Transformer: trains
- Character generation → Standalone Transformer: loads model (evidence: `generate.py`)
- User → Character generation: provides prompt (evidence: `readme.md`)
