Views
No views yet


thinking or non-thinking capabilities, enabling you to make your choices for every job.[!NOTE] Users can dynamically control the model's response by selecting one of three modes (auto-thinking,thinking, ornon-thinking) withthinking_mode.thinking_mode=autoforauto-thinkingmode;thinking_mode=longforthinkingmode;thinking_mode=shortfornon-thinkingmode. Default isauto-thinking.
1import requests
2from PIL import Image
3import torch
4from transformers import AutoModel, AutoProcessor
5
6model_path = "YannQi/R-4B"
7
8# Load model
9model = AutoModel.from_pretrained(
10 model_path,
11 torch_dtype=torch.float32,
12 trust_remote_code=True,
13).to("cuda")
14
15# Load processor
16processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)
17
18# Define conversation messages
19messages = [
20 {
21 "role": "user",
22 "content": [
23 {
24 "type": "image",
25 "image": "http://images.cocodataset.org/val2017/000000039769.jpg",
26 },
27 {"type": "text", "text": "Describe this image."},
28 ],
29 }
30]
31
32# Apply chat template
33text = processor.apply_chat_template(
34 messages,
35 tokenize=False,
36 add_generation_prompt=True,
37 thinking_mode="auto"
38)
39
40# Load image
41image_url = "http://images.cocodataset.org/val2017/000000039769.jpg"
42image = Image.open(requests.get(image_url, stream=True).raw)
43
44# Process inputs
45inputs = processor(
46 images=image,
47 text=text,
48 return_tensors="pt"
49).to("cuda")
50
51# Generate output
52generated_ids = model.generate(**inputs, max_new_tokens=16384)
53output_ids = generated_ids[0][len(inputs.input_ids[0]):]
54
55# Decode output
56output_text = processor.decode(
57 output_ids,
58 skip_special_tokens=True,
59 clean_up_tokenization_spaces=False
60)
61
62# Print result
63print("Auto-Thinking Output:", output_text)1git clone https://github.com/vllm-project/vllm.git
2cd vllm
3VLLM_USE_PRECOMPILED=1 uv pip install --editable .[!TIP] Thethinking_modeswitch is also available in APIs created by vLLM. Default isauto-thinking.
1vllm serve \
2 yannqi/R-4B \
3 --served-model-name r4b \
4 --tensor-parallel-size 8 \
5 --gpu-memory-utilization 0.8 \
6 --host 0.0.0.0 \
7 --port 8000 \
8 --trust-remote-code1import base64
2from PIL import Image
3from openai import OpenAI
4
5
6# Set OpenAI's API key and API base to use vLLM's API server.
7openai_api_key = "EMPTY"
8openai_api_base = "http://localhost:8000/v1"
9
10client = OpenAI(
11 api_key=openai_api_key,
12 base_url=openai_api_base,
13)
14
15# image url
16image_messages = [
17 {
18 "role": "user",
19 "content": [
20 {
21 "type": "image_url",
22 "image_url": {
23 "url": "http://images.cocodataset.org/val2017/000000039769.jpg"
24 },
25 },
26 {"type": "text", "text": "Describe this image."},
27 ],
28 },
29]
30
31
32
33chat_response = client.chat.completions.create(
34 model="r4b",
35 messages=image_messages,
36 max_tokens=16384,
37 extra_body={
38 "chat_template_kwargs": {"thinking_mode": "auto"},
39 },
40)
41print("Chat response:", chat_response)
@misc{yang2025r4bincentivizinggeneralpurposeautothinking,
title={R-4B: Incentivizing General-Purpose Auto-Thinking Capability in MLLMs via Bi-Mode Annealing and Reinforce Learning},
author={Qi Yang and Bolin Ni and Shiming Xiang and Han Hu and Houwen Peng and Jie Jiang},
year={2025},
eprint={2508.21113},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2508.21113},
}