# zai-org/chatglm-6b architecture

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

- Interactive diagram: https://gitdiagram.com/zai-org/chatglm-6b
- Repository: https://github.com/zai-org/chatglm-6b

## Overview

ChatGLM-6B is a bilingual conversational model repository with local command-line and web demos, plus a P-Tuning v2 fine-tuning workflow. Users submit text (or, in VisualGLM demos, an image and text); the demo streams responses from a loaded model while retaining conversation history. Fine-tuning configures model and data inputs, preprocesses datasets, and delegates training and generation-based evaluation. The README documents quantized local deployment and parameter-efficient tuning. Edges reflect shown demo calls, indexed module references, or README statements; unsampled API and utility behavior is not inferred.

Main entry points: [`ptuning/main.py`](https://github.com/zai-org/chatglm-6b/blob/main/ptuning/main.py) (Tuning entrypoint), [`cli_demo.py`](https://github.com/zai-org/chatglm-6b/blob/main/cli_demo.py) (CLI chat), [`web_demo.py`](https://github.com/zai-org/chatglm-6b/blob/main/web_demo.py) (Gradio chat), [`web_demo2.py`](https://github.com/zai-org/chatglm-6b/blob/main/web_demo2.py) (Streamlit chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chat["Text chat demos"]
  node_chat_cli["CLI chat<br/>[cli_demo.py]"]
  node_chat_gradio["Gradio chat<br/>[web_demo.py]"]
  node_chat_streamlit["Streamlit chat<br/>[web_demo2.py]"]
  node_chat_legacy["Legacy Gradio<br/>[web_demo_old.py]"]
end

subgraph group_vision["Visual chat demos"]
  node_vision_cli["Vision CLI<br/>[cli_demo_vision.py]"]
  node_vision_gradio["Vision Gradio<br/>[web_demo_vision.py]"]
end

subgraph group_tuning["P-Tuning workflow"]
  node_tuning_args["Tuning arguments<br/>[arguments.py]"]
  node_tuning_main["Tuning entrypoint<br/>[main.py]"]
  node_seq2seq["Generation evaluation<br/>[trainer_seq2seq.py]"]
  node_trainer["Training engine<br/>[trainer.py]"]
  node_tuning_web["Tuning demo<br/>[web_demo.py]"]
end

node_user(("User"))
node_model["Pretrained model"]

node_user -->|"enters prompts"| node_chat_cli
node_chat_cli -->|"streams chat"| node_model
node_user -->|"submits prompts"| node_chat_gradio
node_chat_gradio -->|"streams chat"| node_model
node_user -->|"submits prompts"| node_chat_streamlit
node_chat_streamlit -->|"streams chat"| node_model
node_user -->|"submits prompts"| node_chat_legacy
node_chat_legacy -->|"streams chat"| node_model
node_user -->|"provides image"| node_vision_cli
node_vision_cli -->|"streams visual chat"| node_model
node_user -->|"uploads image"| node_vision_gradio
node_vision_gradio -->|"streams visual chat"| node_model
node_tuning_main -->|"parses arguments"| node_tuning_args
node_tuning_main -->|"uses evaluator"| node_seq2seq
node_seq2seq -->|"extends trainer"| node_trainer
node_tuning_web -->|"loads arguments"| node_tuning_args

click node_chat_cli "https://github.com/zai-org/chatglm-6b/blob/main/cli_demo.py"
click node_chat_gradio "https://github.com/zai-org/chatglm-6b/blob/main/web_demo.py"
click node_chat_streamlit "https://github.com/zai-org/chatglm-6b/blob/main/web_demo2.py"
click node_chat_legacy "https://github.com/zai-org/chatglm-6b/blob/main/web_demo_old.py"
click node_vision_cli "https://github.com/zai-org/chatglm-6b/blob/main/cli_demo_vision.py"
click node_vision_gradio "https://github.com/zai-org/chatglm-6b/blob/main/web_demo_vision.py"
click node_tuning_args "https://github.com/zai-org/chatglm-6b/blob/main/ptuning/arguments.py"
click node_tuning_main "https://github.com/zai-org/chatglm-6b/blob/main/ptuning/main.py"
click node_seq2seq "https://github.com/zai-org/chatglm-6b/blob/main/ptuning/trainer_seq2seq.py"
click node_trainer "https://github.com/zai-org/chatglm-6b/blob/main/ptuning/trainer.py"
click node_tuning_web "https://github.com/zai-org/chatglm-6b/blob/main/ptuning/web_demo.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_chat_cli,node_chat_gradio,node_chat_streamlit,node_chat_legacy,node_user toneBlue
class node_vision_cli,node_vision_gradio toneAmber
class node_tuning_args,node_tuning_main,node_seq2seq,node_trainer,node_tuning_web toneMint
class node_model toneIndigo
```

## Components

### Text chat demos

- [CLI chat](https://github.com/zai-org/chatglm-6b/blob/main/cli_demo.py): `cli_demo.py`
- [Gradio chat](https://github.com/zai-org/chatglm-6b/blob/main/web_demo.py): `web_demo.py`
- [Streamlit chat](https://github.com/zai-org/chatglm-6b/blob/main/web_demo2.py): `web_demo2.py`
- [Legacy Gradio](https://github.com/zai-org/chatglm-6b/blob/main/web_demo_old.py): `web_demo_old.py`

### Visual chat demos

- [Vision CLI](https://github.com/zai-org/chatglm-6b/blob/main/cli_demo_vision.py): `cli_demo_vision.py`
- [Vision Gradio](https://github.com/zai-org/chatglm-6b/blob/main/web_demo_vision.py): `web_demo_vision.py`

### P-Tuning workflow

- [Tuning arguments](https://github.com/zai-org/chatglm-6b/blob/main/ptuning/arguments.py): `ptuning/arguments.py`
- [Tuning entrypoint](https://github.com/zai-org/chatglm-6b/blob/main/ptuning/main.py): `ptuning/main.py`
- [Generation evaluation](https://github.com/zai-org/chatglm-6b/blob/main/ptuning/trainer_seq2seq.py): `ptuning/trainer_seq2seq.py`
- [Training engine](https://github.com/zai-org/chatglm-6b/blob/main/ptuning/trainer.py): `ptuning/trainer.py`
- [Tuning demo](https://github.com/zai-org/chatglm-6b/blob/main/ptuning/web_demo.py): `ptuning/web_demo.py`

### Other components

- **User**
- **Pretrained model**

## Connections

- User → CLI chat: enters prompts (evidence: `cli_demo.py`)
- CLI chat → Pretrained model: streams chat (evidence: `cli_demo.py`)
- User → Gradio chat: submits prompts (evidence: `web_demo.py`)
- Gradio chat → Pretrained model: streams chat (evidence: `web_demo.py`)
- User → Streamlit chat: submits prompts (evidence: `web_demo2.py`)
- Streamlit chat → Pretrained model: streams chat (evidence: `web_demo2.py`)
- User → Legacy Gradio: submits prompts (evidence: `web_demo_old.py`)
- Legacy Gradio → Pretrained model: streams chat (evidence: `web_demo_old.py`)
- User → Vision CLI: provides image (evidence: `cli_demo_vision.py`)
- Vision CLI → Pretrained model: streams visual chat (evidence: `cli_demo_vision.py`)
- User → Vision Gradio: uploads image (evidence: `web_demo_vision.py`)
- Vision Gradio → Pretrained model: streams visual chat (evidence: `web_demo_vision.py`)
- Tuning entrypoint → Tuning arguments: parses arguments (evidence: `ptuning/main.py`)
- Tuning entrypoint → Generation evaluation: uses evaluator (evidence: `ptuning/main.py`)
- Generation evaluation → Training engine: extends trainer (evidence: `ptuning/trainer_seq2seq.py`)
- Tuning demo → Tuning arguments: loads arguments (evidence: `ptuning/web_demo.py`)
