Skip to content

Repository files navigation

MetaMath: Bootstrap Your Own Mathematical Questions for Large Language Models

Code LicenseModel Weight LicensePython 3.9+

🤗 HF Repo • 📃 [MetaMath]

MetaMath

News

  • 🔥 Our MetaMath-Llemma-7B model achieves 30.0 pass@1 on the MATH Benchmarks, surpassing all the SOTA open-source LLM in 7B-13B scales! All the training scripts and the model are opened.
  • 🔥 Our MetaMath-Mistral-7B model achieves 77.7 pass@1 on the GSM8k Benchmarks, surpassing all the SOTA open-source LLM! All the training scripts and the model are opened.
  • 🔥 The full MetaMathQA dataset is now released in the huggingface MetaMathQA!
  • 🔥 We released the GSM8K_Backward dataset is also released in the huggingface GSM8K_Backward to evaluate the reversal mathematical reasoning ability!
  • 🔥 Although the data augmentation for MetaMathQA is sourced from ChatGPT 3.5, Our MetaMath-70B model outperforms the closed-source LLMs ChatGPT 3.5 on the GSM8K!
  • 🔥 Our MetaMath-7B model achieves 66.5 pass@1 on the GSM8k Benchmarks, 11.6 points higher than the SOTA open-source LLM!
  • 🔥 Our MetaMath-7B model achieves 19.8 pass@1 on the MATH Benchmarks, 9.1 points higher than the SOTA open-source LLM!
ModelCheckpointPaperGSM8kMATHLicense
MetaMath-70B-V1.0🤗 HF Link📃 [MetaMath]82.326.6Llama 2
MetaMath-13B-V1.0🤗 HF Link📃 [MetaMath]72.322.4Llama 2
MetaMath-7B-V1.0🤗 HF Link📃 [MetaMath]66.519.8Llama 2
MetaMath-Mistral-7B🤗 HF Link📃 [MetaMath]77.728.2Apache License 2.0
MetaMath-Llemma-7B🤗 HF Link📃 [MetaMath]69.230.0Apache License 2.0

Comparing MetaMath with the LLM models.

🔥 Comprehensive Results

ModelGSM8k Pass@1MATH Pass@1
MPT-7B6.83.0
Falcon-7B6.82.3
LLaMA-1-7B11.02.9
LLaMA-2-7B14.62.5
MPT-30B15.23.1
LLaMA-1-13B17.83.9
GPT-Neo-2.7B19.5--
Falcon-40B19.62.5
Baichuan-chat-13B23.9--
Vicuna-v1.3-13B27.6--
LLaMA-2-13B28.73.9
InternLM-7B31.2--
ChatGLM-2-6B32.4--
GPT-J-6B34.9--
LLaMA-1-33B35.63.9
LLaMA-2-34B42.26.24
RFT-7B50.3--
LLaMA-1-65B50.910.6
Qwen-7B51.6--
WizardMath-7B54.910.7
LLaMA-2-70B56.813.5
WizardMath-13B63.914.0
🔥 MetaMath-7B66.519.8
🔥 MetaMath-13B72.322.4
🔥 MetaMath-Mistral-7B77.728.2
🔥 MetaMath-Llemma-7B69.230.0
WizardMath-70B81.622.7
🔥 MetaMath-70B82.326.6

Quick Start

Clone Metamath and install the required packages:

git clone https://github.com/meta-math/MetaMath.git
cd MetaMath
pip install -r requirements.txt

If you encounter a Ray installation problem, please run:

pip install --upgrade ray
pip install --upgrade pyarrow
pip install pandas

Dataset Usage

Run the following command to load the data:

fromdatasetsimportload_datasetdataset=load_dataset("meta-math/MetaMathQA")

Training

you need to prepare the llama-2 base model and our MetaMathQA dataset huggingface MetaMathQA

bash run.sh

or

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python3 -m torch.distributed.launch --master_addr ${MASTER_ADDR} --master_port ${MASTER_PORT} --nproc_per_node=8 --use_env train_math.py \
--model_name_or_path "meta-llama/Llama-2-7b-hf" \
--data_path "path/to/metamathqa" \
--data_length 10000000 \
--bf16 True \
--output_dir "path/to/save" \
--num_train_epochs 3 \
--per_device_train_batch_size 4 \
--per_device_eval_batch_size 4 \
--gradient_accumulation_steps 4 \
--evaluation_strategy "no" \
--save_strategy "steps" \
--save_steps 1000 \
--save_total_limit 2 \
--learning_rate 2e-5 \
--weight_decay 0. \
--warmup_ratio 0.03 \
--lr_scheduler_type "cosine" \
--logging_steps 1 \
--fsdp "full_shard auto_wrap" \
--fsdp_transformer_layer_cls_to_wrap 'LlamaDecoderLayer' \
--tf32 True

Supervised fine-tuning

We supervised fine-tune MetaMath-7B with the following hyperparameters:

HyperparameterLLaMA 2 7B
Batch size128
Learning rate2e-5
Epochs3
Max length512
LR schedulercosine

Evaluation

we use the vllm to help the fast generation:

python eval_gsm8k.py --model "path/to/save" --data_file ./data/test/GSM8K_test.jsonl
python eval_math.py --model "path/to/save" --data_file ./data/test/MATH_test.jsonl

where the "path/to/save" should be replaced by the finetuned model, you can also download our series of MetaMath models in huggingface:
🤗 MetaMath 7B 🤗 MetaMath 13B 🤗 MetaMath 70B

The inference prompt for our MetaMath is:

"Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Response: Let's think step by step."

Thanks for the open source code of WizardMath and RFT. Some of our codes are based on them.

Citation

Please cite the paper if you refer to our model, code, data or paper from MetaMath.
@article{yu2023metamath,
title={MetaMath: Bootstrap Your Own Mathematical Questions for Large Language Models},
author={Yu, Longhui and Jiang, Weisen and Shi, Han and Yu, Jincheng and Liu, Zhengying and Zhang, Yu and Kwok, James T and Li, Zhenguo and Weller, Adrian and Liu, Weiyang},
journal={arXiv preprint arXiv:2309.12284},
year={2023}
}

About

MetaMath: Bootstrap Your Own Mathematical Questions for Large Language Models

Resources

Stars

457 stars

Watchers

6 watching

Forks

Used by

Contributors

Languages