littlebird13 commited on
Commit
f9ca7f1
·
verified ·
1 Parent(s): b64a8fd

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
added_tokens.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</think>": 151668,
3
+ "</tool_call>": 151658,
4
+ "</tool_response>": 151666,
5
+ "<think>": 151667,
6
+ "<tool_call>": 151657,
7
+ "<tool_response>": 151665,
8
+ "<|box_end|>": 151649,
9
+ "<|box_start|>": 151648,
10
+ "<|endoftext|>": 151643,
11
+ "<|file_sep|>": 151664,
12
+ "<|fim_middle|>": 151660,
13
+ "<|fim_pad|>": 151662,
14
+ "<|fim_prefix|>": 151659,
15
+ "<|fim_suffix|>": 151661,
16
+ "<|im_end|>": 151645,
17
+ "<|im_start|>": 151644,
18
+ "<|image_pad|>": 151655,
19
+ "<|object_ref_end|>": 151647,
20
+ "<|object_ref_start|>": 151646,
21
+ "<|quad_end|>": 151651,
22
+ "<|quad_start|>": 151650,
23
+ "<|repo_name|>": 151663,
24
+ "<|video_pad|>": 151656,
25
+ "<|vision_end|>": 151653,
26
+ "<|vision_pad|>": 151654,
27
+ "<|vision_start|>": 151652
28
+ }
chat_template.jinja ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0].role == 'system' %}
4
+ {%- if messages[0].content is string %}
5
+ {{- messages[0].content }}
6
+ {%- else %}
7
+ {%- for content in messages[0].content %}
8
+ {%- if 'text' in content %}
9
+ {{- content.text }}
10
+ {%- endif %}
11
+ {%- endfor %}
12
+ {%- endif %}
13
+ {{- '\n\n' }}
14
+ {%- endif %}
15
+ {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
16
+ {%- for tool in tools %}
17
+ {{- "\n" }}
18
+ {{- tool | tojson }}
19
+ {%- endfor %}
20
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
21
+ {%- else %}
22
+ {%- if messages[0].role == 'system' %}
23
+ {{- '<|im_start|>system\n' }}
24
+ {%- if messages[0].content is string %}
25
+ {{- messages[0].content }}
26
+ {%- else %}
27
+ {%- for content in messages[0].content %}
28
+ {%- if 'text' in content %}
29
+ {{- content.text }}
30
+ {%- endif %}
31
+ {%- endfor %}
32
+ {%- endif %}
33
+ {{- '<|im_end|>\n' }}
34
+ {%- endif %}
35
+ {%- endif %}
36
+ {%- set image_count = namespace(value=0) %}
37
+ {%- set video_count = namespace(value=0) %}
38
+ {%- for message in messages %}
39
+ {%- if message.role == "user" %}
40
+ {{- '<|im_start|>' + message.role + '\n' }}
41
+ {%- if message.content is string %}
42
+ {{- message.content }}
43
+ {%- else %}
44
+ {%- for content in message.content %}
45
+ {%- if content.type == 'image' or 'image' in content or 'image_url' in content %}
46
+ {%- set image_count.value = image_count.value + 1 %}
47
+ {%- if add_vision_id %}Picture {{ image_count.value }}: {% endif -%}
48
+ <|vision_start|><|image_pad|><|vision_end|>
49
+ {%- elif content.type == 'video' or 'video' in content %}
50
+ {%- set video_count.value = video_count.value + 1 %}
51
+ {%- if add_vision_id %}Video {{ video_count.value }}: {% endif -%}
52
+ <|vision_start|><|video_pad|><|vision_end|>
53
+ {%- elif 'text' in content %}
54
+ {{- content.text }}
55
+ {%- endif %}
56
+ {%- endfor %}
57
+ {%- endif %}
58
+ {{- '<|im_end|>\n' }}
59
+ {%- elif message.role == "assistant" %}
60
+ {{- '<|im_start|>' + message.role + '\n' }}
61
+ {%- if message.content is string %}
62
+ {{- message.content }}
63
+ {%- else %}
64
+ {%- for content_item in message.content %}
65
+ {%- if 'text' in content_item %}
66
+ {{- content_item.text }}
67
+ {%- endif %}
68
+ {%- endfor %}
69
+ {%- endif %}
70
+ {%- if message.tool_calls %}
71
+ {%- for tool_call in message.tool_calls %}
72
+ {%- if (loop.first and message.content) or (not loop.first) %}
73
+ {{- '\n' }}
74
+ {%- endif %}
75
+ {%- if tool_call.function %}
76
+ {%- set tool_call = tool_call.function %}
77
+ {%- endif %}
78
+ {{- '<tool_call>\n{"name": "' }}
79
+ {{- tool_call.name }}
80
+ {{- '", "arguments": ' }}
81
+ {%- if tool_call.arguments is string %}
82
+ {{- tool_call.arguments }}
83
+ {%- else %}
84
+ {{- tool_call.arguments | tojson }}
85
+ {%- endif %}
86
+ {{- '}\n</tool_call>' }}
87
+ {%- endfor %}
88
+ {%- endif %}
89
+ {{- '<|im_end|>\n' }}
90
+ {%- elif message.role == "tool" %}
91
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
92
+ {{- '<|im_start|>user' }}
93
+ {%- endif %}
94
+ {{- '\n<tool_response>\n' }}
95
+ {%- if message.content is string %}
96
+ {{- message.content }}
97
+ {%- else %}
98
+ {%- for content in message.content %}
99
+ {%- if content.type == 'image' or 'image' in content or 'image_url' in content %}
100
+ {%- set image_count.value = image_count.value + 1 %}
101
+ {%- if add_vision_id %}Picture {{ image_count.value }}: {% endif -%}
102
+ <|vision_start|><|image_pad|><|vision_end|>
103
+ {%- elif content.type == 'video' or 'video' in content %}
104
+ {%- set video_count.value = video_count.value + 1 %}
105
+ {%- if add_vision_id %}Video {{ video_count.value }}: {% endif -%}
106
+ <|vision_start|><|video_pad|><|vision_end|>
107
+ {%- elif 'text' in content %}
108
+ {{- content.text }}
109
+ {%- endif %}
110
+ {%- endfor %}
111
+ {%- endif %}
112
+ {{- '\n</tool_response>' }}
113
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
114
+ {{- '<|im_end|>\n' }}
115
+ {%- endif %}
116
+ {%- endif %}
117
+ {%- endfor %}
118
+ {%- if add_generation_prompt %}
119
+ {{- '<|im_start|>assistant\n' }}
120
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3VLForConditionalGeneration"
4
+ ],
5
+ "dtype": "bfloat16",
6
+ "hidden_size": 2048,
7
+ "image_token_id": 151655,
8
+ "model_type": "qwen3_vl",
9
+ "pad_token_id": 151643,
10
+ "text_config": {
11
+ "attention_bias": false,
12
+ "attention_dropout": 0.0,
13
+ "bos_token_id": 151643,
14
+ "dtype": "float32",
15
+ "eos_token_id": 151645,
16
+ "head_dim": 128,
17
+ "hidden_act": "silu",
18
+ "hidden_size": 2048,
19
+ "initializer_range": 0.02,
20
+ "intermediate_size": 6144,
21
+ "max_position_embeddings": 262144,
22
+ "model_type": "qwen3_vl_text",
23
+ "num_attention_heads": 16,
24
+ "num_hidden_layers": 28,
25
+ "num_key_value_heads": 8,
26
+ "pad_token_id": 151643,
27
+ "rms_norm_eps": 1e-06,
28
+ "rope_scaling": {
29
+ "mrope_interleaved": true,
30
+ "mrope_section": [
31
+ 24,
32
+ 20,
33
+ 20
34
+ ],
35
+ "rope_type": "default"
36
+ },
37
+ "rope_theta": 5000000,
38
+ "tie_word_embeddings": true,
39
+ "use_cache": false,
40
+ "vocab_size": 151936
41
+ },
42
+ "tie_word_embeddings": true,
43
+ "transformers_version": "4.57.0",
44
+ "video_token_id": 151656,
45
+ "vision_config": {
46
+ "deepstack_visual_indexes": [
47
+ 5,
48
+ 11,
49
+ 17
50
+ ],
51
+ "depth": 24,
52
+ "dtype": "float32",
53
+ "hidden_act": "gelu_pytorch_tanh",
54
+ "hidden_size": 1024,
55
+ "in_channels": 3,
56
+ "initializer_range": 0.02,
57
+ "intermediate_size": 4096,
58
+ "model_type": "qwen3_vl",
59
+ "num_heads": 16,
60
+ "num_position_embeddings": 2304,
61
+ "out_hidden_size": 2048,
62
+ "pad_token_id": 151643,
63
+ "patch_size": 16,
64
+ "spatial_merge_size": 2,
65
+ "temporal_patch_size": 2
66
+ },
67
+ "vision_end_token_id": 151653,
68
+ "vision_start_token_id": 151652
69
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "temperature": 0.7,
10
+ "top_k": 20,
11
+ "top_p": 0.8,
12
+ "transformers_version": "4.57.0"
13
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:466ec01961061e9d7f804b4fb1625fb6f406106cd1567e026096d4736fa9d5b9
3
+ size 4255140312
preprocessor_config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "size": {
3
+ "longest_edge": 16777216,
4
+ "shortest_edge": 65536
5
+ },
6
+ "patch_size": 16,
7
+ "temporal_patch_size": 2,
8
+ "image_mean": [
9
+ 0.5,
10
+ 0.5,
11
+ 0.5
12
+ ],
13
+ "image_std": [
14
+ 0.5,
15
+ 0.5,
16
+ 0.5
17
+ ],
18
+ "processor_class": "Qwen3VLProcessor",
19
+ "image_processor_type": "Qwen2VLImageProcessorFast",
20
+ "input_data_format": null,
21
+ "max_pixels": 1310720,
22
+ "merge_size": 2,
23
+ "min_pixels": 4095,
24
+ "pad_size": null,
25
+ "processor_class": "Qwen3VLProcessor",
26
+ "resample": 3,
27
+ "rescale_factor": 0.00392156862745098,
28
+ "return_tensors": null
29
+ }
scripts/qwen3_vl_reranker.py ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import numpy as np
3
+ import logging
4
+
5
+ from PIL import Image
6
+ from scipy import special
7
+ from typing import List
8
+ from qwen_vl_utils import process_vision_info
9
+ from transformers import Qwen3VLForConditionalGeneration, AutoProcessor
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+ IMAGE_BASE_FACTOR = 16
14
+ IMAGE_FACTOR = IMAGE_BASE_FACTOR * 2
15
+ MIN_PIXELS = 4 * IMAGE_FACTOR * IMAGE_FACTOR # 4 tokens
16
+ MAX_PIXELS = 1280 * IMAGE_FACTOR * IMAGE_FACTOR # 1280 tokens
17
+ MAX_RATIO = 200
18
+
19
+ FRAME_FACTOR = 2
20
+ FPS = 1
21
+ MIN_FRAMES = 2
22
+ MAX_FRAMES = 64
23
+ MIN_TOTAL_PIXELS = 1 * FRAME_FACTOR * MIN_PIXELS # 1 frames
24
+ MAX_TOTAL_PIXELS = 4 * FRAME_FACTOR * MAX_PIXELS # 4 frames
25
+
26
+
27
+ def sample_frames(frames, num_segments, max_segments):
28
+ duration = len(frames)
29
+ frame_id_array = np.linspace(0, duration - 1, num_segments, dtype=int)
30
+ frame_id_list = frame_id_array.tolist()
31
+ last_frame_id = frame_id_list[-1]
32
+
33
+ sampled_frames = []
34
+ for frame_idx in frame_id_list:
35
+ try:
36
+ single_frame_path = frames[frame_idx]
37
+ except:
38
+ break
39
+ sampled_frames.append(single_frame_path)
40
+ # If total frame numbers is less than num_segments, append the last images to achieve
41
+ while len(sampled_frames) < num_segments:
42
+ sampled_frames.append(frames[last_frame_id])
43
+ return sampled_frames[:max_segments]
44
+
45
+
46
+
47
+ class Qwen3VLReranker():
48
+ def __init__(
49
+ self,
50
+ model_name_or_path: str,
51
+ **kwargs,
52
+ ):
53
+
54
+ self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
55
+
56
+ self.max_length = kwargs.pop('max_length', 8192)
57
+
58
+ self.default_instruction = "Given a search query, retrieve relevant candidates that answer the query."
59
+
60
+ self.min_pixels = kwargs.pop('min_pixels', MIN_PIXELS)
61
+ self.max_pixels = kwargs.pop('max_pixels', MAX_PIXELS)
62
+ self.total_pixels = kwargs.pop('total_pixels', MAX_TOTAL_PIXELS)
63
+ self.fps = kwargs.pop('fps', FPS)
64
+ self.num_frames = kwargs.pop('num_frames', None)
65
+ self.max_frames = kwargs.pop('max_frames', None)
66
+
67
+
68
+ lm = Qwen3VLForConditionalGeneration.from_pretrained(
69
+ model_name_or_path,
70
+ trust_remote_code=True, **kwargs
71
+ ).to(self.device)
72
+
73
+ self.model = lm.model
74
+
75
+ self.processor = AutoProcessor.from_pretrained(
76
+ model_name_or_path, trust_remote_code=True,
77
+ padding_side='left'
78
+ )
79
+
80
+ token_true_id = self.processor.tokenizer.get_vocab()["yes"]
81
+ token_false_id = self.processor.tokenizer.get_vocab()["no"]
82
+ self.score_linear = self.get_binary_linear(lm, token_true_id, token_false_id)
83
+ self.model.eval()
84
+ self.score_linear.eval()
85
+ self.score_linear.to(self.device).to(self.model.dtype)
86
+
87
+ def get_binary_linear(self, model, token_yes, token_no):
88
+
89
+ lm_head_weights = model.lm_head.weight.data
90
+
91
+ weight_yes = lm_head_weights[token_yes]
92
+ weight_no = lm_head_weights[token_no]
93
+
94
+ D = weight_yes.size()[0]
95
+ linear_layer = torch.nn.Linear(D, 1, bias=False)
96
+ with torch.no_grad():
97
+ linear_layer.weight[0] = weight_yes - weight_no
98
+ return linear_layer
99
+
100
+ @torch.no_grad()
101
+ def compute_scores(self, inputs):
102
+ batch_scores = self.model(**inputs).last_hidden_state[:, -1]
103
+ scores = self.score_linear(batch_scores)
104
+ scores = torch.sigmoid(scores).squeeze(-1).cpu().detach().tolist()
105
+ return scores
106
+
107
+ def truncate_tokens_optimized(
108
+ self,
109
+ tokens: List[str],
110
+ max_length: int,
111
+ special_tokens: List[str]
112
+ ) -> List[str]:
113
+ if len(tokens) <= max_length:
114
+ return tokens
115
+
116
+ special_tokens_set = set(special_tokens)
117
+
118
+ # 1. 确定预算:计算我们能保留多少个非特殊token
119
+ num_special = sum(1 for token in tokens if token in special_tokens_set)
120
+
121
+ # 根据保证(特殊token总数 < max_length),这个值总是非负的
122
+ num_non_special_to_keep = max_length - num_special
123
+
124
+ # 2. 按预算构建最终列表
125
+ final_tokens = []
126
+ non_special_kept_count = 0
127
+ for token in tokens:
128
+ # 如果是特殊token,直接保留
129
+ if token in special_tokens_set:
130
+ final_tokens.append(token)
131
+ # 如果是非特殊token,并且我们还有预算
132
+ elif non_special_kept_count < num_non_special_to_keep:
133
+ final_tokens.append(token)
134
+ non_special_kept_count += 1
135
+ # 如果是非特殊token但预算已用完,则丢弃(即什么都不做)
136
+
137
+ return final_tokens
138
+
139
+ def tokenize(self, pairs: list, **kwargs):
140
+ max_length = self.max_length
141
+ text = self.processor.apply_chat_template(pairs, tokenize=False, add_generation_prompt=True)
142
+ try:
143
+ images, videos, video_kwargs = process_vision_info(
144
+ pairs, image_patch_size=16,
145
+ return_video_kwargs=True, return_video_metadata=True
146
+ )
147
+ except Exception as e:
148
+ logger.warning(f"Error in processing vision info: {e}")
149
+ images = None
150
+ videos = None
151
+ video_kwargs = {'do_sample_frames': False}
152
+ text = self.processor.apply_chat_template(
153
+ [{'role': 'user', 'content': [{'type': 'text', 'text': 'NULL'}]}],
154
+ add_generation_prompt=True, tokenize=False
155
+ )
156
+
157
+ if videos is not None:
158
+ videos, video_metadatas = zip(*videos)
159
+ videos, video_metadatas = list(videos), list(video_metadatas)
160
+ else:
161
+ video_metadatas = None
162
+ inputs = self.processor(text=text,
163
+ images=images,
164
+ videos=videos,
165
+ video_metadata=video_metadatas,
166
+ truncation=False,
167
+ padding=False,
168
+ max_length=max_length,
169
+ do_resize=False,
170
+ **video_kwargs)
171
+ for i, ele in enumerate(inputs['input_ids']):
172
+ inputs['input_ids'][i] = self.truncate_tokens_optimized(inputs['input_ids'][i][:-5], max_length,
173
+ self.processor.tokenizer.all_special_ids) + \
174
+ inputs['input_ids'][i][-5:]
175
+ temp_inputs = self.processor.tokenizer.pad({'input_ids': inputs['input_ids']}, padding=True,
176
+ return_tensors="pt", max_length=self.max_length)
177
+ for key in temp_inputs:
178
+ inputs[key] = temp_inputs[key]
179
+ return inputs
180
+
181
+ def format_mm_content(self, text, image, video, prefix='Query:', fps=None):
182
+ content = []
183
+
184
+ content.append({'type': 'text', 'text': prefix})
185
+ if not text and not image and not video:
186
+ content.append({'type': 'text', 'text': ""})
187
+ return content
188
+ if video:
189
+ video_content = None
190
+ if isinstance(video, list):
191
+ video_content = video
192
+ if self.num_frames is not None or self.max_frames is not None:
193
+ video_content = sample_frames(video_content, self.num_frames, self.max_frames)
194
+ video_content = ['file://' + ele for ele in video_content]
195
+ if video.startswith('http') or video.startswith('oss'):
196
+ video_content = video
197
+ elif isinstance(video, str):
198
+ video_content = 'file://' + video
199
+ if video_content:
200
+ content.append({'type': 'video', 'video': video_content, 'total_pixels': self.total_pixels, 'fps': fps})
201
+
202
+ if image:
203
+ image_content = None
204
+ if isinstance(image, Image.Image):
205
+ image_content = image
206
+
207
+ elif image.startswith('http') or image.startswith('oss'):
208
+ image_content = image
209
+ elif isinstance(image, str):
210
+ image_content = 'file://' + image
211
+ else:
212
+ image_content = image
213
+ if image_content:
214
+ content.append({'type': 'image', 'image': image_content, "min_pixels": self.min_pixels,
215
+ "max_pixels": self.max_pixels})
216
+
217
+ if text:
218
+ content.append({'type': 'text', 'text': text})
219
+ return content
220
+
221
+ def format_mm_instruction(
222
+ self,
223
+ query_text, query_image, query_video,
224
+ doc_text, doc_image, doc_video,
225
+ instruction=None, fps=None
226
+ ):
227
+ inputs = []
228
+ inputs.append({
229
+ "role": "system",
230
+ "content": [{
231
+ "type": "text",
232
+ "text": "Judge whether the Document meets the requirements based on the Query and the Instruct provided. Note that the answer can only be \"yes\" or \"no\"."
233
+ }
234
+ ]
235
+ })
236
+ if isinstance(query_text, tuple):
237
+ instruct, query_text = query_text
238
+ else:
239
+ instruct = instruction
240
+ contents = []
241
+ contents.append({
242
+ "type": "text",
243
+ "text": '<Instruct>: ' + instruct
244
+ })
245
+ query_content = self.format_mm_content(query_text, query_image, query_video, prefix='<Query>:', fps=fps)
246
+ contents.extend(query_content)
247
+ doc_content = self.format_mm_content(doc_text, doc_image, doc_video, prefix='\n<Document>:', fps=fps)
248
+ contents.extend(doc_content)
249
+ inputs.append({
250
+ "role": "user",
251
+ "content": contents
252
+ })
253
+ return inputs
254
+
255
+ def process(
256
+ self,
257
+ inputs,
258
+ ) -> list[torch.Tensor]:
259
+ instruction = inputs.get('instruction', self.default_instruction)
260
+
261
+ query = inputs.get("query", {})
262
+ documents = inputs.get("documents", [])
263
+ if not query or not documents:
264
+ return []
265
+
266
+ pairs = [self.format_mm_instruction(
267
+ query.get('text', None),
268
+ query.get('image', None),
269
+ query.get('video', None),
270
+ document.get('text', None),
271
+ document.get('image', None),
272
+ document.get('video', None),
273
+ instruction=instruction,
274
+ fps=inputs.get('fps', self.fps))
275
+ for document in documents]
276
+ final_scores = []
277
+ for pair in pairs:
278
+ inputs = self.tokenize([pair])
279
+ inputs = inputs.to(self.model.device)
280
+ scores = self.compute_scores(inputs)
281
+ final_scores.extend(scores)
282
+ return final_scores
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|object_ref_start|>",
6
+ "<|object_ref_end|>",
7
+ "<|box_start|>",
8
+ "<|box_end|>",
9
+ "<|quad_start|>",
10
+ "<|quad_end|>",
11
+ "<|vision_start|>",
12
+ "<|vision_end|>",
13
+ "<|vision_pad|>",
14
+ "<|image_pad|>",
15
+ "<|video_pad|>"
16
+ ],
17
+ "eos_token": {
18
+ "content": "<|im_end|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "pad_token": {
25
+ "content": "<|endoftext|>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aeb13307a71acd8fe81861d94ad54ab689df773318809eed3cbe794b4492dae4
3
+ size 11422654
tokenizer_config.json ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "151665": {
182
+ "content": "<tool_response>",
183
+ "lstrip": false,
184
+ "normalized": false,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": false
188
+ },
189
+ "151666": {
190
+ "content": "</tool_response>",
191
+ "lstrip": false,
192
+ "normalized": false,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": false
196
+ },
197
+ "151667": {
198
+ "content": "<think>",
199
+ "lstrip": false,
200
+ "normalized": false,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": false
204
+ },
205
+ "151668": {
206
+ "content": "</think>",
207
+ "lstrip": false,
208
+ "normalized": false,
209
+ "rstrip": false,
210
+ "single_word": false,
211
+ "special": false
212
+ }
213
+ },
214
+ "additional_special_tokens": [
215
+ "<|im_start|>",
216
+ "<|im_end|>",
217
+ "<|object_ref_start|>",
218
+ "<|object_ref_end|>",
219
+ "<|box_start|>",
220
+ "<|box_end|>",
221
+ "<|quad_start|>",
222
+ "<|quad_end|>",
223
+ "<|vision_start|>",
224
+ "<|vision_end|>",
225
+ "<|vision_pad|>",
226
+ "<|image_pad|>",
227
+ "<|video_pad|>"
228
+ ],
229
+ "bos_token": null,
230
+ "clean_up_tokenization_spaces": false,
231
+ "eos_token": "<|im_end|>",
232
+ "errors": "replace",
233
+ "extra_special_tokens": {},
234
+ "model_max_length": 262144,
235
+ "pad_token": "<|endoftext|>",
236
+ "processor_class": "Qwen3VLProcessor",
237
+ "split_special_tokens": false,
238
+ "tokenizer_class": "Qwen2Tokenizer",
239
+ "unk_token": null
240
+ }
video_preprocessor_config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop_size": null,
3
+ "data_format": "channels_first",
4
+ "default_to_square": true,
5
+ "device": null,
6
+ "do_center_crop": null,
7
+ "do_convert_rgb": true,
8
+ "do_normalize": true,
9
+ "do_rescale": true,
10
+ "do_resize": true,
11
+ "do_sample_frames": true,
12
+ "fps": 2,
13
+ "image_mean": [
14
+ 0.5,
15
+ 0.5,
16
+ 0.5
17
+ ],
18
+ "image_std": [
19
+ 0.5,
20
+ 0.5,
21
+ 0.5
22
+ ],
23
+ "input_data_format": null,
24
+ "max_frames": 768,
25
+ "merge_size": 2,
26
+ "min_frames": 4,
27
+ "num_frames": null,
28
+ "pad_size": null,
29
+ "patch_size": 16,
30
+ "processor_class": "Qwen3VLProcessor",
31
+ "resample": 3,
32
+ "rescale_factor": 0.00392156862745098,
33
+ "return_metadata": false,
34
+ "size": {
35
+ "longest_edge": 25165824,
36
+ "shortest_edge": 4096
37
+ },
38
+ "temporal_patch_size": 2,
39
+ "video_metadata": null,
40
+ "video_processor_type": "Qwen3VLVideoProcessor"
41
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff