tangy52 commited on
Commit
2fdf7d7
·
verified ·
1 Parent(s): 67eb643

NV-Reason-PathWSI-4B preview upload (weights, model card, tokenizer, configs)

Browse files
.gitattributes CHANGED
@@ -1,35 +1,3 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  *.safetensors filter=lfs diff=lfs merge=lfs -text
2
+ *.bin filter=lfs diff=lfs merge=lfs -text
3
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ __pycache__/
2
+ *.py[cod]
3
+ .DS_Store
LICENSE ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+
3
+ OpenMDW License Agreement, version 1.1 (OpenMDW-1.1)
4
+
5
+ By exercising rights granted to you under this agreement, you accept and agree
6
+ to its terms.
7
+
8
+ As used in this agreement, "Model Materials" means the materials provided to
9
+ you under this agreement, consisting of: (1) one or more machine learning
10
+ models (including architecture and parameters); and (2) all related artifacts
11
+ (including associated data, documentation and software) that are provided to
12
+ you hereunder.
13
+
14
+ Subject to your compliance with this agreement, permission is hereby granted,
15
+ free of charge, to deal in the Model Materials without restriction, including
16
+ under all copyright, patent, database, and trade secret rights included or
17
+ embodied therein.
18
+
19
+ If you distribute any portion of the Model Materials, you shall retain in your
20
+ distribution (1) a copy of this agreement, and (2) all copyright notices and
21
+ other notices of origin included in the Model Materials that are applicable to
22
+ your distribution.
23
+
24
+ If you file, maintain, or voluntarily participate in a lawsuit against any
25
+ person or entity asserting that the Model Materials directly or indirectly
26
+ infringe any patent or copyright, then all rights and grants made to you
27
+ hereunder are terminated, unless that lawsuit was in response to a
28
+ corresponding lawsuit first brought against you.
29
+
30
+ This agreement does not impose any restrictions or obligations with respect to
31
+ any use, modification, or sharing of any outputs generated by using the Model
32
+ Materials.
33
+
34
+ THE MODEL MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
35
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE, NONINFRINGEMENT, ACCURACY, OR THE
37
+ ABSENCE OF LATENT OR OTHER DEFECTS OR ERRORS, WHETHER OR NOT DISCOVERABLE, ALL
38
+ TO THE GREATEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW.
39
+
40
+ YOU ARE SOLELY RESPONSIBLE FOR (1) CLEARING RIGHTS OF OTHER PERSONS THAT MAY
41
+ APPLY TO THE MODEL MATERIALS OR ANY USE THEREOF, INCLUDING WITHOUT LIMITATION
42
+ ANY PERSON'S COPYRIGHTS OR OTHER RIGHTS INCLUDED OR EMBODIED IN THE MODEL
43
+ MATERIALS; (2) OBTAINING ANY NECESSARY CONSENTS, PERMISSIONS OR OTHER RIGHTS
44
+ REQUIRED FOR ANY USE OF THE MODEL MATERIALS; OR (3) PERFORMING ANY DUE
45
+ DILIGENCE OR UNDERTAKING ANY OTHER INVESTIGATIONS INTO THE MODEL MATERIALS OR
46
+ ANYTHING INCORPORATED OR EMBODIED THEREIN.
47
+
48
+ IN NO EVENT SHALL THE PROVIDERS OF THE MODEL MATERIALS BE LIABLE FOR ANY CLAIM,
49
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
50
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MODEL MATERIALS, THE
51
+ USE THEREOF OR OTHER DEALINGS THEREIN.
README.md CHANGED
@@ -1,3 +1,244 @@
1
  ---
 
2
  license: openmdw-1.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ library_name: transformers
3
  license: openmdw-1.1
4
+ license_name: openmdw-1.1
5
+ license_link: https://huggingface.co/nvidia/NV-Reason-PathWSI-4B/blob/main/LICENSE
6
+ language:
7
+ - en
8
+ pipeline_tag: image-text-to-text
9
+ base_model:
10
+ - Qwen/Qwen3.5-4B
11
+ base_model_relation: finetune
12
+ tags:
13
+ - medical-imaging
14
+ - pathology
15
+ - histopathology
16
+ - whole-slide-imaging
17
+ - vision-language
18
+ - nv-reason-pathwsi
19
+ - nvidia
20
  ---
21
+
22
+ # NV-Reason-PathWSI-4B
23
+
24
+ [![HuggingFace](https://img.shields.io/badge/%F0%9F%A4%97-Hugging%20Face-yellow)](https://huggingface.co/nvidia/NV-Reason-PathWSI-4B)
25
+ [![GitHub](https://img.shields.io/badge/github-repo-blue?logo=github)](https://github.com/NVIDIA-Medtech/NV-Reason-PathWSI)
26
+ [![License](https://img.shields.io/badge/License-OpenMDW--1.1-f5de53)](LICENSE)
27
+
28
+ NV-Reason-PathWSI-4B is a vision-language model for pathology image interpretation.
29
+ It fine-tunes the native multimodal Qwen3.5-4B on a joint pathology
30
+ workload of region grounding, patch captioning, and short chain-of-thought
31
+ reasoning over H&E and IHC-stained histopathology images, and supports
32
+ patch-level question answering, multiple-choice benchmarks, region
33
+ grounding, and thinking-mode reasoning.
34
+
35
+ The model loads with stock Transformers and vLLM as standard
36
+ `Qwen3_5ForConditionalGeneration` weights; `trust_remote_code` is not
37
+ required.
38
+
39
+ ## Installation
40
+
41
+ Python 3.11+ and a CUDA-capable PyTorch installation are recommended.
42
+
43
+ ```bash
44
+ python -m pip install -r https://huggingface.co/nvidia/NV-Reason-PathWSI-4B/resolve/main/requirements.txt
45
+ ```
46
+
47
+ ## Quick Start
48
+
49
+ ```python
50
+ import torch
51
+ from transformers import AutoModelForImageTextToText, AutoProcessor
52
+
53
+ model_id = "nvidia/NV-Reason-PathWSI-4B"
54
+ image_path = "path/to/patch.jpg"
55
+
56
+ model = AutoModelForImageTextToText.from_pretrained(
57
+ model_id,
58
+ dtype=torch.bfloat16,
59
+ ).eval().to("cuda")
60
+ processor = AutoProcessor.from_pretrained(model_id)
61
+
62
+ def generate_response(image_path, prompt_text, enable_thinking=False, max_new_tokens=2048):
63
+ messages = [
64
+ {
65
+ "role": "user",
66
+ "content": [
67
+ {"type": "image"},
68
+ {"type": "text", "text": prompt_text},
69
+ ],
70
+ }
71
+ ]
72
+ prompt = processor.apply_chat_template(
73
+ messages,
74
+ tokenize=False,
75
+ add_generation_prompt=True,
76
+ enable_thinking=enable_thinking,
77
+ )
78
+ inputs = processor(
79
+ text=prompt, images=[image_path], return_tensors="pt"
80
+ ).to(model.device)
81
+
82
+ with torch.inference_mode():
83
+ generated_ids = model.generate(
84
+ **inputs,
85
+ max_new_tokens=max_new_tokens,
86
+ do_sample=False,
87
+ use_cache=True,
88
+ )
89
+
90
+ new_tokens = generated_ids[:, inputs.input_ids.shape[1]:]
91
+ return processor.batch_decode(
92
+ new_tokens, skip_special_tokens=True, clean_up_tokenization_spaces=False
93
+ )[0]
94
+
95
+ # Open-ended description
96
+ print(generate_response(image_path, "Describe the histopathological features visible in this image."))
97
+
98
+ # Multiple-choice with a concise answer (thinking off)
99
+ print(generate_response(image_path, "Which feature is present? A) ... B) ... C) ... D) ...", enable_thinking=False))
100
+
101
+ # Reasoning mode
102
+ print(generate_response(image_path, "Reason step by step about the likely diagnosis.", enable_thinking=True))
103
+ ```
104
+
105
+ ## License/Terms of Use
106
+
107
+ Use of this model is governed by the [OpenMDW-1.1 License](LICENSE).
108
+
109
+ ### Deployment Geography
110
+
111
+ Global
112
+
113
+ ### Use Case
114
+
115
+ Pathologists, pathology researchers, and medical students would be expected
116
+ to use this model for pathology image description, question answering, and
117
+ reviewable AI-generated reasoning analyses in research and educational
118
+ settings.
119
+
120
+ **Important Medical AI Considerations:**
121
+ This model is designed for research and educational purposes only and should
122
+ not be used for clinical diagnosis or treatment decisions. All outputs should
123
+ be reviewed by qualified medical professionals. Generated reasoning is
124
+ reviewable model output and is not guaranteed to represent the model's
125
+ internal computation.
126
+
127
+ ## Model Architecture
128
+
129
+ **Architecture Type:** Transformer (Vision-Language Model)<br>
130
+ **Network Architecture:** Qwen3.5-4B native multimodal vision-language model (ViT vision encoder + language model with thinking-mode chat template)<br>
131
+ **Task:** Vision-Language (pathology image question answering, description, and reasoning)<br>
132
+ **Base Model:** [Qwen3.5-4B](https://huggingface.co/Qwen/Qwen3.5-4B)<br>
133
+ **Number of model parameters:** 4.54B (bf16)<br>
134
+
135
+ **Hugging Face integration:**
136
+ - `AutoModelForImageTextToText` + `AutoProcessor`, no remote code
137
+ - Chat template supports `enable_thinking`
138
+
139
+ ## Input
140
+
141
+ **Input Type(s):** Image, Text<br>
142
+ **Input Format(s):** RGB images (PNG/JPEG; common histopathology patch and
143
+ tile formats), text prompts (string)<br>
144
+ **Other Properties Related to Input:** Accepts H&E and IHC-stained
145
+ histopathology patches and whole-slide image tiles digitized at typical
146
+ clinical magnifications, with natural-language prompts for description,
147
+ questions, or reasoning requests.
148
+
149
+ ## Output
150
+
151
+ **Output Type(s):** Text<br>
152
+ **Output Format:** String<br>
153
+ **Other Properties Related to Output:** Direct answers (default) or
154
+ step-by-step reasoning followed by an answer in thinking mode. Grounding
155
+ prompts elicit bounding-box responses in the trained format.
156
+
157
+ Our AI models are designed and/or optimized to run on NVIDIA GPU-accelerated
158
+ systems. By leveraging NVIDIA's hardware (GPU cores) and software frameworks
159
+ (CUDA libraries), the model achieves faster training and inference times
160
+ compared to CPU-only solutions.
161
+
162
+ ## Software Integration
163
+
164
+ **Runtime Engine(s):**
165
+
166
+ - PyTorch
167
+ - Transformers
168
+ - vLLM
169
+
170
+ **Supported Hardware Microarchitecture Compatibility:**
171
+
172
+ - NVIDIA Ampere
173
+ - NVIDIA Ada
174
+ - NVIDIA Hopper
175
+
176
+ **Supported Operating System(s):**
177
+
178
+ - Linux
179
+
180
+ The integration of foundation and fine-tuned models into AI systems requires
181
+ additional testing using use-case-specific data to ensure safe and effective
182
+ deployment.
183
+
184
+ ## Model Version(s)
185
+
186
+ 0.1 - Initial release version; best all-around 4B checkpoint of the joint
187
+ SFT sweep.
188
+
189
+ ## Training Dataset
190
+
191
+ **Data Modality:** Image, Text<br>
192
+ **Data Collection Method:** Hybrid: Human, Automatic/Sensors<br>
193
+ **Labeling Method:** Hybrid: Human, Synthetic<br>
194
+ **Properties:** Joint supervised fine-tuning on a mix of region-grounding
195
+ examples with verified bounding boxes, TCGA-derived patch caption and
196
+ short chain-of-thought reasoning data, and whole-slide multi-ROI examples.
197
+ All patient-derived source data is de-identified.
198
+
199
+ ## Evaluation Dataset
200
+
201
+ **Data Modality:** Image, Text<br>
202
+ **Properties:** Public and internal pathology benchmarks held out from
203
+ training: PathMMU (8,521), PathVQA (6,719), an internal private benchmark
204
+ (555), patch-level grounding (259) and WSI-level grounding (60).
205
+
206
+ ## Benchmarks
207
+
208
+ Decoding: vLLM, greedy, 16384 context, 8192 max tokens, thinking off
209
+ unless noted.
210
+
211
+ | Benchmark | NV-Reason-PathWSI-4B |
212
+ |---|---|
213
+ | PathMMU (8,521) | **64.61** (thinking: 64.01) |
214
+ | PathVQA (6,719) | 27.28 |
215
+ | Internal private benchmark (555) | 30.81 |
216
+ | Patch grounding F1@0.25 (259) | 0.368 |
217
+ | WSI grounding F1@0.25 (60) | 0.219 |
218
+
219
+ Per-dataset details and provenance: the accompanying GitHub repository's
220
+ `benchmarks/VERIFIED_RESULTS.md`.
221
+
222
+ ## Inference
223
+
224
+ **Acceleration Engine:** PyTorch, Transformers, vLLM<br>
225
+ **Test Hardware:**
226
+
227
+ - H100
228
+
229
+ ## Ethical Considerations
230
+
231
+ NVIDIA believes Trustworthy AI is a shared responsibility and we have
232
+ established policies and practices to enable development for a wide array of AI
233
+ applications. When downloaded or used in accordance with our terms of service,
234
+ developers should work with their internal model team to ensure this model
235
+ meets requirements for the relevant industry and use case and addresses
236
+ unforeseen product misuse.
237
+
238
+ Users are responsible for ensuring pathology images are properly
239
+ de-identified and handled in accordance with applicable privacy
240
+ requirements. Please make sure you have proper rights and permissions for
241
+ all input image content.
242
+
243
+ Please report model quality, risk, security vulnerabilities or concerns
244
+ [here](https://www.nvidia.com/en-us/support/submit-security-vulnerability/).
chat_template.jinja ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- set image_count = namespace(value=0) %}
2
+ {%- set video_count = namespace(value=0) %}
3
+ {%- macro render_content(content, do_vision_count, is_system_content=false) %}
4
+ {%- if content is string %}
5
+ {{- content }}
6
+ {%- elif content is iterable and content is not mapping %}
7
+ {%- for item in content %}
8
+ {%- if 'image' in item or 'image_url' in item or item.type == 'image' %}
9
+ {%- if is_system_content %}
10
+ {{- raise_exception('System message cannot contain images.') }}
11
+ {%- endif %}
12
+ {%- if do_vision_count %}
13
+ {%- set image_count.value = image_count.value + 1 %}
14
+ {%- endif %}
15
+ {%- if add_vision_id %}
16
+ {{- 'Picture ' ~ image_count.value ~ ': ' }}
17
+ {%- endif %}
18
+ {{- '<|vision_start|><|image_pad|><|vision_end|>' }}
19
+ {%- elif 'video' in item or item.type == 'video' %}
20
+ {%- if is_system_content %}
21
+ {{- raise_exception('System message cannot contain videos.') }}
22
+ {%- endif %}
23
+ {%- if do_vision_count %}
24
+ {%- set video_count.value = video_count.value + 1 %}
25
+ {%- endif %}
26
+ {%- if add_vision_id %}
27
+ {{- 'Video ' ~ video_count.value ~ ': ' }}
28
+ {%- endif %}
29
+ {{- '<|vision_start|><|video_pad|><|vision_end|>' }}
30
+ {%- elif 'text' in item %}
31
+ {{- item.text }}
32
+ {%- else %}
33
+ {{- raise_exception('Unexpected item type in content.') }}
34
+ {%- endif %}
35
+ {%- endfor %}
36
+ {%- elif content is none or content is undefined %}
37
+ {{- '' }}
38
+ {%- else %}
39
+ {{- raise_exception('Unexpected content type.') }}
40
+ {%- endif %}
41
+ {%- endmacro %}
42
+ {%- if not messages %}
43
+ {{- raise_exception('No messages provided.') }}
44
+ {%- endif %}
45
+ {%- if tools and tools is iterable and tools is not mapping %}
46
+ {{- '<|im_start|>system\n' }}
47
+ {{- "# Tools\n\nYou have access to the following functions:\n\n<tools>" }}
48
+ {%- for tool in tools %}
49
+ {{- "\n" }}
50
+ {{- tool | tojson }}
51
+ {%- endfor %}
52
+ {{- "\n</tools>" }}
53
+ {{- '\n\nIf you choose to call a function ONLY reply in the following format with NO suffix:\n\n<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call>\n\n<IMPORTANT>\nReminder:\n- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags\n- Required parameters MUST be specified\n- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after\n- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls\n</IMPORTANT>' }}
54
+ {%- if messages[0].role == 'system' %}
55
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
56
+ {%- if content %}
57
+ {{- '\n\n' + content }}
58
+ {%- endif %}
59
+ {%- endif %}
60
+ {{- '<|im_end|>\n' }}
61
+ {%- else %}
62
+ {%- if messages[0].role == 'system' %}
63
+ {%- set content = render_content(messages[0].content, false, true)|trim %}
64
+ {{- '<|im_start|>system\n' + content + '<|im_end|>\n' }}
65
+ {%- endif %}
66
+ {%- endif %}
67
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
68
+ {%- for message in messages[::-1] %}
69
+ {%- set index = (messages|length - 1) - loop.index0 %}
70
+ {%- if ns.multi_step_tool and message.role == "user" %}
71
+ {%- set content = render_content(message.content, false)|trim %}
72
+ {%- if not(content.startswith('<tool_response>') and content.endswith('</tool_response>')) %}
73
+ {%- set ns.multi_step_tool = false %}
74
+ {%- set ns.last_query_index = index %}
75
+ {%- endif %}
76
+ {%- endif %}
77
+ {%- endfor %}
78
+ {%- if ns.multi_step_tool %}
79
+ {{- raise_exception('No user query found in messages.') }}
80
+ {%- endif %}
81
+ {%- for message in messages %}
82
+ {%- set content = render_content(message.content, true)|trim %}
83
+ {%- if message.role == "system" %}
84
+ {%- if not loop.first %}
85
+ {{- raise_exception('System message must be at the beginning.') }}
86
+ {%- endif %}
87
+ {%- elif message.role == "user" %}
88
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
89
+ {%- elif message.role == "assistant" %}
90
+ {%- set reasoning_content = '' %}
91
+ {%- if message.reasoning_content is string %}
92
+ {%- set reasoning_content = message.reasoning_content %}
93
+ {%- else %}
94
+ {%- if '</think>' in content %}
95
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
96
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
97
+ {%- endif %}
98
+ {%- endif %}
99
+ {%- set reasoning_content = reasoning_content|trim %}
100
+ {%- if loop.index0 > ns.last_query_index %}
101
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content + '\n</think>\n\n' + content }}
102
+ {%- else %}
103
+ {{- '<|im_start|>' + message.role + '\n' + content }}
104
+ {%- endif %}
105
+ {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
106
+ {%- for tool_call in message.tool_calls %}
107
+ {%- if tool_call.function is defined %}
108
+ {%- set tool_call = tool_call.function %}
109
+ {%- endif %}
110
+ {%- if loop.first %}
111
+ {%- if content|trim %}
112
+ {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
113
+ {%- else %}
114
+ {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}
115
+ {%- endif %}
116
+ {%- else %}
117
+ {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}
118
+ {%- endif %}
119
+ {%- if tool_call.arguments is defined %}
120
+ {%- for args_name, args_value in tool_call.arguments|items %}
121
+ {{- '<parameter=' + args_name + '>\n' }}
122
+ {%- set args_value = args_value | tojson | safe if args_value is mapping or (args_value is sequence and args_value is not string) else args_value | string %}
123
+ {{- args_value }}
124
+ {{- '\n</parameter>\n' }}
125
+ {%- endfor %}
126
+ {%- endif %}
127
+ {{- '</function>\n</tool_call>' }}
128
+ {%- endfor %}
129
+ {%- endif %}
130
+ {{- '<|im_end|>\n' }}
131
+ {%- elif message.role == "tool" %}
132
+ {%- if loop.previtem and loop.previtem.role != "tool" %}
133
+ {{- '<|im_start|>user' }}
134
+ {%- endif %}
135
+ {{- '\n<tool_response>\n' }}
136
+ {{- content }}
137
+ {{- '\n</tool_response>' }}
138
+ {%- if not loop.last and loop.nextitem.role != "tool" %}
139
+ {{- '<|im_end|>\n' }}
140
+ {%- elif loop.last %}
141
+ {{- '<|im_end|>\n' }}
142
+ {%- endif %}
143
+ {%- else %}
144
+ {{- raise_exception('Unexpected message role.') }}
145
+ {%- endif %}
146
+ {%- endfor %}
147
+ {%- if add_generation_prompt %}
148
+ {{- '<|im_start|>assistant\n' }}
149
+ {%- if enable_thinking is defined and enable_thinking is false %}
150
+ {{- '<think>\n\n</think>\n\n' }}
151
+ {%- else %}
152
+ {{- '<think>\n' }}
153
+ {%- endif %}
154
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3_5ForConditionalGeneration"
4
+ ],
5
+ "dtype": "bfloat16",
6
+ "image_token_id": 248056,
7
+ "model_type": "qwen3_5",
8
+ "text_config": {
9
+ "attention_bias": false,
10
+ "attention_dropout": 0.0,
11
+ "attn_output_gate": true,
12
+ "bos_token_id": null,
13
+ "dtype": "bfloat16",
14
+ "eos_token_id": 248044,
15
+ "full_attention_interval": 4,
16
+ "head_dim": 256,
17
+ "hidden_act": "silu",
18
+ "hidden_size": 2560,
19
+ "initializer_range": 0.02,
20
+ "intermediate_size": 9216,
21
+ "layer_types": [
22
+ "linear_attention",
23
+ "linear_attention",
24
+ "linear_attention",
25
+ "full_attention",
26
+ "linear_attention",
27
+ "linear_attention",
28
+ "linear_attention",
29
+ "full_attention",
30
+ "linear_attention",
31
+ "linear_attention",
32
+ "linear_attention",
33
+ "full_attention",
34
+ "linear_attention",
35
+ "linear_attention",
36
+ "linear_attention",
37
+ "full_attention",
38
+ "linear_attention",
39
+ "linear_attention",
40
+ "linear_attention",
41
+ "full_attention",
42
+ "linear_attention",
43
+ "linear_attention",
44
+ "linear_attention",
45
+ "full_attention",
46
+ "linear_attention",
47
+ "linear_attention",
48
+ "linear_attention",
49
+ "full_attention",
50
+ "linear_attention",
51
+ "linear_attention",
52
+ "linear_attention",
53
+ "full_attention"
54
+ ],
55
+ "linear_conv_kernel_dim": 4,
56
+ "linear_key_head_dim": 128,
57
+ "linear_num_key_heads": 16,
58
+ "linear_num_value_heads": 32,
59
+ "linear_value_head_dim": 128,
60
+ "mamba_ssm_dtype": "float32",
61
+ "max_position_embeddings": 262144,
62
+ "mlp_only_layers": [],
63
+ "model_type": "qwen3_5_text",
64
+ "mtp_num_hidden_layers": 1,
65
+ "mtp_use_dedicated_embeddings": false,
66
+ "num_attention_heads": 16,
67
+ "num_hidden_layers": 32,
68
+ "num_key_value_heads": 4,
69
+ "pad_token_id": null,
70
+ "partial_rotary_factor": 0.25,
71
+ "rms_norm_eps": 1e-06,
72
+ "rope_parameters": {
73
+ "mrope_interleaved": true,
74
+ "mrope_section": [
75
+ 11,
76
+ 11,
77
+ 10
78
+ ],
79
+ "partial_rotary_factor": 0.25,
80
+ "rope_theta": 10000000,
81
+ "rope_type": "default"
82
+ },
83
+ "tie_word_embeddings": true,
84
+ "use_cache": true,
85
+ "vocab_size": 248320
86
+ },
87
+ "tie_word_embeddings": true,
88
+ "transformers_version": "5.8.1",
89
+ "video_token_id": 248057,
90
+ "vision_config": {
91
+ "deepstack_visual_indexes": [],
92
+ "depth": 24,
93
+ "dtype": "bfloat16",
94
+ "hidden_act": "gelu_pytorch_tanh",
95
+ "hidden_size": 1024,
96
+ "in_channels": 3,
97
+ "initializer_range": 0.02,
98
+ "intermediate_size": 4096,
99
+ "model_type": "qwen3_5_vision",
100
+ "num_heads": 16,
101
+ "num_position_embeddings": 2304,
102
+ "out_hidden_size": 2560,
103
+ "patch_size": 16,
104
+ "spatial_merge_size": 2,
105
+ "temporal_patch_size": 2
106
+ },
107
+ "vision_end_token_id": 248054,
108
+ "vision_start_token_id": 248053
109
+ }
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "eos_token_id": 248044,
4
+ "transformers_version": "5.8.1",
5
+ "use_cache": true
6
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:31c6d29744c6bd051c3b41347a05acd05137fc66bafd11035382c427a18d35d3
3
+ size 9078620536
processor_config.json ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_processor": {
3
+ "do_convert_rgb": true,
4
+ "do_normalize": true,
5
+ "do_rescale": true,
6
+ "do_resize": true,
7
+ "image_mean": [
8
+ 0.5,
9
+ 0.5,
10
+ 0.5
11
+ ],
12
+ "image_processor_type": "Qwen2VLImageProcessor",
13
+ "image_std": [
14
+ 0.5,
15
+ 0.5,
16
+ 0.5
17
+ ],
18
+ "merge_size": 2,
19
+ "patch_size": 16,
20
+ "resample": 3,
21
+ "rescale_factor": 0.00392156862745098,
22
+ "size": {
23
+ "longest_edge": 16777216,
24
+ "shortest_edge": 65536
25
+ },
26
+ "temporal_patch_size": 2
27
+ },
28
+ "processor_class": "Qwen3VLProcessor",
29
+ "video_processor": {
30
+ "do_convert_rgb": true,
31
+ "do_normalize": true,
32
+ "do_rescale": true,
33
+ "do_resize": true,
34
+ "do_sample_frames": true,
35
+ "fps": 2,
36
+ "image_mean": [
37
+ 0.5,
38
+ 0.5,
39
+ 0.5
40
+ ],
41
+ "image_std": [
42
+ 0.5,
43
+ 0.5,
44
+ 0.5
45
+ ],
46
+ "max_frames": 768,
47
+ "merge_size": 2,
48
+ "min_frames": 4,
49
+ "patch_size": 16,
50
+ "resample": 3,
51
+ "rescale_factor": 0.00392156862745098,
52
+ "return_metadata": false,
53
+ "size": {
54
+ "longest_edge": 25165824,
55
+ "shortest_edge": 4096
56
+ },
57
+ "temporal_patch_size": 2,
58
+ "video_processor_type": "Qwen3VLVideoProcessor"
59
+ }
60
+ }
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers==5.8.1
2
+ torch
3
+ accelerate
4
+ Pillow
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:06b9509352d2af50381ab2247e083b80d32d5c0aba91c272ca9ff729b6a0e523
3
+ size 19989325
tokenizer_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "audio_bos_token": "<|audio_start|>",
4
+ "audio_eos_token": "<|audio_end|>",
5
+ "audio_token": "<|audio_pad|>",
6
+ "backend": "tokenizers",
7
+ "bos_token": null,
8
+ "clean_up_tokenization_spaces": false,
9
+ "eos_token": "<|im_end|>",
10
+ "errors": "replace",
11
+ "image_token": "<|image_pad|>",
12
+ "is_local": true,
13
+ "local_files_only": false,
14
+ "model_max_length": 262144,
15
+ "model_specific_special_tokens": {
16
+ "audio_bos_token": "<|audio_start|>",
17
+ "audio_eos_token": "<|audio_end|>",
18
+ "audio_token": "<|audio_pad|>",
19
+ "image_token": "<|image_pad|>",
20
+ "video_token": "<|video_pad|>",
21
+ "vision_bos_token": "<|vision_start|>",
22
+ "vision_eos_token": "<|vision_end|>"
23
+ },
24
+ "pad_token": "<|endoftext|>",
25
+ "pretokenize_regex": "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?[\\p{L}\\p{M}]+|\\p{N}| ?[^\\s\\p{L}\\p{M}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+",
26
+ "processor_class": "Qwen3VLProcessor",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "Qwen2Tokenizer",
29
+ "unk_token": null,
30
+ "video_token": "<|video_pad|>",
31
+ "vision_bos_token": "<|vision_start|>",
32
+ "vision_eos_token": "<|vision_end|>"
33
+ }