The Kimi-VL-A3B-Thinking-2506 variant is optimized for multimodal reasoning and supports multi-image inputs.
Key Configuration:
- Temperature: It is recommended to use
Temperature = 0.8 for Thinking models. - Max Tokens: For complex reasoning, you may need a higher
max_new_tokens value (e.g., 32768).
Optimization Tip:
If flash-attn is installed, use torch_dtype=torch.bfloat16 and attn_implementation="flash_attention_2" in from_pretrained to save memory and increase speed.
import torch
from PIL import Image
from transformers import AutoModelForCausalLM, AutoProcessor
model_path = "moonshotai/Kimi-VL-A3B-Thinking-2506"
model = AutoModelForCausalLM.from_pretrained(
model_path,
torch_dtype="auto",
device_map="auto",
trust_remote_code=True,
)
# If flash-attn has been installed, it is recommended to set torch_dtype=torch.bfloat16 and attn_implementation="flash_attention_2"
# model = AutoModelForCausalLM.from_pretrained(
# model_path,
# torch_dtype=torch.bfloat16,
# device_map="auto",
# trust_remote_code=True,
# attn_implementation="flash_attention_2"
# )
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)
image_paths = ["./figures/demo1.png", "./figures/demo2.png"]
images = [Image.open(path) for path in image_paths]
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": image_path} for image_path in image_paths
] + [{"type": "text", "text": "Please infer step by step who this manuscript belongs to and what it records"}],
},
]
text = processor.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
inputs = processor(images=images, text=text, return_tensors="pt", padding=True, truncation=True).to(model.device)
generated_ids = model.generate(**inputs, max_new_tokens=32768, temperature=0.8)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
response = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)[0]
print(response)