Views
No views yet
| Model | Parameters | Context Length | CoT Support | Best For |
|---|---|---|---|---|
| Qianfan-VL-3B | 3B | 32k | ❌ | Edge deployment, real-time OCR |
| Qianfan-VL-8B | 8B | 32k | ✅ | Server-side general scenarios, fine-tuning |
| Qianfan-VL-70B | 70B | 32k | ✅ | Complex reasoning, data synthesis |
| Benchmark | Qianfan-VL-3B | Qianfan-VL-8B | Qianfan-VL-70B | InternVL-3-8B | InternVL-3-78B | Qwen2.5-VL-7B | Qwen2.5-VL-72B |
|---|---|---|---|---|---|---|---|
| A-Bench_VAL | 75.65 | 75.72 | 78.1 | 75.86 | 75.86 | 76.49 | 79.22 |
| CCBench | 66.86 | 70.39 | 80.98 | 77.84 | 70.78 | 57.65 | 73.73 |
| SEEDBench_IMG | 76.55 | 78.02 | 79.13 | 77.0 | 77.52 | 76.98 | 78.34 |
| ScienceQA_TEST | 95.19 | 97.62 | 98.76 | 97.97 | 97.17 | 85.47 | 92.51 |
pip install transformers accelerate torch torchvision pillow einops 1import torch
2import torchvision.transforms as T
3from torchvision.transforms.functional import InterpolationMode
4from transformers import AutoModel, AutoTokenizer
5from PIL import Image
6
7IMAGENET_MEAN = (0.485, 0.456, 0.406)
8IMAGENET_STD = (0.229, 0.224, 0.225)
9
10def build_transform(input_size):
11 MEAN, STD = IMAGENET_MEAN, IMAGENET_STD
12 transform = T.Compose([
13 T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),
14 T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),
15 T.ToTensor(),
16 T.Normalize(mean=MEAN, std=STD)
17 ])
18 return transform
19
20def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
21 best_ratio_diff = float('inf')
22 best_ratio = (1, 1)
23 area = width * height
24 for ratio in target_ratios:
25 target_aspect_ratio = ratio[0] / ratio[1]
26 ratio_diff = abs(aspect_ratio - target_aspect_ratio)
27 if ratio_diff < best_ratio_diff:
28 best_ratio_diff = ratio_diff
29 best_ratio = ratio
30 elif ratio_diff == best_ratio_diff:
31 if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:
32 best_ratio = ratio
33 return best_ratio
34
35def dynamic_preprocess(image, min_num=1, max_num=12, image_size=448, use_thumbnail=False):
36 orig_width, orig_height = image.size
37 aspect_ratio = orig_width / orig_height
38
39 target_ratios = set(
40 (i, j) for n in range(min_num, max_num + 1) for i in range(1, n + 1) for j in range(1, n + 1) if
41 i * j <= max_num and i * j >= min_num)
42 target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])
43
44 target_aspect_ratio = find_closest_aspect_ratio(
45 aspect_ratio, target_ratios, orig_width, orig_height, image_size)
46
47 target_width = image_size * target_aspect_ratio[0]
48 target_height = image_size * target_aspect_ratio[1]
49 blocks = target_aspect_ratio[0] * target_aspect_ratio[1]
50
51 resized_img = image.resize((target_width, target_height))
52 processed_images = []
53 for i in range(blocks):
54 box = (
55 (i % (target_width // image_size)) * image_size,
56 (i // (target_width // image_size)) * image_size,
57 ((i % (target_width // image_size)) + 1) * image_size,
58 ((i // (target_width // image_size)) + 1) * image_size
59 )
60 split_img = resized_img.crop(box)
61 processed_images.append(split_img)
62 if use_thumbnail and len(processed_images) != 1:
63 thumbnail_img = image.resize((image_size, image_size))
64 processed_images.append(thumbnail_img)
65 return processed_images
66
67def load_image(image_file, input_size=448, max_num=12):
68 image = Image.open(image_file).convert('RGB')
69 transform = build_transform(input_size=input_size)
70 images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)
71 pixel_values = [transform(image) for image in images]
72 pixel_values = torch.stack(pixel_values)
73 return pixel_values
74
75# Load model
76MODEL_PATH = "baidu/Qianfan-VL-8B" # or Qianfan-VL-3B, Qianfan-VL-70B
77model = AutoModel.from_pretrained(
78 MODEL_PATH,
79 torch_dtype=torch.bfloat16,
80 trust_remote_code=True,
81 device_map="auto"
82).eval()
83tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, trust_remote_code=True)
84
85# Load and process image
86pixel_values = load_image("./example/scene_ocr.png").to(torch.bfloat16)
87
88# Inference
89prompt = "<image>请识别图中所有文字"
90with torch.no_grad():
91 response = model.chat(
92 tokenizer,
93 pixel_values=pixel_values,
94 question=prompt,
95 generation_config={"max_new_tokens": 512},
96 verbose=False
97 )
98print(response)1@article{dong2026qianfan,
2 title={Qianfan-OCR: A Unified End-to-End Model for Document Intelligence},
3 author={Dong, Daxiang and Zheng, Mingming and Xu, Dong and Luo, Chunhua and Zhuang, Bairong and Li, Yuxuan and He, Ruoyun and Wang, Haoran and Zhang, Wenyu and Wang, Wenbo and others},
4 journal={arXiv preprint arXiv:2603.13398},
5 year={2026}
6}
7
8@misc{qianfan-vl-2025,
9 title={Qianfan-VL: Domain-Enhanced Universal Vision-Language Models},
10 author={Qianfan Team},
11 year={2025},
12 publisher={Baidu}
13}