# bhatraasim/qwen-mathematical-reasoning-model architecture

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

- Interactive diagram: https://gitdiagram.com/bhatraasim/qwen-mathematical-reasoning-model
- Repository: https://github.com/bhatraasim/qwen-mathematical-reasoning-model

## Overview

This repository implements an experimental GSM8K math-reasoning pipeline: generate verified teacher traces, prepare tagged data, train an SFT adapter, continue with GRPO rewards, evaluate models, and analyze saved runs. The README documents the main stages; source excerpts show the core data preparation, training, reward, and evaluation behavior. Some evaluation and analysis details are only partially excerpted, so those links rely on documented workflow or are omitted where wiring is uncertain.

Main entry points: [`scripts/train_grpo.py`](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/train_grpo.py) (GRPO training), [`scripts/evaluate_all.py`](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/evaluate_all.py) (Model evaluation), [`scripts/summarize_runs.py`](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/summarize_runs.py) (Run summaries), [`data_generation/generate_data.py`](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/data_generation/generate_data.py) (Trace generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_trace_gen["Trace generation<br/>[generate_data.py]"]
  node_tagged_data["Tagged SFT data"]
  node_grpo_data["GRPO prompts"]
end

subgraph group_training["Model training"]
  node_sft["SFT training<br/>[train_sft.py]"]
  node_rewards["GRPO rewards<br/>[grpo_rewards.py]"]
  node_grpo["GRPO training<br/>[train_grpo.py]"]
  node_adapter[("Saved adapters<br/>[train_grpo.py]")]
end

subgraph group_evaluation["Evaluation"]
  node_evaluation["Model evaluation<br/>[evaluate_all.py]"]
  node_eval_files[("Evaluation files<br/>[evaluate_all.py]")]
end

subgraph group_analysis["Run analysis"]
  node_summarize["Run summaries<br/>[summarize_runs.py]"]
  node_compare["Paired comparison<br/>[compare_runs.py]"]
  node_summary_files["Summary reports<br/>[summarize_runs.py]"]
end

node_user(("Experimenter"))
node_gsm[("GSM8K")]
node_teacher{{"Teacher model"}}
node_base{{"Qwen base model"}}

node_user -->|"starts"| node_trace_gen
node_gsm -->|"supplies questions"| node_trace_gen
node_teacher -->|"generates traces"| node_trace_gen
node_trace_gen -->|"writes traces"| node_tagged_data
node_user -->|"starts"| node_sft
node_tagged_data -->|"provides training data"| node_sft
node_base -->|"initializes model"| node_sft
node_user -->|"starts"| node_grpo
node_gsm -->|"supplies prompts"| node_grpo_data
node_tagged_data -->|"shares prompt format"| node_grpo_data
node_grpo_data -->|"provides training data"| node_grpo
node_adapter -->|"initializes policy"| node_grpo
node_rewards -->|"scores completions"| node_grpo
node_sft -->|"saves adapter"| node_adapter
node_grpo -->|"saves adapter"| node_adapter
node_user -->|"runs evaluation"| node_evaluation
node_gsm -->|"provides test split"| node_evaluation
node_base -.->|"provides model"| node_evaluation
node_adapter -->|"provides adapter"| node_evaluation
node_evaluation -->|"writes results"| node_eval_files
node_user -->|"starts analysis"| node_summarize
node_eval_files -->|"reads runs"| node_summarize
node_summarize -->|"uses comparison logic"| node_compare
node_summarize -->|"writes reports"| node_summary_files
node_user -->|"compares runs"| node_compare

click node_trace_gen "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/data_generation/generate_data.py"
click node_tagged_data "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/data_generation/prepare_tagged_dataset.py"
click node_grpo_data "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/data_generation/prepare_grpo_dataset.py"
click node_sft "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/train_sft.py"
click node_rewards "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/grpo_rewards.py"
click node_grpo "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/train_grpo.py"
click node_adapter "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/train_grpo.py"
click node_evaluation "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/evaluate_all.py"
click node_eval_files "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/evaluate_all.py"
click node_summarize "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/summarize_runs.py"
click node_compare "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/compare_runs.py"
click node_summary_files "https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/summarize_runs.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_trace_gen,node_tagged_data,node_grpo_data toneBlue
class node_sft,node_rewards,node_grpo,node_adapter,node_gsm toneAmber
class node_evaluation,node_eval_files toneMint
class node_summarize,node_compare,node_summary_files toneRose
class node_user,node_teacher,node_base toneIndigo
```

## Components

### Data preparation

- [Trace generation](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/data_generation/generate_data.py): `data_generation/generate_data.py`
- [Tagged SFT data](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/data_generation/prepare_tagged_dataset.py): `data_generation/prepare_tagged_dataset.py`
- [GRPO prompts](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/data_generation/prepare_grpo_dataset.py): `data_generation/prepare_grpo_dataset.py`

### Model training

- [SFT training](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/train_sft.py): `scripts/train_sft.py`
- [GRPO rewards](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/grpo_rewards.py): `scripts/grpo_rewards.py`
- [GRPO training](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/train_grpo.py): `scripts/train_grpo.py`
- [Saved adapters](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/train_grpo.py): `scripts/train_grpo.py`

### Evaluation

- [Model evaluation](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/evaluate_all.py): `scripts/evaluate_all.py`
- [Evaluation files](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/evaluate_all.py): `scripts/evaluate_all.py`

### Run analysis

- [Run summaries](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/summarize_runs.py): `scripts/summarize_runs.py`
- [Paired comparison](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/compare_runs.py): `scripts/compare_runs.py`
- [Summary reports](https://github.com/bhatraasim/qwen-mathematical-reasoning-model/blob/main/scripts/summarize_runs.py): `scripts/summarize_runs.py`

### Other components

- **Experimenter**
- **GSM8K**
- **Teacher model**
- **Qwen base model**

## Connections

- Experimenter → Trace generation: starts (evidence: `README.md`)
- GSM8K → Trace generation: supplies questions (evidence: `data_generation/generate_data.py`)
- Teacher model → Trace generation: generates traces (evidence: `data_generation/generate_data.py`)
- Trace generation → Tagged SFT data: writes traces (evidence: `data_generation/prepare_tagged_dataset.py`)
- Experimenter → SFT training: starts (evidence: `README.md`)
- Tagged SFT data → SFT training: provides training data (evidence: `scripts/train_sft.py`)
- Qwen base model → SFT training: initializes model (evidence: `scripts/train_sft.py`)
- Experimenter → GRPO training: starts (evidence: `README.md`)
- GSM8K → GRPO prompts: supplies prompts (evidence: `data_generation/prepare_grpo_dataset.py`)
- Tagged SFT data → GRPO prompts: shares prompt format (evidence: `data_generation/prepare_grpo_dataset.py`)
- GRPO prompts → GRPO training: provides training data (evidence: `scripts/train_grpo.py`)
- Saved adapters → GRPO training: initializes policy (evidence: `scripts/train_grpo.py`)
- GRPO rewards → GRPO training: scores completions (evidence: `scripts/train_grpo.py`)
- SFT training → Saved adapters: saves adapter (evidence: `scripts/train_sft.py`)
- GRPO training → Saved adapters: saves adapter (evidence: `scripts/train_grpo.py`)
- Experimenter → Model evaluation: runs evaluation (evidence: `README.md`)
- GSM8K → Model evaluation: provides test split (evidence: `scripts/evaluate_all.py`)
- Qwen base model → Model evaluation: provides model
- Saved adapters → Model evaluation: provides adapter (evidence: `README.md`)
- Model evaluation → Evaluation files: writes results (evidence: `scripts/evaluate_all.py`)
- Experimenter → Run summaries: starts analysis (evidence: `README.md`)
- Evaluation files → Run summaries: reads runs (evidence: `scripts/summarize_runs.py`)
- Run summaries → Paired comparison: uses comparison logic (evidence: `scripts/summarize_runs.py`)
- Run summaries → Summary reports: writes reports (evidence: `scripts/summarize_runs.py`)
- Experimenter → Paired comparison: compares runs (evidence: `scripts/compare_runs.py`)
