# mehulmathodia/grpo-reasoner architecture

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

- Interactive diagram: https://gitdiagram.com/mehulmathodia/grpo-reasoner
- Repository: https://github.com/mehulmathodia/grpo-reasoner

## Overview

This repository is an experimental pipeline for fine-tuning small language models on verifiable math reasoning and measuring whether the gains generalize. The main workflow loads GSM8K prompts and answers, trains a LoRA model with GRPO and correctness/format rewards, then evaluates exact-match accuracy; separate branches measure maj@k, transfer to GSM-Hard/SVAMP, and compare against supervised and rejection-sampling fine-tuning. Source excerpts establish the core data, reward, training, and evaluation calls. Some modules are represented from the README and source index because their implementations were not excerpted.

Main entry points: [`grpo_reasoner/eval.py`](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/eval.py) (Greedy evaluation), [`grpo_reasoner/data.py`](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/data.py) (GSM8K loader), [`grpo_reasoner/rft.py`](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/rft.py) (RFT data builder), [`grpo_reasoner/rewards.py`](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/rewards.py) (Verifiable rewards)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_gsm_data["GSM8K loader<br/>[data.py]"]
  node_sft_data["SFT data loader<br/>[sft_data.py]"]
  node_generation["Model generation<br/>[generate.py]"]
end

subgraph group_training["Model training"]
  node_rewards["Verifiable rewards<br/>[rewards.py]"]
  node_grpo_training["GRPO training<br/>[train_grpo.py]"]
  node_rft_data["RFT data builder<br/>[rft.py]"]
  node_sft_training["SFT training<br/>[train_sft.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluation["Greedy evaluation<br/>[eval.py]"]
  node_majk["Maj@k evaluation<br/>[majk.py]"]
  node_transfer["Transfer evaluation<br/>[transfer.py]"]
end

subgraph group_experiments["Comparative experiments"]
  node_ablation["SFT/RFT ablation"]
  node_transfer_run["Transfer benchmark run"]
  node_comparison["Maj@k comparison"]
end

node_researcher(("Researcher"))
node_gsm8k[("GSM8K")]
node_modelhub[("Model checkpoint")]

node_researcher -->|"trains model"| node_grpo_training
node_gsm8k -->|"supplies examples"| node_gsm_data
node_researcher -->|"evaluates model"| node_evaluation
node_modelhub -.->|"loads checkpoint"| node_generation
node_gsm_data -->|"provides prompts"| node_grpo_training
node_rewards -->|"scores completions"| node_grpo_training
node_gsm_data -->|"provides examples"| node_rft_data
node_generation -->|"samples completions"| node_rft_data
node_rewards -->|"verifies answers"| node_rft_data
node_sft_data -->|"provides examples"| node_sft_training
node_rft_data -->|"provides RFT data"| node_sft_training
node_gsm_data -->|"loads test split"| node_evaluation
node_generation -->|"generates answers"| node_evaluation
node_rewards -->|"extracts answers"| node_evaluation
node_gsm_data -->|"loads examples"| node_majk
node_generation -->|"samples completions"| node_majk
node_rewards -->|"extracts answers"| node_majk
node_evaluation -->|"evaluates benchmarks"| node_transfer_run
node_transfer -->|"loads benchmark data"| node_transfer_run
node_rft_data -->|"builds comparison data"| node_ablation
node_sft_training -->|"trains SFT arms"| node_ablation
node_evaluation -->|"evaluates arms"| node_ablation
node_majk -->|"measures sampling"| node_comparison

click node_gsm_data "https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/data.py"
click node_sft_data "https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/sft_data.py"
click node_generation "https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/generate.py"
click node_rewards "https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/rewards.py"
click node_grpo_training "https://github.com/mehulmathodia/grpo-reasoner/blob/main/train_grpo.py"
click node_rft_data "https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/rft.py"
click node_sft_training "https://github.com/mehulmathodia/grpo-reasoner/blob/main/train_sft.py"
click node_evaluation "https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/eval.py"
click node_majk "https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/majk.py"
click node_transfer "https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/transfer.py"
click node_ablation "https://github.com/mehulmathodia/grpo-reasoner/blob/main/notebooks/kaggle_sft_ablation_fair_kernel.py"
click node_transfer_run "https://github.com/mehulmathodia/grpo-reasoner/blob/main/notebooks/kaggle_transfer_kernel.py"
click node_comparison "https://github.com/mehulmathodia/grpo-reasoner/blob/main/eval_majk_compare.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_gsm_data,node_sft_data,node_generation toneBlue
class node_rewards,node_grpo_training,node_rft_data,node_sft_training,node_gsm8k,node_modelhub toneAmber
class node_evaluation,node_majk,node_transfer toneMint
class node_ablation,node_transfer_run,node_comparison toneRose
class node_researcher toneIndigo
```

## Components

### Data preparation

- [GSM8K loader](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/data.py): `grpo_reasoner/data.py`
- [SFT data loader](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/sft_data.py): `grpo_reasoner/sft_data.py`
- [Model generation](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/generate.py): `grpo_reasoner/generate.py`

### Model training

- [Verifiable rewards](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/rewards.py): `grpo_reasoner/rewards.py`
- [GRPO training](https://github.com/mehulmathodia/grpo-reasoner/blob/main/train_grpo.py): `train_grpo.py`
- [RFT data builder](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/rft.py): `grpo_reasoner/rft.py`
- [SFT training](https://github.com/mehulmathodia/grpo-reasoner/blob/main/train_sft.py): `train_sft.py`

### Evaluation

- [Greedy evaluation](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/eval.py): `grpo_reasoner/eval.py`
- [Maj@k evaluation](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/majk.py): `grpo_reasoner/majk.py`
- [Transfer evaluation](https://github.com/mehulmathodia/grpo-reasoner/blob/main/grpo_reasoner/transfer.py): `grpo_reasoner/transfer.py`

### Comparative experiments

- [SFT/RFT ablation](https://github.com/mehulmathodia/grpo-reasoner/blob/main/notebooks/kaggle_sft_ablation_fair_kernel.py): `notebooks/kaggle_sft_ablation_fair_kernel.py`
- [Transfer benchmark run](https://github.com/mehulmathodia/grpo-reasoner/blob/main/notebooks/kaggle_transfer_kernel.py): `notebooks/kaggle_transfer_kernel.py`
- [Maj@k comparison](https://github.com/mehulmathodia/grpo-reasoner/blob/main/eval_majk_compare.py): `eval_majk_compare.py`

### Other components

- **Researcher**
- **GSM8K**
- **Model checkpoint**

## Connections

- Researcher → GRPO training: trains model (evidence: `README.md`)
- GSM8K → GSM8K loader: supplies examples (evidence: `grpo_reasoner/data.py`)
- Researcher → Greedy evaluation: evaluates model (evidence: `README.md`)
- Model checkpoint → Model generation: loads checkpoint
- GSM8K loader → GRPO training: provides prompts (evidence: `train_grpo.py`)
- Verifiable rewards → GRPO training: scores completions (evidence: `train_grpo.py`)
- GSM8K loader → RFT data builder: provides examples (evidence: `grpo_reasoner/rft.py`)
- Model generation → RFT data builder: samples completions (evidence: `grpo_reasoner/rft.py`)
- Verifiable rewards → RFT data builder: verifies answers (evidence: `grpo_reasoner/rft.py`)
- SFT data loader → SFT training: provides examples (evidence: `train_sft.py`)
- RFT data builder → SFT training: provides RFT data
- GSM8K loader → Greedy evaluation: loads test split (evidence: `grpo_reasoner/eval.py`)
- Model generation → Greedy evaluation: generates answers (evidence: `grpo_reasoner/eval.py`)
- Verifiable rewards → Greedy evaluation: extracts answers (evidence: `grpo_reasoner/eval.py`)
- GSM8K loader → Maj@k evaluation: loads examples (evidence: `grpo_reasoner/majk.py`)
- Model generation → Maj@k evaluation: samples completions (evidence: `grpo_reasoner/majk.py`)
- Verifiable rewards → Maj@k evaluation: extracts answers (evidence: `grpo_reasoner/majk.py`)
- Greedy evaluation → Transfer benchmark run: evaluates benchmarks (evidence: `notebooks/kaggle_transfer_kernel.py`)
- Transfer evaluation → Transfer benchmark run: loads benchmark data (evidence: `notebooks/kaggle_transfer_kernel.py`)
- RFT data builder → SFT/RFT ablation: builds comparison data (evidence: `notebooks/kaggle_sft_ablation_fair_kernel.py`)
- SFT training → SFT/RFT ablation: trains SFT arms (evidence: `notebooks/kaggle_sft_ablation_fair_kernel.py`)
- Greedy evaluation → SFT/RFT ablation: evaluates arms (evidence: `notebooks/kaggle_sft_ablation_fair_kernel.py`)
- Maj@k evaluation → Maj@k comparison: measures sampling (evidence: `eval_majk_compare.py`)
