yujiepan commited on
Commit
332fd89
·
verified ·
1 Parent(s): 6ecd0c3

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
.meta/create_model.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def create_model(source_model_id: str, source_revision: str, save_folder: str) -> str:
2
+ import json
3
+ from pathlib import Path
4
+
5
+ import torch
6
+ from huggingface_hub import hf_hub_download
7
+ from safetensors.torch import save_file
8
+ from transformers import AutoConfig, AutoModelForSequenceClassification, set_seed
9
+
10
+ folder = Path(save_folder)
11
+ folder.mkdir(parents=True, exist_ok=True)
12
+ config = json.loads(
13
+ Path(hf_hub_download(source_model_id, "config.json", revision=source_revision)).read_text(encoding="utf-8")
14
+ )
15
+ text = config["text_config"]
16
+ text.update(
17
+ hidden_size=16,
18
+ intermediate_size=32,
19
+ head_dim=256,
20
+ num_hidden_layers=8,
21
+ num_attention_heads=8,
22
+ num_key_value_heads=2,
23
+ linear_key_head_dim=128,
24
+ linear_value_head_dim=128,
25
+ linear_num_key_heads=16,
26
+ linear_num_value_heads=16,
27
+ layer_types=["linear_attention", "linear_attention", "linear_attention", "full_attention"] * 2,
28
+ )
29
+ config["vision_config"].update(
30
+ hidden_size=128,
31
+ intermediate_size=256,
32
+ depth=4,
33
+ num_heads=4,
34
+ out_hidden_size=16,
35
+ )
36
+ config["hidden_size"] = 16
37
+ config["num_labels"] = 2
38
+ config["architectures"] = ["Qwen3_5ForSequenceClassification"]
39
+ config["problem_type"] = "single_label_classification"
40
+ (folder / "config.json").write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8")
41
+ for name in (
42
+ "chat_template.jinja",
43
+ "generation_config.json",
44
+ "preprocessor_config.json",
45
+ "processor_config.json",
46
+ "tokenizer.json",
47
+ "tokenizer_config.json",
48
+ ):
49
+ (folder / name).write_bytes(Path(hf_hub_download(source_model_id, name, revision=source_revision)).read_bytes())
50
+
51
+ previous_dtype = torch.get_default_dtype()
52
+ try:
53
+ torch.set_default_dtype(torch.bfloat16)
54
+ set_seed(42)
55
+ model = AutoModelForSequenceClassification.from_config(AutoConfig.from_pretrained(folder))
56
+ with torch.no_grad():
57
+ for name, parameter in sorted(model.named_parameters()):
58
+ if name.endswith("A_log"):
59
+ parameter.zero_()
60
+ elif name.endswith("dt_bias"):
61
+ parameter.fill_(1)
62
+ elif name.endswith("weight") and "norm" in name:
63
+ parameter.fill_(1)
64
+ elif name.endswith("bias"):
65
+ parameter.zero_()
66
+ else:
67
+ parameter.normal_(mean=0.0, std=0.02)
68
+ state = {name: value.detach().cpu().contiguous() for name, value in model.state_dict().items()}
69
+ save_file(state, folder / "model.safetensors", metadata={"format": "pt"})
70
+ finally:
71
+ torch.set_default_dtype(previous_dtype)
72
+ (folder / "config.json").write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8")
73
+ (folder / "generation_config.json").write_bytes(
74
+ Path(hf_hub_download(source_model_id, "generation_config.json", revision=source_revision)).read_bytes()
75
+ )
76
+ return str(model)
77
+
78
+
79
+ create_model(
80
+ source_model_id="openbmb/MiniCPM-OCR-Jev",
81
+ source_revision="bdb03f86182a2824d2632d129c719cdf780502e2",
82
+ save_folder="/tmp/minicpm-ocr-jev",
83
+ )
.meta/env.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "source_model": {
3
+ "name": "openbmb/MiniCPM-OCR-Jev",
4
+ "commit_id": "bdb03f86182a2824d2632d129c719cdf780502e2"
5
+ },
6
+ "environments": {
7
+ "creation": {
8
+ "python": "3.12.13",
9
+ "packages": {
10
+ "huggingface_hub": "2.3.0",
11
+ "safetensors": "0.8.0",
12
+ "tokenizers": "0.23.3",
13
+ "torch": "2.13.0+cu126",
14
+ "transformers": "5.22.0.dev0"
15
+ },
16
+ "cuda": "12.6"
17
+ },
18
+ "transformers": {
19
+ "python": "3.11.2",
20
+ "packages": {
21
+ "torch": "2.7.1",
22
+ "transformers": "5.22.1",
23
+ "tokenizers": "0.23.3",
24
+ "huggingface_hub": "2.4.0",
25
+ "safetensors": "0.8.0",
26
+ "Pillow": "11.3.0",
27
+ "numpy": "2.3.2"
28
+ },
29
+ "cuda": "12.6",
30
+ "hardware": {
31
+ "gpu_model": "NVIDIA A800-SXM4-80GB"
32
+ }
33
+ }
34
+ }
35
+ }
.meta/model.log ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Qwen3_5ForSequenceClassification(
2
+ (model): Qwen3_5Model(
3
+ (visual): Qwen3_5VisionModel(
4
+ (patch_embed): Qwen3_5VisionPatchEmbed(
5
+ (proj): Conv3d(3, 128, kernel_size=(2, 16, 16), stride=(2, 16, 16))
6
+ )
7
+ (pos_embed): Embedding(2304, 128)
8
+ (rotary_pos_emb): Qwen3_5VisionRotaryEmbedding()
9
+ (blocks): ModuleList(
10
+ (0-3): 4 x Qwen3_5VisionBlock(
11
+ (norm1): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
12
+ (norm2): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
13
+ (attn): Qwen3_5VisionAttention(
14
+ (qkv): Linear(in_features=128, out_features=384, bias=True)
15
+ (proj): Linear(in_features=128, out_features=128, bias=True)
16
+ )
17
+ (mlp): Qwen3_5VisionMLP(
18
+ (linear_fc1): Linear(in_features=128, out_features=256, bias=True)
19
+ (linear_fc2): Linear(in_features=256, out_features=128, bias=True)
20
+ (act_fn): GELUTanh()
21
+ )
22
+ )
23
+ )
24
+ (merger): Qwen3_5VisionPatchMerger(
25
+ (norm): LayerNorm((128,), eps=1e-06, elementwise_affine=True, bias=True)
26
+ (linear_fc1): Linear(in_features=512, out_features=512, bias=True)
27
+ (act_fn): GELU(approximate='none')
28
+ (linear_fc2): Linear(in_features=512, out_features=16, bias=True)
29
+ )
30
+ )
31
+ (language_model): Qwen3_5TextModel(
32
+ (embed_tokens): Embedding(248320, 16, padding_idx=248044)
33
+ (layers): ModuleList(
34
+ (0-2): 3 x Qwen3_5DecoderLayer(
35
+ (linear_attn): Qwen3_5GatedDeltaNet(
36
+ (conv1d): Conv1d(6144, 6144, kernel_size=(4,), stride=(1,), padding=(3,), groups=6144, bias=False)
37
+ (norm): Qwen3_5RMSNormGated()
38
+ (out_proj): Linear(in_features=2048, out_features=16, bias=False)
39
+ (in_proj_qkv): Linear(in_features=16, out_features=6144, bias=False)
40
+ (in_proj_z): Linear(in_features=16, out_features=2048, bias=False)
41
+ (in_proj_b): Linear(in_features=16, out_features=16, bias=False)
42
+ (in_proj_a): Linear(in_features=16, out_features=16, bias=False)
43
+ )
44
+ (mlp): Qwen3_5MLP(
45
+ (gate_proj): Linear(in_features=16, out_features=32, bias=False)
46
+ (up_proj): Linear(in_features=16, out_features=32, bias=False)
47
+ (down_proj): Linear(in_features=32, out_features=16, bias=False)
48
+ (act_fn): SiLUActivation()
49
+ )
50
+ (input_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
51
+ (post_attention_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
52
+ )
53
+ (3): Qwen3_5DecoderLayer(
54
+ (self_attn): Qwen3_5Attention(
55
+ (q_proj): Linear(in_features=16, out_features=4096, bias=False)
56
+ (k_proj): Linear(in_features=16, out_features=512, bias=False)
57
+ (v_proj): Linear(in_features=16, out_features=512, bias=False)
58
+ (o_proj): Linear(in_features=2048, out_features=16, bias=False)
59
+ (q_norm): Qwen3_5RMSNorm((256,), eps=1e-06)
60
+ (k_norm): Qwen3_5RMSNorm((256,), eps=1e-06)
61
+ )
62
+ (mlp): Qwen3_5MLP(
63
+ (gate_proj): Linear(in_features=16, out_features=32, bias=False)
64
+ (up_proj): Linear(in_features=16, out_features=32, bias=False)
65
+ (down_proj): Linear(in_features=32, out_features=16, bias=False)
66
+ (act_fn): SiLUActivation()
67
+ )
68
+ (input_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
69
+ (post_attention_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
70
+ )
71
+ (4-6): 3 x Qwen3_5DecoderLayer(
72
+ (linear_attn): Qwen3_5GatedDeltaNet(
73
+ (conv1d): Conv1d(6144, 6144, kernel_size=(4,), stride=(1,), padding=(3,), groups=6144, bias=False)
74
+ (norm): Qwen3_5RMSNormGated()
75
+ (out_proj): Linear(in_features=2048, out_features=16, bias=False)
76
+ (in_proj_qkv): Linear(in_features=16, out_features=6144, bias=False)
77
+ (in_proj_z): Linear(in_features=16, out_features=2048, bias=False)
78
+ (in_proj_b): Linear(in_features=16, out_features=16, bias=False)
79
+ (in_proj_a): Linear(in_features=16, out_features=16, bias=False)
80
+ )
81
+ (mlp): Qwen3_5MLP(
82
+ (gate_proj): Linear(in_features=16, out_features=32, bias=False)
83
+ (up_proj): Linear(in_features=16, out_features=32, bias=False)
84
+ (down_proj): Linear(in_features=32, out_features=16, bias=False)
85
+ (act_fn): SiLUActivation()
86
+ )
87
+ (input_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
88
+ (post_attention_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
89
+ )
90
+ (7): Qwen3_5DecoderLayer(
91
+ (self_attn): Qwen3_5Attention(
92
+ (q_proj): Linear(in_features=16, out_features=4096, bias=False)
93
+ (k_proj): Linear(in_features=16, out_features=512, bias=False)
94
+ (v_proj): Linear(in_features=16, out_features=512, bias=False)
95
+ (o_proj): Linear(in_features=2048, out_features=16, bias=False)
96
+ (q_norm): Qwen3_5RMSNorm((256,), eps=1e-06)
97
+ (k_norm): Qwen3_5RMSNorm((256,), eps=1e-06)
98
+ )
99
+ (mlp): Qwen3_5MLP(
100
+ (gate_proj): Linear(in_features=16, out_features=32, bias=False)
101
+ (up_proj): Linear(in_features=16, out_features=32, bias=False)
102
+ (down_proj): Linear(in_features=32, out_features=16, bias=False)
103
+ (act_fn): SiLUActivation()
104
+ )
105
+ (input_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
106
+ (post_attention_layernorm): Qwen3_5RMSNorm((16,), eps=1e-06)
107
+ )
108
+ )
109
+ (norm): Qwen3_5RMSNorm((16,), eps=1e-06)
110
+ (rotary_emb): Qwen3_5TextRotaryEmbedding()
111
+ )
112
+ )
113
+ (score): Linear(in_features=16, out_features=2, bias=False)
114
+ )
README.md ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ pipeline_tag: image-text-to-text
4
+ base_model:
5
+ - openbmb/MiniCPM-OCR-Jev
6
+ ---
7
+
8
+ This is a randomly initialized tiny model based on [openbmb/MiniCPM-OCR-Jev](https://huggingface.co/openbmb/MiniCPM-OCR-Jev) for testing and debugging.
9
+
10
+ | Feature | Source | This repo |
11
+ |---|---|---|
12
+ | Checkpoint tensor elements | 2.21B BF16 | 6.64M BF16 |
13
+ | Safetensors weight files | 4.43 GB (model.safetensors) | 13.31 MB (model.safetensors) |
14
+ | Architecture / input | Qwen3.5 vision-language correctness scorer | Same |
15
+ | Vocabulary rows / tied embeddings | 248,320 / false | Same |
16
+ | Backbone layers / layer cadence | 24 / six 3-linear + 1-full cycles | 8 / two complete cycles |
17
+ | Hidden width / MLP width | 2,048 / 6,144 | 16 / 32 |
18
+ | Q heads / KV heads / head dimension | 8 / 2 / 256 | Same |
19
+ | Linear-attention key/value heads and dimensions | 16/16, 128/128 | Same |
20
+ | Vision depth / width / output width | 24 / 1,024 / 2,048 | 4 / 128 / 16 |
21
+ | Vision patch / temporal patch / spatial merge | 16 / 2 / 2 | Same |
22
+ | Task head | binary `score` [2, 2,048]; no `lm_head` | binary `score` [2, 16]; no `lm_head` |
23
+ | MTP | config declares one layer; no MTP tensors | Same |
24
+ | Checkpoint precision | BF16 | Same |
25
+
26
+ Load this checkpoint with `AutoModelForSequenceClassification`; it keeps the source binary `score` head and does not contain `lm_head`. Two complete linear/linear/linear/full cycles are retained. The Qwen3.5 linear-attention path requires CUDA and Triton. The exact public snippet was verified on an NVIDIA A800-SXM4-80GB.
27
+
28
+ | File path | Size |
29
+ |------|------|
30
+ | model.safetensors | 13.3MB |
31
+
32
+ ### Example usage
33
+
34
+ #### Transformers (✅ verified)
35
+
36
+ The example sends two images: the original block and a rendered image of the candidate text. Load with `AutoModelForSequenceClassification`; the checkpoint has a binary `score` head instead of `lm_head`. Install `transformers>=5.10.4` and `Pillow`; the Qwen3.5 linear-attention path requires CUDA and Triton.
37
+
38
+ ```python
39
+ def run_transformers(model_id: str):
40
+ import torch
41
+ from PIL import Image, ImageDraw
42
+ from transformers import AutoModelForSequenceClassification, AutoProcessor
43
+
44
+ model_id = str(model_id)
45
+ processor = AutoProcessor.from_pretrained(model_id)
46
+ model = AutoModelForSequenceClassification.from_pretrained(
47
+ model_id,
48
+ dtype=torch.bfloat16,
49
+ device_map="cuda",
50
+ attn_implementation="sdpa",
51
+ )
52
+ candidate = "Hello"
53
+ original = Image.new("RGB", (448, 448), "white")
54
+ ImageDraw.Draw(original).text((20, 20), candidate, fill="black")
55
+ rendered = Image.new("RGB", (448, 448), "white")
56
+ ImageDraw.Draw(rendered).text((20, 20), candidate, fill="black")
57
+ instruction = (
58
+ "第一张图是原图,第二张图是上述 OCR 文本渲染得到的图片。\n"
59
+ "请判断该 OCR 文本及其对应渲染图是否与原图内容一致。\n"
60
+ "这是一个二分类任务:一致标为 1,不一致标为 0。"
61
+ )
62
+ messages = [
63
+ {
64
+ "role": "user",
65
+ "content": [
66
+ {"type": "image", "image": original},
67
+ {"type": "text", "text": f"\nOCR文本:\n{candidate}\n"},
68
+ {"type": "image", "image": rendered},
69
+ {"type": "text", "text": "\n" + instruction},
70
+ ],
71
+ }
72
+ ]
73
+ inputs = processor.apply_chat_template(
74
+ messages,
75
+ tokenize=True,
76
+ add_generation_prompt=True,
77
+ return_dict=True,
78
+ return_tensors="pt",
79
+ ).to(model.device)
80
+ with torch.no_grad():
81
+ logits = model(**inputs).logits
82
+ assert torch.isfinite(logits).all()
83
+ score = torch.softmax(logits.float(), dim=-1)[:, 1]
84
+ print(float(score[0]))
85
+
86
+
87
+ if __name__ == "__main__":
88
+ run_transformers(model_id="tiny-random/minicpm-ocr-jev")
89
+ ```
90
+
91
+ ### Creating this repo
92
+
93
+ - Code: [.meta/create_model.py](.meta/create_model.py)
94
+ - Model structure: [.meta/model.log](.meta/model.log)
95
+ - Environment: [.meta/env.json](.meta/env.json)
96
+
97
+ ### Change log
98
+
99
+ - 2026-11-01: Initial tiny MiniCPM-OCR Jev checkpoint.
100
+
101
+ *This repo is generated by DeepSeek-V4.1-Flash.*
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 true %}
150
+ {{- '<think>\n' }}
151
+ {%- else %}
152
+ {{- '<think>\n\n</think>\n\n' }}
153
+ {%- endif %}
154
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3_5ForSequenceClassification"
4
+ ],
5
+ "dtype": "bfloat16",
6
+ "eos_token_id": 248046,
7
+ "hidden_size": 16,
8
+ "image_token_id": 248056,
9
+ "model_type": "qwen3_5",
10
+ "pad_token_id": 248044,
11
+ "problem_type": "single_label_classification",
12
+ "text_config": {
13
+ "attention_bias": false,
14
+ "attention_dropout": 0.0,
15
+ "attn_output_gate": true,
16
+ "bos_token_id": null,
17
+ "dtype": "bfloat16",
18
+ "eos_token_id": 248044,
19
+ "full_attention_interval": 4,
20
+ "head_dim": 256,
21
+ "hidden_act": "silu",
22
+ "hidden_size": 16,
23
+ "initializer_range": 0.02,
24
+ "intermediate_size": 32,
25
+ "layer_types": [
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
+ ],
35
+ "linear_conv_kernel_dim": 4,
36
+ "linear_key_head_dim": 128,
37
+ "linear_num_key_heads": 16,
38
+ "linear_num_value_heads": 16,
39
+ "linear_value_head_dim": 128,
40
+ "mamba_ssm_dtype": "float32",
41
+ "max_position_embeddings": 262144,
42
+ "mlp_only_layers": [],
43
+ "model_type": "qwen3_5_text",
44
+ "mtp_num_hidden_layers": 1,
45
+ "mtp_use_dedicated_embeddings": false,
46
+ "num_attention_heads": 8,
47
+ "num_hidden_layers": 8,
48
+ "num_key_value_heads": 2,
49
+ "pad_token_id": 248044,
50
+ "partial_rotary_factor": 0.25,
51
+ "rms_norm_eps": 1e-06,
52
+ "rope_parameters": {
53
+ "mrope_interleaved": true,
54
+ "mrope_section": [
55
+ 11,
56
+ 11,
57
+ 10
58
+ ],
59
+ "partial_rotary_factor": 0.25,
60
+ "rope_theta": 10000000,
61
+ "rope_type": "default"
62
+ },
63
+ "tie_word_embeddings": false,
64
+ "use_cache": false,
65
+ "vocab_size": 248320
66
+ },
67
+ "tie_word_embeddings": false,
68
+ "transformers_version": "5.10.4",
69
+ "use_cache": false,
70
+ "video_token_id": 248057,
71
+ "vision_config": {
72
+ "deepstack_visual_indexes": [],
73
+ "depth": 4,
74
+ "dtype": "bfloat16",
75
+ "hidden_act": "gelu_pytorch_tanh",
76
+ "hidden_size": 128,
77
+ "in_channels": 3,
78
+ "initializer_range": 0.02,
79
+ "intermediate_size": 256,
80
+ "model_type": "qwen3_5_vision",
81
+ "num_heads": 4,
82
+ "num_position_embeddings": 2304,
83
+ "out_hidden_size": 16,
84
+ "patch_size": 16,
85
+ "spatial_merge_size": 2,
86
+ "temporal_patch_size": 2
87
+ },
88
+ "vision_end_token_id": 248054,
89
+ "vision_start_token_id": 248053,
90
+ "num_labels": 2
91
+ }
generation_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "eos_token_id": [
4
+ 248046,
5
+ 248044,
6
+ 248046
7
+ ],
8
+ "pad_token_id": 248044,
9
+ "transformers_version": "5.10.4",
10
+ "use_cache": true
11
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:596753a5776151dc1ccea6b750958a0a405439fdd4d559b466a09147fc7b6117
3
+ size 13306128
preprocessor_config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "size": {
3
+ "longest_edge": 16777216,
4
+ "shortest_edge": 65536
5
+ },
6
+ "patch_size": 16,
7
+ "temporal_patch_size": 2,
8
+ "merge_size": 2,
9
+ "image_mean": [
10
+ 0.5,
11
+ 0.5,
12
+ 0.5
13
+ ],
14
+ "image_std": [
15
+ 0.5,
16
+ 0.5,
17
+ 0.5
18
+ ],
19
+ "processor_class": "Qwen3VLProcessor",
20
+ "image_processor_type": "Qwen2VLImageProcessorFast"
21
+ }
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
+ }
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
+ }