# duxiaoman-di/xuanyuan architecture

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

- Interactive diagram: https://gitdiagram.com/duxiaoman-di/xuanyuan
- Repository: https://github.com/duxiaoman-di/xuanyuan

## Overview

XuanYuan is a Chinese finance-focused language-model project: it publishes model families, interactive inference, a FinanceIQ benchmark, and a DeepSpeed training toolkit. The user-facing paths are either asking questions in the chat demo and receiving generated text, or evaluating a model/API against finance exam questions and saved accuracy results. The README also documents FinX1’s thinking, reward-model, and reinforcement-learning approach; those training stages are documented capabilities, not sampled implementation modules.

Main entry points: [`FinanceIQ/src/utils.py`](https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/utils.py) (Evaluation runner), [`cli_demo.py`](https://github.com/duxiaoman-di/xuanyuan/blob/main/cli_demo.py) (Chat demo), [`llm-code/model_hook.py`](https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/model_hook.py) (Model and data hooks), [`llm-code/dataset.py`](https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/dataset.py) (Training datasets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Chat inference"]
  node_demo["Chat demo<br/>[cli_demo.py]"]
  node_templates["Conversation templates<br/>[conversation.py]"]
  node_model["Language model"]
end

subgraph group_evaluation["FinanceIQ evaluation"]
  node_benchmark["FinanceIQ questions"]
  node_evalrunner["Evaluation runner<br/>[utils.py]"]
  node_subjects["Exam subjects<br/>[categories.py]"]
  node_localeval["Local model evaluator<br/>[hf_causal_model.py]"]
  node_chatgpt["ChatGPT evaluator<br/>[chatgpt.py]"]
  node_gpt4["GPT-4 evaluator<br/>[gpt4.py]"]
  node_ernie["ERNIE evaluator<br/>[ernie.py]"]
  node_results["Evaluation results<br/>[utils.py]"]
end

subgraph group_training["Model training"]
  node_trainer["Training orchestrator<br/>[dxm_llm_main.py]"]
  node_hooks["Model and data hooks<br/>[model_hook.py]"]
  node_dataset["Training datasets<br/>[dataset.py]"]
  node_config["Training configuration<br/>[config.py]"]
  node_rawdata["Pretraining data"]
  node_finx["FinX1 reasoning approach"]
end

node_user(("User"))
node_evaluser(("Evaluator"))

node_user -->|"asks"| node_demo
node_demo -->|"formats turns"| node_templates
node_demo -->|"generates text"| node_model
node_evaluser -->|"starts evaluation"| node_evalrunner
node_evalrunner -->|"iterates subjects"| node_subjects
node_evalrunner -.->|"loads questions"| node_benchmark
node_evalrunner -->|"runs evaluator"| node_localeval
node_evalrunner -->|"runs evaluator"| node_chatgpt
node_evalrunner -->|"runs evaluator"| node_gpt4
node_evalrunner -->|"runs evaluator"| node_ernie
node_localeval -->|"loads checkpoint"| node_model
node_evalrunner -->|"saves scores"| node_results
node_trainer -->|"gets training hooks"| node_hooks
node_hooks -->|"builds dataloader"| node_dataset
node_hooks -->|"gets settings"| node_config
node_dataset -->|"logs loading"| node_trainer
node_rawdata -.->|"prepares corpus"| node_dataset
node_finx -.->|"guides training"| node_model

click node_demo "https://github.com/duxiaoman-di/xuanyuan/blob/main/cli_demo.py"
click node_templates "https://github.com/duxiaoman-di/xuanyuan/blob/main/conversation.py"
click node_benchmark "https://github.com/duxiaoman-di/xuanyuan/tree/main/FinanceIQ/data"
click node_evalrunner "https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/utils.py"
click node_subjects "https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/categories.py"
click node_localeval "https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/hf_causal_model.py"
click node_chatgpt "https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/chatgpt.py"
click node_gpt4 "https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/gpt4.py"
click node_ernie "https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/ernie.py"
click node_results "https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/utils.py"
click node_trainer "https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/dxm_llm_main.py"
click node_hooks "https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/model_hook.py"
click node_dataset "https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/dataset.py"
click node_config "https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/config.py"
click node_rawdata "https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/pretrain_data_process.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_demo,node_templates,node_model,node_user toneBlue
class node_benchmark,node_evalrunner,node_subjects,node_localeval,node_chatgpt,node_gpt4,node_ernie,node_results toneAmber
class node_trainer,node_hooks,node_dataset,node_config,node_rawdata,node_finx toneMint
class node_evaluser toneIndigo
```

## Components

### Chat inference

- [Chat demo](https://github.com/duxiaoman-di/xuanyuan/blob/main/cli_demo.py): `cli_demo.py`
- [Conversation templates](https://github.com/duxiaoman-di/xuanyuan/blob/main/conversation.py): `conversation.py`
- **Language model**

### FinanceIQ evaluation

- [FinanceIQ questions](https://github.com/duxiaoman-di/xuanyuan/tree/main/FinanceIQ/data): `FinanceIQ/data`
- [Evaluation runner](https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/utils.py): `FinanceIQ/src/utils.py`
- [Exam subjects](https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/categories.py): `FinanceIQ/src/categories.py`
- [Local model evaluator](https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/hf_causal_model.py): `FinanceIQ/src/hf_causal_model.py`
- [ChatGPT evaluator](https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/chatgpt.py): `FinanceIQ/src/chatgpt.py`
- [GPT-4 evaluator](https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/gpt4.py): `FinanceIQ/src/gpt4.py`
- [ERNIE evaluator](https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/ernie.py): `FinanceIQ/src/ernie.py`
- [Evaluation results](https://github.com/duxiaoman-di/xuanyuan/blob/main/FinanceIQ/src/utils.py): `FinanceIQ/src/utils.py`

### Model training

- [Training orchestrator](https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/dxm_llm_main.py): `llm-code/dxm_llm_main.py`
- [Model and data hooks](https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/model_hook.py): `llm-code/model_hook.py`
- [Training datasets](https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/dataset.py): `llm-code/dataset.py`
- [Training configuration](https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/config.py): `llm-code/config.py`
- [Pretraining data](https://github.com/duxiaoman-di/xuanyuan/blob/main/llm-code/pretrain_data_process.py): `llm-code/pretrain_data_process.py`
- **FinX1 reasoning approach**

### Other components

- **User**
- **Evaluator**

## Connections

- User → Chat demo: asks (evidence: `cli_demo.py`)
- Chat demo → Conversation templates: formats turns (evidence: `cli_demo.py`)
- Chat demo → Language model: generates text (evidence: `cli_demo.py`)
- Evaluator → Evaluation runner: starts evaluation (evidence: `FinanceIQ/src/utils.py`)
- Evaluation runner → Exam subjects: iterates subjects (evidence: `FinanceIQ/src/utils.py`)
- Evaluation runner → FinanceIQ questions: loads questions
- Evaluation runner → Local model evaluator: runs evaluator (evidence: `FinanceIQ/src/hf_causal_model.py`)
- Evaluation runner → ChatGPT evaluator: runs evaluator (evidence: `FinanceIQ/src/chatgpt.py`)
- Evaluation runner → GPT-4 evaluator: runs evaluator (evidence: `FinanceIQ/src/gpt4.py`)
- Evaluation runner → ERNIE evaluator: runs evaluator (evidence: `FinanceIQ/src/ernie.py`)
- Local model evaluator → Language model: loads checkpoint (evidence: `FinanceIQ/src/hf_causal_model.py`)
- Evaluation runner → Evaluation results: saves scores (evidence: `FinanceIQ/src/utils.py`)
- Training orchestrator → Model and data hooks: gets training hooks (evidence: `llm-code/dxm_llm_main.py`)
- Model and data hooks → Training datasets: builds dataloader (evidence: `llm-code/model_hook.py`)
- Model and data hooks → Training configuration: gets settings (evidence: `llm-code/model_hook.py`)
- Training datasets → Training orchestrator: logs loading (evidence: `llm-code/dataset.py`)
- Pretraining data → Training datasets: prepares corpus
- FinX1 reasoning approach → Language model: guides training
