Views
No views yet

1# Or execute the following code
2import requests
3from PIL import Image
4import torch
5from transformers import AutoProcessor, AutoTokenizer
6from vargpt_qwen_v1_1.modeling_vargpt_qwen2_vl import VARGPTQwen2VLForConditionalGeneration
7from vargpt_qwen_v1_1.prepare_vargpt_v1_1 import prepare_vargpt_qwen2vl_v1_1
8from vargpt_qwen_v1_1.processing_vargpt_qwen2_vl import VARGPTQwen2VLProcessor
9from patching_utils.patching import patching
10
11model_id = "VARGPT-family/VARGPT-v1.1"
12
13prepare_vargpt_qwen2vl_v1_1(model_id)
14
15model = VARGPTQwen2VLForConditionalGeneration.from_pretrained(
16 model_id,
17 torch_dtype=torch.float32,
18 low_cpu_mem_usage=True,
19).to(0)
20
21patching(model)
22
23tokenizer = AutoTokenizer.from_pretrained(model_id)
24processor = VARGPTQwen2VLProcessor.from_pretrained(model_id)
25
26# Define a chat history and use `apply_chat_template` to get correctly formatted prompt
27# Each value in "content" has to be a list of dicts with types ("text", "image")
28conversation = [
29 {
30 "role": "user",
31 "content": [
32 {"type": "text", "text": "Please explain the meme in detail."},
33 {"type": "image"},
34 ],
35 },
36]
37prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
38image_file = "./assets/llava_bench_demo.png"
39print(prompt)
40
41raw_image = Image.open(image_file)
42inputs = processor(images=[raw_image], text=prompt, return_tensors='pt').to(0, torch.float32)
43
44output = model.generate(
45 **inputs,
46 max_new_tokens=2048,
47 do_sample=False)
48
49print(processor.decode(output[0], skip_special_tokens=True))
50
511import requests
2from PIL import Image
3import torch
4from transformers import AutoProcessor, AutoTokenizer
5from vargpt_qwen_v1_1.modeling_vargpt_qwen2_vl import VARGPTQwen2VLForConditionalGeneration
6from vargpt_qwen_v1_1.prepare_vargpt_v1_1 import prepare_vargpt_qwen2vl_v1_1
7from vargpt_qwen_v1_1.processing_vargpt_qwen2_vl import VARGPTQwen2VLProcessor
8from patching_utils.patching import patching
9model_id = "VARGPT-family/VARGPT-v1.1"
10
11prepare_vargpt_qwen2vl_v1_1(model_id)
12
13model = VARGPTQwen2VLForConditionalGeneration.from_pretrained(
14 model_id,
15 torch_dtype=torch.float32,
16 low_cpu_mem_usage=True,
17).to(0)
18
19patching(model)
20tokenizer = AutoTokenizer.from_pretrained(model_id)
21processor = VARGPTQwen2VLProcessor.from_pretrained(model_id)
22
23conversation = [
24 {
25 "role": "user",
26 "content": [
27 {"type": "text", "text": "Can you depict a scene of A power metalalbum cover featuring a fantasy-style illustration witha white falcon."},
28 ],
29 },
30]
31prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
32print(prompt)
33
34inputs = processor(text=prompt, return_tensors='pt').to(0, torch.float32)
35model._IMAGE_GEN_PATH = "output.png"
36output = model.generate(
37 **inputs,
38 max_new_tokens=4096,
39 do_sample=False)
40
41print(processor.decode(output[0][:-1], skip_special_tokens=True))
42
43@misc{zhuang2025vargptunifiedunderstandinggeneration,
title={VARGPT: Unified Understanding and Generation in a Visual Autoregressive Multimodal Large Language Model},
author={Xianwei Zhuang and Yuxin Xie and Yufan Deng and Liming Liang and Jinghan Ru and Yuguo Yin and Yuexian Zou},
year={2025},
eprint={2501.12327},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2501.12327},
}
@misc{zhuang2025vargptv11improvevisualautoregressive,
title={VARGPT-v1.1: Improve Visual Autoregressive Large Unified Model via Iterative Instruction Tuning and Reinforcement Learning},
author={Xianwei Zhuang and Yuxin Xie and Yufan Deng and Dongchao Yang and Liming Liang and Jinghan Ru and Yuguo Yin and Yuexian Zou},
year={2025},
eprint={2504.02949},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2504.02949},
}