kaivoss's picture
Thinking with images: SFT on Qwen3.6 image reasoning traces; full merged checkpoint servable with Akicou/sglang@clover-vl
56a465e verified
Raw History Blame Contribute Delete
1.1 kB
"""Ask Clover-Preview-VL about an image (Hugging Face path; slow). python run.py photo.jpg "What is shown?" [--no-think]"""
import sys
import torch
from huggingface_hub import snapshot_download
from PIL import Image
from transformers import AutoTokenizer
from clover_sft.model import CloverForSFT
from clover_vl import load_processor, load_vision, vl_generate
here = snapshot_download("kaivoss/Clover-Preview-VL")
tok = AutoTokenizer.from_pretrained(here)
lm = CloverForSFT.from_pretrained(here, dtype=torch.bfloat16, device_map="cuda").eval()
vision = load_vision("cuda", path=here).eval()
args = [a for a in sys.argv[1:] if a != "--no-think"]
image = Image.open(args[0])
question = args[1] if len(args) > 1 else "Describe this image in detail."
if "--no-think" in sys.argv:
print(vl_generate(lm, vision, tok, load_processor(), image, question, max_new_tokens=512))
else:
reasoning, answer, _ = vl_generate(lm, vision, tok, load_processor(), image, question, think=True,
max_new_tokens=2048)
print(f"<think>\n{reasoning}\n</think>\n\n{answer}")