1# default: greedy, thinking disabled
2python inference.py --image path/to/image.jpg --no-thinking --max-new-tokens 1024
3
4# with sampling + thinking mode
5python inference.py --image path/to/image.jpg --thinking --do-sample \
6 --temperature 0.6 --top-p 0.8 --top-k 20 --max-new-tokens 2048
1import torch
2from transformers import AutoProcessor, AutoTokenizer, AutoModelForImageTextToText
3from qwen_vl_utils import process_vision_info
4
5MODEL = "vankey/DocShield-9B"
6
7tokenizer = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True)
8processor = AutoProcessor.from_pretrained(MODEL, trust_remote_code=True)
9model = AutoModelForImageTextToText.from_pretrained(
10 MODEL, torch_dtype=torch.bfloat16, trust_remote_code=True, device_map="auto"
11)
12model.eval()
13
14SYSTEM_PROMPT = (
15 "你是一个图像鉴伪专家,擅长结合视觉,文字结合伪造特征分析手段鉴别输入图像的真假。"
16 "分析过程中,你会逐步分析,抽丝剥茧,找到图像伪造的蛛丝马迹,最终给出专业的鉴别结果及分析。"
17)
18USER_PROMPT = "请分析这张文档图片是否存在伪造或篡改风险,并输出一份专业、精炼、准确的防伪分析报告。"
19
20messages = [
21 {"role": "system", "content": [{"type": "text", "text": SYSTEM_PROMPT}]},
22 {"role": "user", "content": [
23 {"type": "image", "image": "image.jpg"},
24 {"type": "text", "text": USER_PROMPT},
25 ]},
26]
27
28text = processor.apply_chat_template(messages, tokenize=False,
29 add_generation_prompt=True, enable_thinking=False)
30image_inputs, video_inputs = process_vision_info(messages)
31inputs = processor(text=[text], images=image_inputs, videos=video_inputs,
32 padding=True, return_tensors="pt").to(model.device)
33
34with torch.no_grad():
35 out = model.generate(**inputs, max_new_tokens=1024, do_sample=False)
36
37gen = [o[len(i):] for i, o in zip(inputs["input_ids"], out)]
38print(processor.batch_decode(gen, skip_special_tokens=False)[0])
1@article{docshield2026,
2 title={DocShield: A Forensic Vision-Language Model for Document Forgery Analysis},
3 author={DocShield},
4 year={2026},
5 url={https://arxiv.org/abs/2604.02694}
6}
Apache-2.0.