Views
No views yet
| Model Name | Base Model | Parameters | Download Link |
|---|---|---|---|
| SkyworkVL-2B | OpenGVLab/InternVL2_5-2B | 2B | 🤗 Download |
| SkyworkVL-38B | OpenGVLab/InternVL2_5-38B | 38B | 🤗 Download |
| Metric | MathVista (testmini) | MMMU (val) | AI2D | OCRBench | MME | RealWorldQA | HallusionBench |
|---|---|---|---|---|---|---|---|
| Cambrain-34B | 53.2 | 49.7 | 79.5 | 600 | - | 67.8 | 41.6 |
| Internvl2-40B | 63.7 | 55.2 | 86.6 | 837 | 2307 | 71.8 | 56.9 |
| Internvl2.5-38B | 71.9 | 63.9 | 87.6 | 842 | 2455 | 73.5 | 56.8 |
| SkyworkVL-38B | 74.4 | 64.0 | 88.4 | 854 | 2479 | 76.9 | 58.9 |
SkyworkVL-38B using transformers1import torch
2from transformers import AutoTokenizer, AutoModel
3path = "Skywork/SkyworkVL-38B"
4model = AutoModel.from_pretrained(
5 path,
6 torch_dtype=torch.bfloat16,
7 low_cpu_mem_usage=True,
8 use_flash_attn=True,
9 trust_remote_code=True).eval().cuda()1import math
2import numpy as np
3import torch
4import torchvision.transforms as T
5from decord import VideoReader, cpu
6from PIL import Image
7from torchvision.transforms.functional import InterpolationMode
8from transformers import AutoModel, AutoTokenizer
9
10IMAGENET_MEAN = (0.485, 0.456, 0.406)
11IMAGENET_STD = (0.229, 0.224, 0.225)
12
13def build_transform(input_size):
14 MEAN, STD = IMAGENET_MEAN, IMAGENET_STD
15 transform = T.Compose([
16 T.Lambda(lambda img: img.convert('RGB') if img.mode != 'RGB' else img),
17 T.Resize((input_size, input_size), interpolation=InterpolationMode.BICUBIC),
18 T.ToTensor(),
19 T.Normalize(mean=MEAN, std=STD)
20 ])
21 return transform
22
23def find_closest_aspect_ratio(aspect_ratio, target_ratios, width, height, image_size):
24 best_ratio_diff = float('inf')
25 best_ratio = (1, 1)
26 area = width * height
27 for ratio in target_ratios:
28 target_aspect_ratio = ratio[0] / ratio[1]
29 ratio_diff = abs(aspect_ratio - target_aspect_ratio)
30 if ratio_diff < best_ratio_diff:
31 best_ratio_diff = ratio_diff
32 best_ratio = ratio
33 elif ratio_diff == best_ratio_diff:
34 if area > 0.5 * image_size * image_size * ratio[0] * ratio[1]:
35 best_ratio = ratio
36 return best_ratio
37
38def dynamic_preprocess(image, min_num=1, max_num=12, image_size=448, use_thumbnail=False):
39 orig_width, orig_height = image.size
40 aspect_ratio = orig_width / orig_height
41
42 # calculate the existing image aspect ratio
43 target_ratios = set(
44 (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
45 i * j <= max_num and i * j >= min_num)
46 target_ratios = sorted(target_ratios, key=lambda x: x[0] * x[1])
47
48 # find the closest aspect ratio to the target
49 target_aspect_ratio = find_closest_aspect_ratio(
50 aspect_ratio, target_ratios, orig_width, orig_height, image_size)
51
52 # calculate the target width and height
53 target_width = image_size * target_aspect_ratio[0]
54 target_height = image_size * target_aspect_ratio[1]
55 blocks = target_aspect_ratio[0] * target_aspect_ratio[1]
56
57 # resize the image
58 resized_img = image.resize((target_width, target_height))
59 processed_images = []
60 for i in range(blocks):
61 box = (
62 (i % (target_width // image_size)) * image_size,
63 (i // (target_width // image_size)) * image_size,
64 ((i % (target_width // image_size)) + 1) * image_size,
65 ((i // (target_width // image_size)) + 1) * image_size
66 )
67 # split the image
68 split_img = resized_img.crop(box)
69 processed_images.append(split_img)
70 assert len(processed_images) == blocks
71 if use_thumbnail and len(processed_images) != 1:
72 thumbnail_img = image.resize((image_size, image_size))
73 processed_images.append(thumbnail_img)
74 return processed_images
75
76def load_image(image_file, input_size=448, max_num=12):
77 image = Image.open(image_file).convert('RGB')
78 transform = build_transform(input_size=input_size)
79 images = dynamic_preprocess(image, image_size=input_size, use_thumbnail=True, max_num=max_num)
80 pixel_values = [transform(image) for image in images]
81 pixel_values = torch.stack(pixel_values)
82 return pixel_values
83
84def split_model(model_name):
85 device_map = {}
86 world_size = torch.cuda.device_count()
87 num_layers = {
88 'SkyworkVL-2B': 24, 'SkyworkVL-38B': 64}[model_name]
89 num_layers_per_gpu = math.ceil(num_layers / (world_size - 0.5))
90 num_layers_per_gpu = [num_layers_per_gpu] * world_size
91 num_layers_per_gpu[0] = math.ceil(num_layers_per_gpu[0] * 0.5)
92 layer_cnt = 0
93 for i, num_layer in enumerate(num_layers_per_gpu):
94 for j in range(num_layer):
95 device_map[f'language_model.model.layers.{layer_cnt}'] = i
96 layer_cnt += 1
97 device_map['vision_model'] = 0
98 device_map['mlp1'] = 0
99 device_map['language_model.model.tok_embeddings'] = 0
100 device_map['language_model.model.embed_tokens'] = 0
101 device_map['language_model.output'] = 0
102 device_map['language_model.model.norm'] = 0
103 device_map['language_model.model.rotary_emb'] = 0
104 device_map['language_model.lm_head'] = 0
105 device_map[f'language_model.model.layers.{num_layers - 1}'] = 0
106
107 return device_map
108
109path = 'Skywork/SkyworkVL-38B'
110device_map = split_model('SkyworkVL-38B')
111model = AutoModel.from_pretrained(
112 path,
113 torch_dtype=torch.bfloat16,
114 load_in_8bit=True,
115 low_cpu_mem_usage=True,
116 use_flash_attn=True,
117 trust_remote_code=True,
118 device_map=device_map).eval()
119tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True, use_fast=False)
120
121# set the max number of tiles in `max_num`
122pixel_values = load_image('./demo/image1.jpg', max_num=12).to(torch.bfloat16).cuda()
123generation_config = dict(max_new_tokens=1024, do_sample=True)
124
125# pure-text conversation (纯文本对话)
126question = 'Hi, what can you do?'
127response, history = model.chat(tokenizer, None, question, generation_config, history=None, return_history=True)
128print(f'User: {question}\nAssistant: {response}')
129
130question = 'Can you explain quantum mechanics to me?'
131response, history = model.chat(tokenizer, None, question, generation_config, history=history, return_history=True)
132print(f'User: {question}\nAssistant: {response}')
133
134# image-text conversation (图文对话)
135question = '<image>\nWhat do you see in this image?'
136response = model.chat(tokenizer, pixel_values, question, generation_config)
137print(f'User: {question}\nAssistant: {response}')
1381@misc{SkyworkVL,
2 author = {Jiangbo Pei and Peiyu Wang and Yichen Wei and Xiaokun Wang and Yi Peng and Weijie Qiu and Ai Jian and Yunzhuo Hao and Jiachun Pan and Tianyidan Xie and Li Ge and Rongxian Zhuang and Xuchen Song and Yang Liu and Yahui Zhou},
3 title = {SkyworkVL: Multimodal Understanding with Bag of Tricks},
4 year = {2025},
5 publisher = {Huggingface},
6 journal = {Huggingface repository},
7 howpublished = {\url{https://huggingface.co/Skywork/SkyworkVL-38B}}
8}