HuggingFace镜像/MathCoder2-DeepSeekMath-7B-openmind
模型介绍文件和版本分析
下载使用量0

MathCoder2

简介

MathCoder2 模型是通过在 MathCode-Pile 上进行持续预训练而创建的。它们在论文 MathCoder2: Better Math Reasoning from Continued Pretraining on Model-translated Mathematical Code 中被首次提出。

该数学预训练数据集包含数学代码以及对应的自然语言推理步骤,对于旨在执行高级数学推理任务的模型而言,这是一种优质资源。

在 Openmind 中的使用

from openmind import AutoModelForCausalLM, AutoTokenizer, pipeline, is_torch_npu_available
from openmind_hub import snapshot_download
import torch

import argparse
import time

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default="jeffding/MathCoder2-DeepSeekMath-7B-openmind",
    )
    args = parser.parse_args()
    return args

def main():
    args = parse_args()
    model_path = args.model_name_or_path

    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"

    # 加载分词器和模型
    model = AutoModelForCausalLM.from_pretrained( 
        model_path,  
        device_map=device,  
        torch_dtype="auto",  
        trust_remote_code=True,  
    ) 

    tokenizer = AutoTokenizer.from_pretrained(model_path,trust_remote_code=True) 
                                              
    start_time = time.time()

    torch.random.manual_seed(0) 
    

    messages = [ 
        {"role": "system", "content": "You are a helpful AI assistant."}, 
        {"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"}, 
        {"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."}, 
        {"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"}, 
    ] 

    pipe = pipeline( 
        "text-generation", 
        model=model, 
        tokenizer=tokenizer,
    ) 

    generation_args = { 
        "max_new_tokens": 500, 
        "return_full_text": False, 
        "temperature": 0.0, 
        "do_sample": False, 
    } 

    output = pipe(messages, **generation_args) 
    print(output[0]['generated_text']) 
                                        
    end_time = time.time()
    print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")

if __name__ == "__main__":
    main()

评估

image/png

引用

如果您发现本仓库对您有所帮助,请考虑引用我们的论文:

@misc{lu2024mathcoder2bettermathreasoning,
      title={MathCoder2: Better Math Reasoning from Continued Pretraining on Model-translated Mathematical Code}, 
      author={Zimu Lu and Aojun Zhou and Ke Wang and Houxing Ren and Weikang Shi and Junting Pan and Mingjie Zhan and Hongsheng Li},
      year={2024},
      eprint={2410.08196},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2410.08196}, 
}
@inproceedings{
wang2024mathcoder,
title={MathCoder: Seamless Code Integration in {LLM}s for Enhanced Mathematical Reasoning},
author={Zimu Lu and Aojun Zhou and Zimu Lu and Sichun Luo and Weikang Shi and Renrui Zhang and Linqi Song and Mingjie Zhan and Hongsheng Li},
booktitle={The Twelfth International Conference on Learning Representations},
year={2024},
url={https://openreview.net/forum?id=z8TW0ttBPp}
}