1python>=3.10
2torch==2.8.0
3torchvision==0.23.0
4transformers==4.57.3
5diffusers==0.36.0
6accelerate==1.12.0
7deepspeed==0.17.0
1dtype = bfloat16
2attn_implementation = sdpa
3block_size = 4
4denoising_steps = 4
1import torch
2from transformers import AutoProcessor
3
4from qwen_vl_utils import process_vision_info
5from nemo_automodel.components.models.bard_vl import BardVLForConditionalGeneration
6
7model_id = "fudan-generative-ai/Bard-VL-B4-Mask-4B-Instruct"
8device = "cuda" if torch.cuda.is_available() else "cpu"
9
10model = BardVLForConditionalGeneration.from_pretrained(
11 model_id,
12 dtype=torch.bfloat16,
13 _attn_implementation="sdpa",
14).to(device).eval()
15processor = AutoProcessor.from_pretrained(model_id)
16
17messages = [
18 {
19 "role": "system",
20 "content": "You are a helpful assistant.",
21 },
22 {
23 "role": "user",
24 "content": [
25 {"type": "image", "image": "assets/puzzle.jpg", "min_pixels": 256 * 256, "max_pixels": 2048 * 2048},
26 {"type": "text", "text": "Please describe this image."},
27 ],
28 },
29]
30
31text = processor.apply_chat_template(
32 messages,
33 tokenize=False,
34 add_generation_prompt=True,
35)
36
37image_inputs, video_inputs, video_kwargs = process_vision_info(
38 messages,
39 return_video_kwargs=True,
40 return_video_metadata=False,
41 image_patch_size=processor.image_processor.patch_size,
42)
43
44batch = processor(
45 text=[text],
46 images=image_inputs,
47 videos=video_inputs,
48 padding=False,
49 return_tensors="pt",
50 **video_kwargs,
51).to(device)
52
53response_ids = model.generate(
54 batch,
55 max_new_tokens=1024,
56 block_size=4,
57 denoising_steps=4,
58 temperature=0.0,
59 top_k=0,
60 top_p=1.0,
61 remasking_strategy="low_confidence_dynamic",
62 confidence_threshold=0.5,
63 return_step_stats=False,
64)
65
66print(processor.tokenizer.batch_decode(response_ids, skip_special_tokens=True)[0].strip())
1@article{chen2026bard,
2 title={BARD: Bridging AutoRegressive and Diffusion Vision-Language Models Via Highly Efficient Progressive Block Merging and Stage-Wise Distillation},
3 author={Baoyou Chen and Hanchen Xia and Peng Tu and Haojun Shi and Liwei Zhang and Weihao Yuan and Siyu Zhu},
4 journal={arXiv preprint arXiv:2604.16514},
5 year={2026}
6}