InternLM/Intern-S2-Preview
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Intern-S2-Preview

 

💻GitHub 代码库 • 🤗模型集合 • 💬在线对话

👋 欢迎加入我们的 Discord 和 微信 社群

简介

我们推出Intern-S2-Preview,这是一款高效的350亿参数科学多模态基础模型。除了常规的参数与数据规模扩展外,Intern-S2-Preview探索了任务扩展:通过提升科学任务的难度、多样性与覆盖范围,进一步释放模型能力。

通过将专业科学任务融入从预训练到强化学习的全链条训练流程,Intern-S2-Preview在多个核心专业科学任务上达到了与万亿参数规模的Intern-S1-Pro相当的性能,而其参数规模仅为350亿(基于Qwen3.5持续预训练)。同时,它还保持了强大的通用推理、多模态理解及智能体能力。

特性

  • 全链条训练的科学任务扩展:Intern-S2-Preview将数百项专业科学任务从预训练阶段扩展至强化学习阶段,使350亿参数模型在多个专业领域均展现出强劲性能。它进一步强化了小分子结构的空间建模能力,并引入实值预测模块,成为首个兼具材料晶体结构生成能力与强大通用能力的开源模型。

  • 面向科学工作流的增强型智能体能力:相比上一代模型,Intern-S2-Preview的智能体能力得到显著提升,在多项科学智能体基准测试中取得优异成绩。

  • 基于MTP与CoT压缩的高效RL推理:在强化学习阶段,Intern-S2-Preview采用带KL损失的共享权重MTP(多任务预测)机制,减少训练与推理行为的偏差,大幅提升MTP接受率与token生成速度。同时引入CoT(思维链)压缩技术,在缩短响应长度的同时保留强大推理能力,实现性能与效率的双重提升。

efficient RL reasoning with MTP and CoT compression
图1:复杂数学基准测试的推理效率。准确率 vs. 平均响应长度。Intern-S2-Preview(红色星形)显著优于万亿参数规模的Intern-S1-Pro(红色圆形),且在中等规模模型中以更高的token效率实现了更高准确率。

性能表现

我们在各类基准测试集(包括通用数据集和科学数据集)上对Intern-S2-Preview进行了评估。以下是其与近期视觉语言模型(VLMs)及大语言模型(LLMs)的性能对比结果。

performance

注:下划线表示开源模型中的最佳性能,粗体表示所有模型中的最佳性能。

我们使用OpenCompass和VLMEvalKit对所有模型进行评估。在文本推理基准测试中,Intern-S2-Preview的最大推理长度为128K tokens;在多模态基准测试中,其最大推理长度为64K tokens。

快速开始

采样参数

为确保获得更优结果,我们建议使用以下超参数:

top_p = 0.95
top_k = 50
min_p = 0.0
temperature = 0.8

服务部署

Intern-S2-Preview 可通过以下任意一种 LLM 推理框架进行部署:

  • LMDeploy
  • vLLM
  • SGLang

这些框架的详细部署示例可在 模型部署指南 中找到。

高级用法

工具调用

工具调用使模型能够通过调用外部工具和 API 来扩展其功能。以下示例展示了如何通过兼容 OpenAI 的 API(基于 lmdeploy api server)使用工具调用获取最新天气预报。

      

from openai import OpenAI
import json


def get_current_temperature(location: str, unit: str = "celsius"):
    """Get current temperature at a location.

    Args:
        location: The location to get the temperature for, in the format "City, State, Country".
        unit: The unit to return the temperature in. Defaults to "celsius". (choices: ["celsius", "fahrenheit"])

    Returns:
        the temperature, the location, and the unit in a dict
    """
    return {
        "temperature": 26.1,
        "location": location,
        "unit": unit,
    }


def get_temperature_date(location: str, date: str, unit: str = "celsius"):
    """Get temperature at a location and date.

    Args:
        location: The location to get the temperature for, in the format "City, State, Country".
        date: The date to get the temperature for, in the format "Year-Month-Day".
        unit: The unit to return the temperature in. Defaults to "celsius". (choices: ["celsius", "fahrenheit"])

    Returns:
        the temperature, the location, the date and the unit in a dict
    """
    return {
        "temperature": 25.9,
        "location": location,
        "date": date,
        "unit": unit,
    }

def get_function_by_name(name):
    if name == "get_current_temperature":
        return get_current_temperature
    if name == "get_temperature_date":
        return get_temperature_date

tools = [{
    'type': 'function',
    'function': {
        'name': 'get_current_temperature',
        'description': 'Get current temperature at a location.',
        'parameters': {
            'type': 'object',
            'properties': {
                'location': {
                    'type': 'string',
                    'description': 'The location to get the temperature for, in the format \'City, State, Country\'.'
                },
                'unit': {
                    'type': 'string',
                    'enum': [
                        'celsius',
                        'fahrenheit'
                    ],
                    'description': 'The unit to return the temperature in. Defaults to \'celsius\'.'
                }
            },
            'required': [
                'location'
            ]
        }
    }
}, {
    'type': 'function',
    'function': {
        'name': 'get_temperature_date',
        'description': 'Get temperature at a location and date.',
        'parameters': {
            'type': 'object',
            'properties': {
                'location': {
                    'type': 'string',
                    'description': 'The location to get the temperature for, in the format \'City, State, Country\'.'
                },
                'date': {
                    'type': 'string',
                    'description': 'The date to get the temperature for, in the format \'Year-Month-Day\'.'
                },
                'unit': {
                    'type': 'string',
                    'enum': [
                        'celsius',
                        'fahrenheit'
                    ],
                    'description': 'The unit to return the temperature in. Defaults to \'celsius\'.'
                }
            },
            'required': [
                'location',
                'date'
            ]
        }
    }
}]



messages = [
    {'role': 'user', 'content': 'Today is 2024-11-14, What\'s the temperature in San Francisco now? How about tomorrow?'}
]

openai_api_key = "EMPTY"
openai_api_base = "http://0.0.0.0:23333/v1"
client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)
model_name = client.models.list().data[0].id
response = client.chat.completions.create(
    model=model_name,
    messages=messages,
    max_tokens=32768,
    temperature=0.8,
    top_p=0.95,
    extra_body=dict(spaces_between_special_tokens=False),
    tools=tools)
print(response.choices[0].message)
messages.append(response.choices[0].message)

for tool_call in response.choices[0].message.tool_calls:
    tool_call_args = json.loads(tool_call.function.arguments)
    tool_call_result = get_function_by_name(tool_call.function.name)(**tool_call_args)
    tool_call_result = json.dumps(tool_call_result, ensure_ascii=False)
    messages.append({
        'role': 'tool',
        'name': tool_call.function.name,
        'content': tool_call_result,
        'tool_call_id': tool_call.id
    })

response = client.chat.completions.create(
    model=model_name,
    messages=messages,
    temperature=0.8,
    top_p=0.95,
    extra_body=dict(spaces_between_special_tokens=False),
    tools=tools)
print(response.choices[0].message)

思维与非思维模式切换

Intern-S2-Preview 默认启用思维模式,可增强模型的推理能力以生成更高质量的响应。通过在 tokenizer.apply_chat_template 中设置 enable_thinking=False,即可禁用该功能。

text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True,
    enable_thinking=False  # think mode indicator
)

在部署 Intern-S2-Preview 模型时,您可以通过调整请求中的 enable_thinking 参数来动态控制思考模式。

from openai import OpenAI
import json

messages = [
{
    'role': 'user',
    'content': 'who are you'
}, {
    'role': 'assistant',
    'content': 'I am an AI'
}, {
    'role': 'user',
    'content': 'AGI is?'
}]

openai_api_key = "EMPTY"
openai_api_base = "http://0.0.0.0:23333/v1"
client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)
model_name = client.models.list().data[0].id

response = client.chat.completions.create(
    model=model_name,
    messages=messages,
    temperature=0.8,
    top_p=0.95,
    max_tokens=2048,
    extra_body={
        "chat_template_kwargs": {"enable_thinking": False}
    }
)
print(json.dumps(response.model_dump(), indent=2, ensure_ascii=False))

注意:对于智能体任务,我们不建议禁用思考模式。

智能体集成

Intern-S2-Preview 可以通过两种方式接入智能体框架:连接自托管部署,或调用官方 InternLM API。下面我们将介绍这两种方式,并提供智能体框架(OpenClaw、Hermes 等)及 Claude Code 的使用示例。

1. 自托管部署(以 LMDeploy 为例)

首先,按照 模型部署指南 使用 LMDeploy 启动模型服务。以下示例假设服务运行在 http://0.0.0.0:23333。

连接智能体框架

大多数智能体框架(OpenClaw、Hermes 等)支持 OpenAI 兼容的端点。将它们指向 LMDeploy 服务的基础 URL http://0.0.0.0:23333/v1 即可。

您可以通过以下命令检查连接情况:

curl http://0.0.0.0:23333/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer EMPTY" \
  -d '{
    "model": "internlm/Intern-S2-Preview",
    "messages": [
      {"role": "user", "content": "Hello"}
    ],
    "temperature": 0.8,
    "top_p": 0.95
  }'

或者您可以使用环境变量配置您的代理框架

export OPENAI_API_KEY=EMPTY
export OPENAI_BASE_URL=http://0.0.0.0:23333/v1
export OPENAI_MODEL=internlm/Intern-S2-Preview

记得使用 --tool-call-parser interns2-preview 启动 LMDeploy,以确保工具调用被正确解析。

连接 Claude Code

LMDeploy 公开了一个与 Anthropic 兼容的 /v1/messages 端点,Claude Code 可以直接与之通信。将以下内容添加到 ~/.claude/settings.json 中:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://127.0.0.1:23333",
    "ANTHROPIC_AUTH_TOKEN": "dummy",
    "ANTHROPIC_MODEL": "internlm/Intern-S2-Preview",
    "ANTHROPIC_CUSTOM_MODEL_OPTION": "internlm/Intern-S2-Preview"
  }
}

如需完整操作指南(包括 curl 验证、模型路由、故障排除),请参见 LMDeploy × Claude Code。

2. 官方 Intern API

如果您不想自行部署,可以使用官方 Intern API。请在 internlm.intern-ai.org.cn 注册并创建 API 令牌(sk-xxxxxxxx)。

连接 Agent 框架

该服务兼容 OpenAI,因此任何 Agent 框架均可使用。您可以在命令行界面或配置文件中将基础 URL 设置为 https://chat.intern-ai.org.cn/api/v1,模型名称设置为 intern-s2-preview。

您可以通过以下命令检查连接情况:

curl https://chat.intern-ai.org.cn/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxx" \
  -d '{
    "model": "intern-s2-preview",
    "messages": [
      {"role": "user", "content": "Hello"}
    ],
    "temperature": 0.8,
    "top_p": 0.95
  }'

有关当前端点、可用模型名称、速率限制和高级参数的信息,请参阅 Intern API 文档。

连接 Claude Code

通过将 ANTHROPIC_BASE_URL 指向 Intern Anthropic 兼容网关,Claude Code 可以路由到官方 Intern API:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://chat.staging.intern-ai.org.cn",
    "ANTHROPIC_AUTH_TOKEN": "your-api-token",
    "ANTHROPIC_MODEL": "intern-s2-preview",
    "ANTHROPIC_SMALL_FAST_MODEL": "intern-s2-preview"
  }
}

然后使用以下命令启动 claude 代码:

claude --model intern-s2-preview

如需分步设置,请参见 Intern API × Claude Code Integration。