# jddd-hy/jlm architecture

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

- Interactive diagram: https://gitdiagram.com/jddd-hy/jlm
- Repository: https://github.com/jddd-hy/jlm
- Video tour (about a minute): https://gitdiagram.com/jddd-hy/jlm/video

## Overview

JLM is a local, style-tuned conversational model. Its main user workflow accepts a chat turn, generates multiple replies, judges and ranks them, then returns a selectable response while maintaining session history; GPU and CPU/llama.cpp backends are documented. Its model-building workflow collects and curates attributed quotes, prepares leakage-aware dialogue/training data, trains a QLoRA adapter, and evaluates generations. The README documents review and offline packaging capabilities; only relationships supported by excerpts or README statements are connected, so unsampled links are omitted.

Main entry points: [`src/training/train.py`](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/training/train.py) (QLoRA training), [`scripts/chat.py`](https://github.com/jddd-hy/jlm/blob/jlm-0.3/scripts/chat.py) (Candidate generation and judging), [`src/data/clean.py`](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/data/clean.py) (Text cleaning), [`src/evaluation/evaluate.py`](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/evaluation/evaluate.py) (Model evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_collection["Collection and curation"]
  node_collector["Quote collection<br/>[collectors.py]"]
  node_parser["Source parsing<br/>[parsers.py]"]
  node_review["Collection review"]
end

subgraph group_model["Data and training"]
  node_validate["Record validation<br/>[validate.py]"]
  node_clean["Text cleaning<br/>[clean.py]"]
  node_deduplicate["Deduplication<br/>[deduplicate.py]"]
  node_prepare["Leakage-aware splits<br/>[prepare.py]"]
  node_data_gate["Training data gate<br/>[data_gate.py]"]
  node_train["QLoRA training<br/>[train.py]"]
end

subgraph group_runtime["Chat and inference"]
  node_gpu_engine["GPU chat engine<br/>[engine.py]"]
  node_chat_script["Candidate generation and judging<br/>[chat.py]"]
  node_generate["Model generation<br/>[generate.py]"]
  node_judge["Candidate judge<br/>[judge.py]"]
  node_selection["Reply selection<br/>[selection.py]"]
  node_tui["Terminal chat<br/>[tui.py]"]
  node_cpu_engine["CPU llama.cpp backend<br/>[llama_engine.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluation["Model evaluation<br/>[evaluate.py]"]
  node_novelty["Novelty metrics<br/>[novelty.py]"]
  node_report["Evaluation reports<br/>[report.py]"]
end

node_user(("Chat user"))
node_base_model[("Qwen base model")]
node_llama_server["llama-server"]

node_user -->|"sends turns"| node_tui
node_tui -->|"routes chat"| node_gpu_engine
node_gpu_engine -->|"requests replies"| node_chat_script
node_chat_script -->|"generates candidates"| node_generate
node_chat_script -.->|"judges candidates"| node_judge
node_chat_script -.->|"ranks replies"| node_selection
node_gpu_engine -->|"loads adapted model"| node_base_model
node_tui -.->|"uses CPU backend"| node_cpu_engine
node_cpu_engine -->|"starts server"| node_llama_server
node_cpu_engine -.->|"ranks replies"| node_selection
node_collector -.->|"parses sources"| node_parser
node_parser -->|"normalizes text"| node_clean
node_review -->|"validates records"| node_validate
node_validate -->|"normalizes records"| node_clean
node_deduplicate -->|"canonicalizes text"| node_clean
node_prepare -->|"finds duplicates"| node_deduplicate
node_train -->|"prepares splits"| node_prepare
node_train -->|"checks inputs"| node_data_gate
node_train -->|"adapts base model"| node_base_model
node_train -.->|"saves adapter for inference"| node_generate
node_evaluation -->|"samples generations"| node_generate
node_evaluation -->|"measures novelty"| node_novelty
node_novelty -->|"canonicalizes quotes"| node_clean
node_evaluation -.->|"renders report"| node_report

click node_collector "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/collection/collectors.py"
click node_parser "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/collection/parsers.py"
click node_review "https://github.com/jddd-hy/jlm/blob/jlm-0.3/scripts/build_collection_review.py"
click node_validate "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/data/validate.py"
click node_clean "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/data/clean.py"
click node_deduplicate "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/data/deduplicate.py"
click node_prepare "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/data/prepare.py"
click node_data_gate "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/training/data_gate.py"
click node_train "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/training/train.py"
click node_gpu_engine "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/app/engine.py"
click node_chat_script "https://github.com/jddd-hy/jlm/blob/jlm-0.3/scripts/chat.py"
click node_generate "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/inference/generate.py"
click node_judge "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/inference/judge.py"
click node_selection "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/inference/selection.py"
click node_tui "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/app/tui.py"
click node_cpu_engine "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/app/llama_engine.py"
click node_evaluation "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/evaluation/evaluate.py"
click node_novelty "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/evaluation/novelty.py"
click node_report "https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/evaluation/report.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_collector,node_parser,node_review,node_user toneBlue
class node_validate,node_clean,node_deduplicate,node_prepare,node_data_gate,node_train,node_base_model toneAmber
class node_gpu_engine,node_chat_script,node_generate,node_judge,node_selection,node_tui,node_cpu_engine,node_llama_server toneMint
class node_evaluation,node_novelty,node_report toneRose
```

## Components

### Collection and curation

- [Quote collection](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/collection/collectors.py): `src/collection/collectors.py`
- [Source parsing](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/collection/parsers.py): `src/collection/parsers.py`
- [Collection review](https://github.com/jddd-hy/jlm/blob/jlm-0.3/scripts/build_collection_review.py): `scripts/build_collection_review.py`

### Data and training

- [Record validation](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/data/validate.py): `src/data/validate.py`
- [Text cleaning](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/data/clean.py): `src/data/clean.py`
- [Deduplication](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/data/deduplicate.py): `src/data/deduplicate.py`
- [Leakage-aware splits](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/data/prepare.py): `src/data/prepare.py`
- [Training data gate](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/training/data_gate.py): `src/training/data_gate.py`
- [QLoRA training](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/training/train.py): `src/training/train.py`

### Chat and inference

- [GPU chat engine](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/app/engine.py): `src/app/engine.py`
- [Candidate generation and judging](https://github.com/jddd-hy/jlm/blob/jlm-0.3/scripts/chat.py): `scripts/chat.py`
- [Model generation](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/inference/generate.py): `src/inference/generate.py`
- [Candidate judge](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/inference/judge.py): `src/inference/judge.py`
- [Reply selection](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/inference/selection.py): `src/inference/selection.py`
- [Terminal chat](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/app/tui.py): `src/app/tui.py`
- [CPU llama.cpp backend](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/app/llama_engine.py): `src/app/llama_engine.py`

### Evaluation

- [Model evaluation](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/evaluation/evaluate.py): `src/evaluation/evaluate.py`
- [Novelty metrics](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/evaluation/novelty.py): `src/evaluation/novelty.py`
- [Evaluation reports](https://github.com/jddd-hy/jlm/blob/jlm-0.3/src/evaluation/report.py): `src/evaluation/report.py`

### Other components

- **Chat user**
- **Qwen base model**
- **llama-server**

## Connections

- Chat user → Terminal chat: sends turns
- Terminal chat → GPU chat engine: routes chat (evidence: `src/app/tui.py`)
- GPU chat engine → Candidate generation and judging: requests replies (evidence: `src/app/engine.py`)
- Candidate generation and judging → Model generation: generates candidates (evidence: `scripts/chat.py`)
- Candidate generation and judging → Candidate judge: judges candidates (evidence: `scripts/chat.py`)
- Candidate generation and judging → Reply selection: ranks replies (evidence: `scripts/chat.py`)
- GPU chat engine → Qwen base model: loads adapted model (evidence: `src/app/engine.py`)
- Terminal chat → CPU llama.cpp backend: uses CPU backend (evidence: `src/app/llama_engine.py`)
- CPU llama.cpp backend → llama-server: starts server (evidence: `src/app/llama_engine.py`)
- CPU llama.cpp backend → Reply selection: ranks replies (evidence: `src/app/llama_engine.py`)
- Quote collection → Source parsing: parses sources
- Source parsing → Text cleaning: normalizes text (evidence: `src/collection/parsers.py`)
- Collection review → Record validation: validates records (evidence: `scripts/build_collection_review.py`)
- Record validation → Text cleaning: normalizes records (evidence: `src/data/validate.py`)
- Deduplication → Text cleaning: canonicalizes text (evidence: `src/data/deduplicate.py`)
- Leakage-aware splits → Deduplication: finds duplicates (evidence: `src/data/prepare.py`)
- QLoRA training → Leakage-aware splits: prepares splits (evidence: `src/training/train.py`)
- QLoRA training → Training data gate: checks inputs (evidence: `src/training/train.py`)
- QLoRA training → Qwen base model: adapts base model (evidence: `src/training/train.py`)
- QLoRA training → Model generation: saves adapter for inference
- Model evaluation → Model generation: samples generations (evidence: `src/evaluation/evaluate.py`)
- Model evaluation → Novelty metrics: measures novelty (evidence: `src/evaluation/evaluate.py`)
- Novelty metrics → Text cleaning: canonicalizes quotes (evidence: `src/evaluation/novelty.py`)
- Model evaluation → Evaluation reports: renders report
