ORED基准实验
MATH
提示不同的区别
这两段代码分别表示了两种不同的提示(CoT 和 TIR)格式,它们是用于与语言模型进行交互的提示,目的是引导模型按特定的方式进行推理或解决问题
CoT (Chain of Thought):要求模型展示逐步推理的过程,通常适用于需要分步推理的任务,如数学题目。
TIR (Task-Integrated Reasoning):要求模型结合自然语言推理和程序(代码)来解决问题,这对于需要程序执行的任务(如编程或更复杂的数学计算)更为适用。
两者的主要区别在于 TIR 要求在推理过程中结合程序执行,而 CoT 只是让模型按步骤思考问题
Qwen推理代码
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "/kaggle/input/qwen2.5-math/transformers/1.5b/1"
#device = "cuda" # the device to load the model onto
model = AutoModelForCausalLM.from_pretrained(
model_path,
torch_dtype="auto",
device_map="auto",
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(
model_path,
trust_remote_code=True
)
prompt = "what is the integral of $x^2$ from 0 to 2?"
# CoT
messages = [
{"role": "system", "content": "Please reason step by step, and put your final answer within \\boxed{}."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer(
[text],
return_tensors="pt"
).to(model.device)
print(f"开始推理{prompt}")
generated_ids = model.generate(
**model_inputs,
max_new_tokens=512,
)
print("推理完成.")
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(
generated_ids,
skip_special_tokens=True
)[0]
print(f"推理结果{response}")
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗