Structured arithmetic reasoning with Qwen2.5 on GSM8K
Math-Consistent Qwen investigates whether explicit supervision of intermediate arithmetic structure can improve reasoning beyond standard next-token imitation. It fine-tunes Qwen2.5-1.5B-Instruct with LoRA on GSM8K.
The evaluation distinguishes two outcomes:
- answer correctness — whether the final numerical answer is right;
- reasoning consistency — whether intermediate calculations are valid and agree with the final answer.
Status: A0–A2 have single-seed reference results. A3–A4 are implemented and ready to run. A5–A8 are planned. The findings have not been peer reviewed.
On the same local BF16/MPS validation protocol, A1 reduces completion-only
eval_loss by 41.4% relative to the pretrained baseline.
| Model | eval_loss |
Final | Strict | Consistent | Correct + consistent |
|---|---|---|---|---|---|
| A0 — pretrained | 0.9131 | 66.67% | 15.00% | 1.67% | 1.33% |
| A1 — LoRA CE | 0.5350 | 70.33% | 70.33% | 80.67% | 63.00% |
| A2 — math-token weighting | 0.3469† | 64.00% | 64.00% | 79.33% | 57.00% |
† A2 loss was measured on CUDA/L40S; A0/A1 losses were measured on MPS, so they must not be compared directly. Generation metrics use the same frozen 300-example validation subset. See the versioned A0–A2 report for conditions and provenance.
The core technical contributions are:
- deterministic data splits with revisions and SHA-256 fingerprints;
- canonical
<<expression=result>>supervision; - safe AST-based arithmetic parsing without
eval; - exact arithmetic graphs compiled into executable postfix programs;
- declarative ablations sharing one training and evaluation pipeline;
- separate final-answer, format, step-accuracy, and consistency metrics.
Python 3.10–3.13 is supported. Data preparation and tests run on CPU; full training is intended for CUDA.
python3 -m pip install uv
uv sync --frozen
uv run ruff check .
uv run pytestPrepare the frozen split:
uv run python script/create_data_split.py
Train an ablation:
uv run python script/train.py \ --ablation A1 \ --num-train-epochs 30 \ --wandb-mode disabled \ --require-cuda
Evaluate the pretrained model:
uv run python script/evaluation.py \ --experiment-name a0-pretrained-test \ --output-file outputs/a0_test.json
Evaluate a LoRA checkpoint:
uv run python script/evaluation.py \ --checkpoint-path outputs/qwen2.5-1.5b-gsm8k-a1 \ --experiment-name a1-lora-test \ --output-file outputs/a1_test.json
Use --subset-size 20 for a smoke evaluation. Weights & Biases tracking is
optional; set WANDB_KEY in .env and choose --wandb-mode online to enable
it.
| Stage | Objective | Status |
|---|---|---|
| A0 | pretrained baseline | evaluated |
| A1 | completion-only cross-entropy | evaluated |
| A2 | mathematical-token weighting | evaluated |
| A3 | signed-log result prediction | implemented |
| A4 | postfix execution consistency | implemented |
| A5–A7 | structured operator, dependency, and composition losses | planned |
| A8 | best-of-N generation with verification | planned |
The complete hypotheses, controls, hyperparameters, and objective definitions are in the experimental protocol.
| Topic | Reference |
|---|---|
| Documentation map | documentation index |
| Experimental controls | research protocol |
| Dataset and training features | dataset contract |
| Arithmetic graph and postfix execution | graph contract |
| Generated-answer parsing | parsing contract |
| Evaluation metrics | metric definitions |
| Planned experiments | research roadmap |
documentation/ scientific and technical contracts
script/ data, training, and evaluation entry points
src/data/ frozen splits, language features, arithmetic graphs
src/model/ model factory, tokenizer, device policy, auxiliary heads
src/training/ declarative objectives, callbacks, and Trainer
src/evaluation/ generation, parsing, diagnostics, and metrics
tests/ unit and integration tests
Citation metadata is provided in CITATION.cff. Contributions must follow CONTRIBUTING.md and the frozen comparison protocol.
Original code and documentation are released under the Apache License 2.0. Qwen2.5 is Apache-2.0 and GSM8K is MIT. See THIRD_PARTY_NOTICES.md for attribution and checkpoint redistribution guidance.