- evaluate_math500.py: standalone script to evaluate models on the MATH-500 dataset
- evaluate_math500_batched.py: same as above, but processes multiple examples in parallel during generation (for higher throughput)
- evaluate_json.py: evaluate saved records JSON/JSONL files and report accuracy
Both evaluation scripts import functionality from the reasoning_from_scratch package to avoid code duplication. (See chapter 2 setup instructions for installation details.)
Note: If you are not a uv user, replace uv run ...py with python ...py in the examples below.
Run with:
python evaluate_math500.pyOr, with uv:
uv run evaluate_math500.pyOptions:
uv run evaluate_math500.py --help
options:
-h, --help show this help message and exit
--device DEVICE Device to use: "auto" (default) or any torch device string
(e.g., "cpu", "cuda", "cuda:0", "mps").
--which_model {base,reasoning}
Model variant to load (default: "base").
--dataset_size DATASET_SIZE
Number of MATH-500 examples to evaluate (default: 10).
--max_new_tokens MAX_NEW_TOKENS
Max new tokens to generate (default: 2048).
--compile Enable torch.compile.
--verbose Print per-sample correctness while evaluating.
This version extends batching to generation itself, enabling parallel decoding:
uv run evaluate_math500_batched.py --helpExtra options:
--batch_size BATCH_SIZE
Number of examples to generate in parallel (default: 4).
--disable_efficient_mode
Use a simpler batched inference method. Slower and more
memory-intensive, but easier to debug.
Implementation note:
By default, batched generation halts for sequences that emit a stop token. With --disable_efficient_mode, all sequences continue until the longest finishes. This affects compute efficiency only, not qualitative results, since tokens after the stop token are discarded.
Tip (MPS devices): Run with:
PYTORCH_ENABLE_MPS_FALLBACK=1 uv run evaluate_math500_batched.pySome PyTorch ops used in efficient batched inference are not yet supported on MPS. As a fallback, you can also use --disable_efficient_mode.
evaluate_math500.py --dataset_size 500
| Device / Dataset size | Base model | Reasoning model |
|---|---|---|
| Mac Mini M4 CPU (500 examples, sequential | 43.6 min | Didn't run (too hot) |
| Mac Mini M4 GPU (500 examples, sequential) | 37.5 min | Didn't run (too hot) |
| DGX Spark (500 examples, sequential) | 10.0 min | 182.2 min |
| H100 GPU (500 examples, sequential) | 13.3 min | 185.4 min |
evaluate_math500_batched.py --dataset_size 500 --batch_size 128
| Device / Dataset size | Base model | Reasoning model |
|---|---|---|
Mac Mini M4 CPU (500 examples, batched, --batch_size 128) |
167.2 min | Didn't run (too hot) |
Mac Mini M4 GPU (500 examples, batched, --batch_size 128) |
Error* | Error |
DGX Spark (500 examples, batched, --batch_size 128) |
16.3 min | 119.3 min |
H100 GPU (500 examples, batched, --batch_size 128) |
3.3 min | 14.6 min |
- The accuracy of the base model is 15.6% (78/500); the accuracy of the reasoning model is 48.2% (241/500).
Use this if you already have saved records and only want to (re)compute accuracy:
uv run evaluate_json.py --json_path math500_base-mps-evaluate-script.jsonl
# Accuracy 15.6% (78/500)
Optional keys:
```bash
uv run evaluate_json.py \
--json_path my_records.json \
--gtruth_answer "gtruth_answer" \
--generated_text "generated_text"