如何开启InternVL3_5-14B-MPO思考模式:R1系统提示词与采样参数配置实战
如何开启InternVL3_5-14B-MPO思考模式:R1系统提示词与采样参数配置实战
本文带你快速上手 InternVL3_5-14B-MPO 思考模式(Thinking Mode):只需两步——设置 R1_SYSTEM_PROMPT 系统提示词,并配置 do_sample=True、temperature=0.6 采样参数,即可让这款多模态模型"先深度推理、再给答案"。
🧠 为什么需要思考模式
InternVL3.5 系列采用 Cascade Reinforcement Learning(级联强化学习) 训练:先用离线 RL 算法 MPO(Mixed Preference Optimization,混合偏好优化) 打基础,再用在线 RL 算法 GSPO 精调。本仓库的 InternVL3_5-14B-MPO 正是完成了 CPT + SFT + MPO 三阶段的 14B 多模态模型,官方训练数据中专门包含 "Thinking 模式" 的多模态推理数据(详见 README.md 的 Supervised Fine-Tuning 一节)。
官方将这种能力称为 Deep Thinking(深度思考):通过系统提示词引导模型把复杂问题拆解为逻辑步骤、逐步验证中间结论,再输出最终答案,能显著提升数学、科学等多步推理任务的表现。
💡 简单理解:MPO 阶段让模型"学会了推理",而 R1 系统提示词 是按下"开始思考"的开关。
🚀 一键开启:配置 R1_SYSTEM_PROMPT
官方推荐的思考模式系统提示词(R1_SYSTEM_PROMPT)如下,要求模型先在 <think>...</think> 标签内展开分析,再给出独立、简洁的最终答案:
R1_SYSTEM_PROMPT = """
You are an AI assistant that rigorously follows this response protocol:
1. First, conduct a detailed analysis of the question. Consider different angles, potential solutions, and reason through the problem step-by-step. Enclose this entire thinking process within and tags.
2. After the thinking section, provide a clear, concise, and direct answer to the user's question. Separate the answer from the think section with a newline.
Ensure that the thinking process is thorough but remains focused on the query. The final answer should be standalone and not reference the thinking section.
""".strip()
在 transformers 中,开启方式只有一行——把它赋给模型的 system_message 属性(注意变量名拼写为 R1_SYSTEM_PROMPT,README.md 示例中的 R1_SYSTEMP_PROMPT 是笔误):
model.system_message = R1_SYSTEM_PROMPT
系统提示词在哪里生效?
- 本模型使用的对话模板是
internvl2_5,见 config.json 中"template": "internvl2_5"; - 模板默认自带一句自我介绍式的系统提示词,定义在 conversation.py。你设置的
R1_SYSTEM_PROMPT会在每次chat()时覆盖它; - 覆盖逻辑在 modeling_internvl_chat.py 的
chat()方法中:template.system_message = self.system_message,随后拼入最终 prompt 送给 Qwen3-14B 语言模型生成。
也就是说,只要覆盖了 system_message,无需修改任何模板代码。
⚡ 最快配置方法:do_sample 与 temperature
开启思考模式后,模型要生成长链推理,官方特别提醒:建议设置 do_sample=True 且 temperature=0.6,以抑制不期望的重复输出(这是 README 的官方推荐值)。
而 config.json 中默认是 "do_sample": false(贪心解码),所以必须显式覆盖,否则思考文本很容易陷入复读:
| 参数 | 推荐值 | 说明 |
|---|---|---|
do_sample |
True |
开启随机采样,避免思考过程重复 |
temperature |
0.6 |
官方推荐值,兼顾多样性与稳定性 |
max_new_tokens |
2048 起,复杂题建议 8192 |
思考链很长,给足生成长度 |
top_k / top_p |
50 / 0.95(默认) |
模型自带默认值,一般无需改动 |
配置示例(transformers,完整推理流程可参考 README.md 的 Inference with Transformers 一节):
import torch
from transformers import AutoTokenizer, AutoModel
path = "OpenGVLab/InternVL3_5-14B-MPO" # 本地路径亦可
model = AutoModel.from_pretrained(
path, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True,
use_flash_attn=True, trust_remote_code=True,
device_map="auto").eval()
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast=False)
model.system_message = R1_SYSTEM_PROMPT # ① 开启思考模式
generation_config = dict(
max_new_tokens=8192,
do_sample=True, # ② 开启采样
temperature=0.6, # ③ 官方推荐温度
)
question = "<image>\n图中有几只红熊猫?请仔细数一数并给出推理过程。"
# pixel_values 由 load_image(...) 得到,参考 README 示例
response = model.chat(tokenizer, pixel_values, question, generation_config)
print(response)
加载前请确保 transformers>=4.52.1。如果本地下载了模型文件,也可以用 git clone https://gitcode.com/OpenGVLab/InternVL3_5-14B-MPO 获取权重与推理代码,然后把 path 指向本地目录。
🖥️ 服务化部署:LMDeploy 中开启思考模式
用 LMDeploy 部署时,系统提示词直接拼进用户消息,采样参数走 GenerationConfig:
from lmdeploy import pipeline, GenerationConfig
from lmdeploy.vl import load_image
pipe = pipeline("OpenGVLab/InternVL3_5-14B-MPO", backend_config=PytorchEngineConfig(session_len=32768, tp=1))
image = load_image("examples/image1.jpg")
# 思考模式:R1 提示词 + 官方推荐采样参数
prompt = R1_SYSTEM_PROMPT + "\n" + "这张图里有什么?请详细推理。"
gen_config = GenerationConfig(top_k=50, top_p=0.95, temperature=0.6, max_new_tokens=8192)
sess = pipe.chat((prompt, image), gen_config=gen_config)
print(sess.response.text)
🛠️ 常见问题排查清单
- 模型没有输出
<think>...思考块:确认model.system_message = R1_SYSTEM_PROMPT是否在chat()调用前执行,且变量名拼写正确(不是R1_SYSTEMP_PROMPT)。 - 思考过程反复复读、卡住:检查
do_sample是否为True、temperature是否为0.6;同时把max_new_tokens调大,思考链被提前截断也会显得"没说完"。 - 多轮对话里系统提示词丢失:
chat()每轮都会用当前self.system_message重建模板(见 modeling_internvl_chat.py),所以切换思考/普通模式只需改这一个属性,无需重建模型。 - 显存不够:14B 模型单卡 A100 即可部署(bf16),显存紧张时可用 BNB 8-bit 量化加载,写法见 README.md 的 BNB 8-bit Quantization 小节。
- 推理效果不理想:官方提示感知类任务本身已很强,主要收益在数学、图表、科学等多步推理题;这类任务开启思考模式后再配合更大的
max_new_tokens效果最佳。
✅ 三步总结
- 设提示词:
model.system_message = R1_SYSTEM_PROMPT,覆盖internvl2_5模板的默认系统消息; - 配采样:
do_sample=True+temperature=0.6,防复读; - 给长度:
max_new_tokens提到2048~8192,让思考链完整展开。
配置完成后,InternVL3_5-14B-MPO 就会先输出完整的推理过程,再给出独立简洁的最终答案——这就是官方的 Deep Thinking 用法。