Instructions to use internlm/Intern-S2-Preview-397B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use internlm/Intern-S2-Preview-397B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="internlm/Intern-S2-Preview-397B", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoModelForImageTextToText model = AutoModelForImageTextToText.from_pretrained("internlm/Intern-S2-Preview-397B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use internlm/Intern-S2-Preview-397B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "internlm/Intern-S2-Preview-397B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/Intern-S2-Preview-397B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/internlm/Intern-S2-Preview-397B
- SGLang
How to use internlm/Intern-S2-Preview-397B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "internlm/Intern-S2-Preview-397B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/Intern-S2-Preview-397B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "internlm/Intern-S2-Preview-397B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "internlm/Intern-S2-Preview-397B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use internlm/Intern-S2-Preview-397B with Docker Model Runner:
docker model run hf.co/internlm/Intern-S2-Preview-397B
File size: 20,341 Bytes
eee12e7 dfd4935 eee12e7 dfd4935 eee12e7 dfd4935 35eba5f dfd4935 fe1086b dfd4935 7ccb1db dfd4935 7ccb1db dfd4935 a9647c0 dfd4935 a9647c0 dfd4935 a9647c0 dfd4935 573135c dfd4935 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | ---
library_name: transformers
license: apache-2.0
license_link: https://huggingface.co/internlm/Intern-S2-Preview-397B/blob/main/LICENSE
pipeline_tag: image-text-to-text
---
## Intern-S2-Preview-397B
<div align="center">
<img src="./figs/title.png" />
<div> </div>
[💻Github Repo](https://github.com/InternLM/Intern-S1) • [🤗HF Model Collections](https://huggingface.co/collections/internlm/intern-s2) • [🤖ModelScope Collections](https://modelscope.cn/collections/Shanghai_AI_Laboratory/intern-s2) • [💬Online Chat](https://chat.intern-ai.org.cn/)
</div>
<p align="center">
👋 join us on <a href="https://discord.gg/xa29JuW87d" target="_blank">Discord</a> and <a href="https://cdn.vansin.top/intern-s1.jpg" target="_blank">WeChat</a>
</p>
## Introduction
We introduce **Intern-S2-Preview-397B**, our most capable multimodal foundation model for scientific intelligence and long-horizon agents. Intern-S2-Preview-397B scales along three critical dimensions: pre-training, reinforcement-learning task coverage, and interactive agent environments. By combining a new vision-language pre-training paradigm with large-scale multi-task reinforcement learning and long-horizon agent reinforcement learning, Intern-S2-Preview-397B delivers a step change in general reasoning, scientific problem solving, and agentic capabilities.
### Features
- **New Pre-training Paradigm.** Via visual pretraining, Intern-S2-Preview-397B learns directly from raw pages of scientific literature, jointly modeling symbolic semantics and visual relationships in a shared representation space without intermediate parsing. This preserves text-visual correspondence, strengthens spatial and visual reasoning, and improves data efficiency.
- **Scientific Modality Reasoning and Generation.** By scaling diverse scientific reinforcement-learning tasks across more than 20 domains and training them jointly, Intern-S2-Preview-397B achieves leading general-reasoning performance among open-source models and strong results in specialized scientific tasks such as biomolecular interaction design and material structure generation.
- **General & Scientific Long-Horizon Agents.** By connecting multiple agent frameworks to large-scale sandboxed environments for black-box agentic reinforcement learning, Intern-S2-Preview-397B improves generalization and raises the capability ceiling for long-horizon tasks in both general and scientific domains.
### Performance
We evaluate the Intern-S2-Preview-397B on various benchmarks, including general datasets and scientific datasets. We report the performance comparison with the recent VLMs and LLMs below.


> **Note**: <u>Underline</u> means the best performance among open-sourced models, **Bold** indicates the best performance among all models.
We use the [OpenCompass](https://github.com/open-compass/OpenCompass/), [VLMEvalKit](https://github.com/open-compass/vlmevalkit), and [AgentCompass](https://github.com/open-compass/AgentCompass) to evaluate all models. For text reasoning benchmarks, Intern-S2-Preview-397B is evaluated with a maximum inference length of 256K tokens, while for multimodal benchmarks, it is evaluated with a maximum inference length of 64K tokens.
## Quick Start
### Sampling Parameters
We recommend using the following hyperparameters to ensure better results
```python
top_p = 0.95
top_k = 50
min_p = 0.0
temperature = 0.8
```
### Serving
Intern-S2-Preview-397B can be deployed using any of the following LLM inference frameworks:
- LMDeploy
- vLLM
- SGLang
Detailed deployment examples for these frameworks are available in the [Model Deployment Guide](./deployment_guide.md).
## Advanced Usage
### Tool Calling
Tool Calling lets the model extend its capabilities by invoking external tools and APIs. The example below shows how to use it to fetch the latest weather forecast via an OpenAI-compatible API (based on lmdeploy api server).
```python
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)
```
### Switching Between Thinking and Non-Thinking Modes
Intern-S2-Preview-397B enables thinking mode by default, enhancing the model's reasoning capabilities to generate higher-quality responses. This feature can be disabled by setting `enable_thinking=False` in `tokenizer.apply_chat_template`
```python
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=False # think mode indicator
)
```
When serving Intern-S2-Preview-397B models, you can dynamically control the thinking mode by adjusting the `enable_thinking` parameter in your requests.
```python
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))
```
> Note: We do not recommend disabling thinking mode for agentic tasks.
### Time Series Demo
Time series inference is currently only supported in LMDeploy. To get started, download and deploy Intern-S2-Preview-397B with LMDeploy by following the [Model Deployment Guide](./deployment_guide.md).
Below is an example of detecting earthquake events from a time series signal file. Additional data types and functionalities are also supported.
**Please note**: in the message content, the order of time_series_url and the text prompt can be arbitrary.
```
from openai import OpenAI
from lmdeploy.vl.utils import encode_time_series_base64
openai_api_key = "EMPTY"
openai_api_base = "http://0.0.0.0:8000/v1"
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
model_name = client.models.list().data[0].id
def send_base64(file_path: str, sampling_rate: int = 100):
"""base64-encoded time-series data."""
# encode_time_series_base64 accepts local file paths and http urls,
# encoding time-series data (.npy, .csv, .wav, .mp3, .flac, etc.) into base64 strings.
base64_ts = encode_time_series_base64(file_path)
messages = [
{
"role": "user",
"content": [
{
"type": "time_series_url",
"time_series_url": {
"url": f"data:time_series/npy;base64,{base64_ts}",
"sampling_rate": sampling_rate
},
},
{
"type": "text",
"text": "Please determine whether an Earthquake event has occurred in the provided time-series data. If so, please specify the starting time point indices of the P-wave and S-wave in the event."
},
],
}
]
return client.chat.completions.create(
model=model_name,
messages=messages,
temperature=0,
max_tokens=200,
extra_body={
"chat_template_kwargs": {"enable_thinking": False}
}
)
def send_http_url(url: str, sampling_rate: int = 100):
"""http(s) url pointing to the time-series data."""
messages = [
{
"role": "user",
"content": [
{
"type": "time_series_url",
"time_series_url": {
"url": url,
"sampling_rate": sampling_rate
},
},
{
"type": "text",
"text": "Please determine whether an Earthquake event has occurred in the provided time-series data. If so, please specify the starting time point indices of the P-wave and S-wave in the event."
},
],
}
]
return client.chat.completions.create(
model=model_name,
messages=messages,
temperature=0,
max_tokens=200,
extra_body={
"chat_template_kwargs": {"enable_thinking": False}
}
)
def send_file_url(file_path: str, sampling_rate: int = 100):
"""file url pointing to the time-series data."""
messages = [
{
"role": "user",
"content": [
{
"type": "time_series_url",
"time_series_url": {
"url": f"file://{file_path}",
"sampling_rate": sampling_rate
},
},
{
"type": "text",
"text": "Please determine whether an Earthquake event has occurred in the provided time-series data. If so, please specify the starting time point indices of the P-wave and S-wave in the event."
},
],
}
]
return client.chat.completions.create(
model=model_name,
messages=messages,
temperature=0,
max_tokens=200,
extra_body={
"chat_template_kwargs": {"enable_thinking": False}
}
)
response = send_base64("./0092638_seism.npy")
# response = send_http_url("https://huggingface.co/internlm/Intern-S1-Pro/raw/main/0092638_seism.npy")
# response = send_file_url("./0092638_seism.npy")
print(response.choices[0].message)
```
For time series forecasting, `forecast_horizon` is optional. Set it to an integer to produce a forecast of exactly that length, or set it to `None` to let the model infer the horizon from the text prompt.
```
def forecast_base64(file_path: str, forecast_horizon: int | None = None):
base64_ts = encode_time_series_base64(file_path)
messages = [
{
"role": "user",
"content": [
{
"type": "text",
"text": (
"Please complete a electric load forecasting task. "
"This dataset is based on historical electricity load data every half hour within 24 hours of the region, "
"as well as data on minimum temperature, maximum temperature, humidity, air pressure, etc., "
"to predict future load consumption every half hour within 24 hours. Here is the weather information for city TAS: "
"Historical date weather: minimum temperature of 279.71K, maximum temperature of 285.83K, humidity of 85.0%, "
"air pressure of 1003.0hPa. Forecast date weather: minimum temperature 280.54K, maximum temperature 286.47K, "
"humidity 74.0%, air pressure 1007.0hPa. This data has no relevant effect information. "
"Please predict the next 48 time points given information above."
),
},
{
"type": "time_series_url",
"time_series_url": {
"url": f"data:time_series/npy;base64,{base64_ts}",
},
},
],
}
]
return client.chat.completions.create(
model=model_name,
messages=messages,
temperature=0,
max_tokens=16,
extra_body={
"chat_template_kwargs": {"enable_thinking": False},
"enable_forecasting": True,
"forecast_horizon": forecast_horizon,
},
)
response = forecast_base64("./load_20210803_0.npy", forecast_horizon=None)
forecast = response.choices[0].message.ts_forecast
print("Point forecast:", forecast.point_forecast)
print("Quantile forecast:", forecast.quantile_forecast)
```
## Agent Integration
Intern-S2-Preview-397B can be plugged into agent frameworks in two ways: connecting to a **self-hosted deployment**, or calling the **official InternLM API**. Below we cover both, with examples for agent frameworks (OpenClaw, Hermes, etc.) and for Claude Code.
### 1. Self-hosted Deployment (LMDeploy as an example)
First, serve the model with LMDeploy following the [Model Deployment Guide](./deployment_guide.md). The example below assumes the server is running at `http://0.0.0.0:23333`.
#### Connecting Agent Frameworks
Most agent frameworks (OpenClaw, Hermes, etc.) accept an OpenAI-compatible endpoint. Point them at the LMDeploy server base url `http://0.0.0.0:23333/v1`.
You can check the connection with the following command:
```bash
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-397B",
"messages": [
{"role": "user", "content": "Hello"}
],
"temperature": 0.8,
"top_p": 0.95
}'
```
Or you can configure your agent framework with the environment variables
```bash
export OPENAI_API_KEY=EMPTY
export OPENAI_BASE_URL=http://0.0.0.0:23333/v1
export OPENAI_MODEL=internlm/Intern-S2-Preview-397B
```
Remember to launch LMDeploy with `--tool-call-parser interns2-preview` so tool calls are parsed correctly.
#### Connecting Claude Code
LMDeploy exposes an Anthropic-compatible `/v1/messages` endpoint that Claude Code can talk to directly. Add the following to `~/.claude/settings.json`:
```json
{
"env": {
"ANTHROPIC_BASE_URL": "http://127.0.0.1:23333",
"ANTHROPIC_AUTH_TOKEN": "dummy",
"ANTHROPIC_MODEL": "internlm/Intern-S2-Preview-397B",
"ANTHROPIC_CUSTOM_MODEL_OPTION": "internlm/Intern-S2-Preview-397B"
}
}
```
For a full walkthrough (curl verification, model routing, troubleshooting), see [LMDeploy × Claude Code](https://lmdeploy.readthedocs.io/en/latest/intergration/claude_code.html).
### 2. Official Intern API
If you do not want to self-host, you can use the official Intern API. Register at [internlm.intern-ai.org.cn](https://internlm.intern-ai.org.cn/) and create an API token (`sk-xxxxxxxx`).
#### Connecting Agent Frameworks
The service is OpenAI-compatible, so any agent framework works. You can set the base url to `https://chat.intern-ai.org.cn/api/v1` and the model name to `intern-s2-preview-397b` in the cli or config file.
You can check the connection with the following command:
```bash
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-397b",
"messages": [
{"role": "user", "content": "Hello"}
],
"temperature": 0.8,
"top_p": 0.95
}'
```
Refer to the [Intern API documentation](https://internlm.intern-ai.org.cn/api/document?lang=en) for the current endpoint, available model names, rate limits, and advanced parameters.
#### Connecting Claude Code
Claude Code can route to the official Intern API by pointing `ANTHROPIC_BASE_URL` at the Intern Anthropic-compatible gateway:
```json
{
"env": {
"ANTHROPIC_BASE_URL": "https://chat.intern-ai.org.cn",
"ANTHROPIC_AUTH_TOKEN": "your-api-token",
"ANTHROPIC_MODEL": "intern-s2-preview-397b",
"ANTHROPIC_SMALL_FAST_MODEL": "intern-s2-preview-397b"
}
}
```
Then start claude code with the following command:
```bash
claude --model intern-s2-preview-397b
```
For step-by-step setup, see [Intern API × Claude Code Integration](https://internlm.intern-ai.org.cn/docEn/docs/Claude-Code-Integration).
|