# beomi/koalpaca architecture

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

- Interactive diagram: https://gitdiagram.com/beomi/koalpaca
- Repository: https://github.com/beomi/koalpaca

## Overview

KoAlpaca is a Korean instruction-tuned language-model project: seed examples are expanded into instruction data, then fine-tuned into model variants that can be used for text generation and chat. The main visible runtime paths are instruction generation, supervised training, and the Gradio chat demo; README also documents larger-model training and LoRA/QLoRA inference. Some training and notebook details are unsampled, so those capabilities are included only where documented, without inferred connections between them.

Main entry points: [`webui/app.py`](https://github.com/beomi/koalpaca/blob/main/webui/app.py) (Gradio chat UI), [`generate_instruction.py`](https://github.com/beomi/koalpaca/blob/main/generate_instruction.py) (Instruction generator), [`train.py`](https://github.com/beomi/koalpaca/blob/main/train.py) (Supervised fine-tuning), [`train_v1.1b/run_clm.py`](https://github.com/beomi/koalpaca/blob/main/train_v1.1b/run_clm.py) (Causal-LM training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Instruction data"]
  node_seed["Seed tasks<br/>[seed_tasks.jsonl]"]
  node_prompt["Prompt examples<br/>[prompt.txt]"]
  node_generator["Instruction generator"]
  node_generation_utils["Generation utilities<br/>[utils.py]"]
  node_generated_data["Generated instructions"]
  node_training_data["Training data"]
end

subgraph group_training["Model training"]
  node_supervised_training["Supervised fine-tuning<br/>[train.py]"]
  node_clm_training["Causal-LM training<br/>[run_clm.py]"]
  node_parallel_training["Tensor-parallel training"]
end

subgraph group_inference["Inference and chat"]
  node_webui["Gradio chat UI<br/>[app.py]"]
  node_chat_state["Conversation context<br/>[app.py]"]
  node_text_generation["Text generation<br/>[app.py]"]
  node_lora_notebook["LoRA inference example"]
end

subgraph group_release["Model variants"]
  node_base_models["Base models"]
  node_trained_models["KoAlpaca models"]
end

node_user(("User"))
node_chat_user(("Chat user"))
node_model_hub["Hugging Face models"]

node_seed -->|"seeds generation"| node_generator
node_prompt -->|"formats prompts"| node_generator
node_generator -->|"requests completion"| node_generation_utils
node_generator -->|"writes results"| node_generated_data
node_training_data -->|"trains on"| node_supervised_training
node_supervised_training -->|"loads JSON"| node_generation_utils
node_base_models -.->|"fine-tunes"| node_supervised_training
node_base_models -.->|"fine-tunes"| node_clm_training
node_base_models -.->|"fine-tunes"| node_parallel_training
node_supervised_training -->|"saves weights"| node_trained_models
node_clm_training -.->|"trains models"| node_trained_models
node_parallel_training -.->|"trains models"| node_trained_models
node_chat_user -->|"sends message"| node_webui
node_webui -->|"updates context"| node_chat_state
node_webui -->|"requests generation"| node_text_generation
node_text_generation -->|"returns reply"| node_chat_state
node_trained_models -->|"serves chat"| node_webui
node_model_hub -->|"loads checkpoint"| node_webui
node_lora_notebook -->|"loads adapter"| node_model_hub

click node_seed "https://github.com/beomi/koalpaca/blob/main/seed_tasks.jsonl"
click node_prompt "https://github.com/beomi/koalpaca/blob/main/prompt.txt"
click node_generator "https://github.com/beomi/koalpaca/blob/main/generate_instruction.py"
click node_generation_utils "https://github.com/beomi/koalpaca/blob/main/utils.py"
click node_training_data "https://github.com/beomi/koalpaca/blob/main/KoAlpaca_v1.1.jsonl"
click node_supervised_training "https://github.com/beomi/koalpaca/blob/main/train.py"
click node_clm_training "https://github.com/beomi/koalpaca/blob/main/train_v1.1b/run_clm.py"
click node_parallel_training "https://github.com/beomi/koalpaca/blob/main/train_v1.1b/run_tensor_parallel.py"
click node_webui "https://github.com/beomi/koalpaca/blob/main/webui/app.py"
click node_chat_state "https://github.com/beomi/koalpaca/blob/main/webui/app.py"
click node_text_generation "https://github.com/beomi/koalpaca/blob/main/webui/app.py"
click node_lora_notebook "https://github.com/beomi/koalpaca/blob/main/2023_06_08_PEFT%EB%A1%9CLoRA%EB%A1%9C%EB%93%9C.ipynb"

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_seed,node_prompt,node_generator,node_generation_utils,node_generated_data,node_training_data,node_user,node_chat_user toneBlue
class node_supervised_training,node_clm_training,node_parallel_training toneAmber
class node_webui,node_chat_state,node_text_generation,node_lora_notebook toneMint
class node_base_models,node_trained_models toneRose
class node_model_hub toneIndigo
```

## Components

### Instruction data

- [Seed tasks](https://github.com/beomi/koalpaca/blob/main/seed_tasks.jsonl): `seed_tasks.jsonl`
- [Prompt examples](https://github.com/beomi/koalpaca/blob/main/prompt.txt): `prompt.txt`
- [Instruction generator](https://github.com/beomi/koalpaca/blob/main/generate_instruction.py): `generate_instruction.py`
- [Generation utilities](https://github.com/beomi/koalpaca/blob/main/utils.py): `utils.py`
- **Generated instructions**
- [Training data](https://github.com/beomi/koalpaca/blob/main/KoAlpaca_v1.1.jsonl): `KoAlpaca_v1.1.jsonl`

### Model training

- [Supervised fine-tuning](https://github.com/beomi/koalpaca/blob/main/train.py): `train.py`
- [Causal-LM training](https://github.com/beomi/koalpaca/blob/main/train_v1.1b/run_clm.py): `train_v1.1b/run_clm.py`
- [Tensor-parallel training](https://github.com/beomi/koalpaca/blob/main/train_v1.1b/run_tensor_parallel.py): `train_v1.1b/run_tensor_parallel.py`

### Inference and chat

- [Gradio chat UI](https://github.com/beomi/koalpaca/blob/main/webui/app.py): `webui/app.py`
- [Conversation context](https://github.com/beomi/koalpaca/blob/main/webui/app.py): `webui/app.py`
- [Text generation](https://github.com/beomi/koalpaca/blob/main/webui/app.py): `webui/app.py`
- [LoRA inference example](https://github.com/beomi/koalpaca/blob/main/2023_06_08_PEFT%EB%A1%9CLoRA%EB%A1%9C%EB%93%9C.ipynb): `2023_06_08_PEFT로LoRA로드.ipynb`

### Model variants

- **Base models**
- **KoAlpaca models**

### Other components

- **User**
- **Chat user**
- **Hugging Face models**

## Connections

- Seed tasks → Instruction generator: seeds generation (evidence: `generate_instruction.py`)
- Prompt examples → Instruction generator: formats prompts (evidence: `generate_instruction.py`)
- Instruction generator → Generation utilities: requests completion (evidence: `generate_instruction.py`)
- Instruction generator → Generated instructions: writes results (evidence: `generate_instruction.py`)
- Training data → Supervised fine-tuning: trains on (evidence: `train.py`)
- Supervised fine-tuning → Generation utilities: loads JSON (evidence: `train.py`)
- Base models → Supervised fine-tuning: fine-tunes
- Base models → Causal-LM training: fine-tunes
- Base models → Tensor-parallel training: fine-tunes
- Supervised fine-tuning → KoAlpaca models: saves weights (evidence: `train.py`)
- Causal-LM training → KoAlpaca models: trains models
- Tensor-parallel training → KoAlpaca models: trains models
- Chat user → Gradio chat UI: sends message (evidence: `webui/app.py`)
- Gradio chat UI → Conversation context: updates context (evidence: `webui/app.py`)
- Gradio chat UI → Text generation: requests generation (evidence: `webui/app.py`)
- Text generation → Conversation context: returns reply (evidence: `webui/app.py`)
- KoAlpaca models → Gradio chat UI: serves chat (evidence: `webui/app.py`)
- Hugging Face models → Gradio chat UI: loads checkpoint (evidence: `webui/app.py`)
- LoRA inference example → Hugging Face models: loads adapter (evidence: `README.md`)
