如何开启InternVL3.5-30B-A3B的思考模式?R1风格推理系统提示词与采样参数调优完全指南

原创2026-10-17 12:13:541,930 阅读

如何开启InternVL3.5-30B-A3B的思考模式?R1风格推理系统提示词与采样参数调优完全指南

本文介绍 InternVL3.5-30B-A3B 多模态大模型如何开启思考模式(Thinking Mode):只需一行代码设置 R1 风格系统提示词,再配合 do_sample=True、temperature=0.6 的采样参数调优,即可让模型先输出 think 推理链、再给出最终答案,显著提升数学与视觉推理任务表现。

什么是 InternVL3.5 的思考模式 🧠

InternVL3.5 是上海人工智能实验室开源的多模态大模型家族,30B-A3B 是其中基于 Qwen3-30B-A3B MoE 语言模型 + InternViT-300M 视觉编码器的高效版本(总参数约 30.8B,激活仅 3B)。

所谓思考模式(Thinking Mode),属于官方提出的 Test-Time Scaling(测试时扩展) 中的 Deep Thinking 能力:通过系统提示词引导模型在给出答案前,先逐步拆解问题、验证中间结论,把完整推理过程包裹在 think 与 think 标签内。

⚠️ 小提示:本仓库 InternVL3_5-30B-A3B-Pretrained 是完成 CPT(多模态持续预训练) 阶段的检查点。官方建议:如果你想要最好的思考模式体验,请选用完成完整训练流程(CPT + SFT + CascadeRL)的 InternVL3.5-30B-A3B,两者参数用法完全一致。

一步开启思考模式:R1 风格系统提示词

开启方式非常直接——把模型的 system_message 属性替换为官方 R1_SYSTEM_PROMPT,无需修改模型内部代码:

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 think and think 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 think section.
""".strip()

model.system_message = R1_SYSTEM_PROMPT

这行赋值背后发生了什么?

理解机制有助于排查问题,核心链路在源码中非常清晰:

  1. 模型初始化时,system_message 默认为对话模板 internvl2_5 内置的一句话(conversation.py),模板格式为 system + {system_message}。
  2. 当你执行 model.system_message = R1_SYSTEM_PROMPT 后,每次调用 chat() 时,该提示词会被写入对话模板并渲染到最终 prompt 的开头(见 modeling_internvl_chat.py 的 template.system_message = self.system_message)。
  3. 因此你随时可以来回切换:赋值为空字符串 '' 或原始默认值即可回到普通对话模式。

采样参数调优:官方推荐值速查

开启思考模式后,官方明确推荐 do_sample=True 且 temperature=0.6,用于缓解长推理链中常见的**重复生成(repetition)**问题:

generation_config = dict(
    max_new_tokens=4096,   # 思考链较长,建议调大
    do_sample=True,        # 官方推荐
    temperature=0.6,       # 官方推荐,抑制复读
)

pixel_values = load_image('./your_image.jpg', max_num=12).to(torch.bfloat16).cuda()
question = '<image>\n请一步步分析这张图里的几何题并给出答案。'
response = model.chat(tokenizer, pixel_values, question, generation_config)
参数 推荐值 作用
do_sample True 开启采样,避免贪心解码在推理链上"卡住复读"
temperature 0.6 官方推荐值,平衡多样性与稳定性
max_new_tokens 4096~8192 think 标签内容较长,1024 的默认值容易截断推理过程
top_k / top_p 50 / 0.95(可选) LMDeploy 部署时官方示例采用的组合,见 README.md

💡 如果用 LMDeploy 部署成服务,对应写法是:

from lmdeploy import GenerationConfig
gen_config = GenerationConfig(top_k=50, top_p=0.95, temperature=0.6, max_new_tokens=8192)

常见坑与排查清单 ✅

  • 没有输出 think 标签:确认 model.system_message 的赋值发生在第一次 chat() 调用之前,且变量名拼写正确(应为 R1_SYSTEM_PROMPT)。
  • 推理链被截断:think 内容往往超过 1024 token,把 max_new_tokens 调大到 4096 以上;chat() 内部会按模板分隔符切分输出(modeling_internvl_chat.py),截断只会让你拿到不完整的推理。
  • 复读/重复内容:回到 temperature=0.6 + do_sample=True 组合,这是官方针对该问题的直接建议。
  • 显存不够:30B 级别模型单卡 A100 可部署 30B 及以下版本;多卡场景加 device_map="auto",或改用 8-bit 量化(load_in_8bit=True)。

相关资料位置

总结

开启 InternVL3.5-30B-A3B 思考模式只需两步:① 一行 model.system_message = R1_SYSTEM_PROMPT 注入 R1 风格系统提示词;② 设置 do_sample=True, temperature=0.6 并调大 max_new_tokens。掌握这套组合拳,你就能在这款高效 MoE 多模态模型上稳定获得"先推理、后作答"的 Deep Thinking 能力。

登录后查看全文
InternVL3_5-30B-A3B-Pretrained