[🏠官网] | [🤖 与DeepSeek LLM对话] | [Discord] | [微信]
更多详情请参见 Introduction。
以下为模型使用示例。
对话补全
❗❗❗ 请使用思维链提示词来测试 DeepSeekMath-Instruct 和 DeepSeekMath-RL:
英文问题:{question}\nPlease reason step by step, and put your final answer within \boxed{}.
中文问题:{question}\n请通过逐步推理来解答问题,并把最终答案放置于\boxed{}中。
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
model_name = "deepseek-ai/deepseek-math-7b-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
model.generation_config = GenerationConfig.from_pretrained(model_name)
model.generation_config.pad_token_id = model.generation_config.eos_token_id
messages = [
{"role": "user", "content": "what is the integral of x^2 from 0 to 2?\nPlease reason step by step, and put your final answer within \\boxed{}."}
]
input_tensor = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
outputs = model.generate(input_tensor.to(model.device), max_new_tokens=100)
result = tokenizer.decode(outputs[0][input_tensor.shape[1]:], skip_special_tokens=True)
print(result)若不想使用提供的函数apply_chat_template,您也可以按照示例模板与我们的模型进行交互。请注意,messages需替换为您的输入内容。
User: {messages[0]['content']}
Assistant: {messages[1]['content']}<|end▁of▁sentence|>User: {messages[2]['content']}
Assistant:注意: 默认情况下(add_special_tokens=True),我们的分词器会在输入文本前自动添加一个 bos_token(<|begin▁of▁sentence|>)。此外,由于系统提示与我们当前版本的模型不兼容,不建议在输入中包含系统提示。
本代码仓库采用 MIT 许可证。DeepSeekMath 模型的使用受模型许可证约束。DeepSeekMath 支持商业用途。
更多详情请参见 LICENSE-MODEL。
如有任何问题,请提交 issue 或通过 service@deepseek.com 与我们联系。