Loading...

文章背景图

DeepSeek-Math:数学推理大模型下载与推理使用指南

2026-10-27
0
- 字
- 分钟
|

DeepSeek-Math:数学推理大模型下载与推理使用指南

一、项目官方信息

项目 信息
GitHub 仓库 https://github.com/deepseek-ai/DeepSeek-Math
官网 https://www.deepseek.com
HuggingFace https://huggingface.co/deepseek-ai
开源协议 代码 MIT;模型遵循 Model License
主要语言 Python(约 100%)
Star 数 约 3.5k

DeepSeekMath 以 DeepSeek-Coder-v1.5 7B 为基础初始化,继续在 Common Crawl 中的数学相关 token 及自然语言、代码数据上预训练 500B token。DeepSeekMath 7B 在竞赛级 MATH 基准上达到 51.7%,不依赖外部工具与投票,性能接近 Gemini-Ultra 与 GPT-4。

官方放出 Base、Instruct、RL 三类 checkpoint。

DeepSeek-Math Logo

二、官方图片

上图为 DeepSeek-Math 官方 Logo。

三、环境要求

  • GPU:7B 模型,单卡约 16GB+ 显存(BF16);
  • CUDA、PyTorch;
  • HuggingFace transformers;
  • 磁盘:7B 权重 BF16 约 14GB。

四、部署/接入步骤

1. 下载模型权重

从 HuggingFace 拉取对应 checkpoint(Base / Instruct / RL),如:

huggingface-cli download deepseek-ai/deepseek-math-7b-base --local-dir ./deepseek-math-7b-base

Instruct / RL 版本对应 HuggingFace 上的 deepseek-math-7b-instruct、deepseek-math-7b-rl 仓库。

2. 用 transformers 加载推理

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

path = "deepseek-ai/deepseek-math-7b-instruct"
tokenizer = AutoTokenizer.from_pretrained(path)
model = AutoModelForCausalLM.from_pretrained(
    path, torch_dtype=torch.bfloat16, device_map="auto"
)

prompt = "Please reason step by step, and put your final answer within \\boxed{}.\n\nQuestion: What is the derivative of x^2?"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=512, do_sample=False)
print(tokenizer.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))

3. 数学题提示词范式

DeepSeek-Math 官方推荐让模型逐步推理、最终答案用 \boxed{} 包裹,这是其评测与使用的标准格式。

五、使用方法

  • Base 模型:继续预训练或研究数学表示;
  • Instruct 模型:直接做数学问答,配合 step-by-step 提示;
  • RL 模型:强化学习后的版本,数学解题能力更强;
  • 适用场景:数学题求解、公式推导、竞赛题辅助。

六、常见问题 FAQ

  1. 7B 需要多少显存? BF16 约 14GB 权重,单卡 16GB 显存可跑;更长上下文需更多。

  2. 为什么强调 step-by-step 和 boxed? 这是 DeepSeek-Math 的标准推理与答题格式,能显著提升解题准确率。

  3. 有多大的模型? 本开源版本为 7B 系列(Base/Instruct/RL)。

  4. 支持工具调用吗? 官方强调不依赖外部工具即可自包含解题;也提供工具使用评测,可自行扩展。

  5. 商用条款? 代码 MIT、模型遵循 Model License,使用前阅读 LICENSE-MODEL。

  6. 和通用模型比有什么优势? 专门在数学 token 上预训练,竞赛级 MATH 达 51.7%,接近 GPT-4 水平。

七、跳转链接

评论交流

文章目录