psyche Ji-Ha commited on
Commit
d8268c5
·
0 Parent(s):

Duplicate from Ji-Ha/glm-ocr-onnx

Browse files

Co-authored-by: Ji-Ha <Ji-Ha@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ *.onnx filter=lfs diff=lfs merge=lfs -text
2
+ *.data filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - zh
5
+ - en
6
+ - fr
7
+ - es
8
+ - ru
9
+ - de
10
+ - ja
11
+ - ko
12
+ pipeline_tag: image-to-text
13
+ library_name: onnxruntime
14
+ base_model:
15
+ - zai-org/GLM-OCR
16
+ ---
17
+
18
+ # GLM-OCR ONNX (Static Split, Edge-Oriented)
19
+
20
+ This repository contains a production-oriented ONNX export/bundle for GLM-OCR with static graph wiring and quantization-aware layout for edge/browser deployment workflows.
21
+
22
+ ## Credits and Upstream
23
+
24
+ - Original model and research release: `zai-org/GLM-OCR`
25
+ - Hugging Face: https://huggingface.co/zai-org/GLM-OCR
26
+ - GitHub: https://github.com/zai-org/GLM-OCR
27
+ - This repo is a deployment/export artifact built from the upstream model for ONNX static inference pipelines.
28
+
29
+ Please cite and credit the original GLM-OCR authors for model architecture, training, and benchmark claims.
30
+
31
+ ## What Is Included
32
+
33
+ - `manifest.json`: runtime manifest for static Python/ONNX flows.
34
+ - `manifest.web.json`: ORT Web (WASM/WebGPU) wiring manifest.
35
+ - `fp16/`: core fp16 split graphs and external weight shards.
36
+ - `quant/`: quantized vision graph (`vision_quant`) and external shard.
37
+
38
+ The bundle is organized so quantized assets are clearly separated from fp16 assets.
39
+
40
+ ## Notes on Quality and Optimization
41
+
42
+ - Primary quality baseline is upstream GLM-OCR behavior, with quality-preserving deployment optimizations.
43
+ - Quantization is applied selectively (not blanket full-model int8) to avoid OCR quality degradation on difficult layouts.
44
+ - `vision_quant` is provided as an optional path, while fp16 vision remains available.
45
+
46
+ ## Python Inference Example
47
+
48
+ Use your static runner with `manifest.json` from this model repo.
49
+
50
+ ```bash
51
+ python run_onnx_static.py \
52
+ --artifact_dir . \
53
+ --image ./examples/source/page.png \
54
+ --task document \
55
+ --device cuda \
56
+ --cuda_no_fallback \
57
+ --official_quality \
58
+ --vision_policy table_quant \
59
+ --out_text ./pred.md
60
+ ```
61
+
62
+ `--vision_policy table_quant` keeps conservative quality defaults for document/text while using quantized vision where appropriate for tables.
63
+
64
+ ## Browser / ORT Web (WASM-WebGPU)
65
+
66
+ Use `manifest.web.json` for session graph wiring.
67
+
68
+ - For constrained clients, prefer hybrid/server-assisted profiles in the manifest.
69
+ - Full in-browser loading of all graphs may exceed practical memory on many devices.
70
+
71
+ Minimal JS loading sketch:
72
+
73
+ ```ts
74
+ import * as ort from "onnxruntime-web";
75
+
76
+ const manifest = await fetch("manifest.web.json").then((r) => r.json());
77
+ const visionPath = manifest.graphs.vision; // or manifest.graphs.vision_quant
78
+ const session = await ort.InferenceSession.create(visionPath, {
79
+ executionProviders: ["webgpu"], // fallback to "wasm" when needed
80
+ });
81
+ ```
82
+
83
+ ## Hugging Face Model Repo Upload Tips
84
+
85
+ - Track `.onnx` and `.data` files with Git LFS.
86
+ - Upload all of `fp16/`, `quant/`, and both manifest files together.
87
+ - If a web app will fetch directly from this model repo, configure CORS on the app side accordingly.
88
+
89
+ ## License
90
+
91
+ This deployment artifact follows the upstream GLM-OCR license metadata (`MIT` at time of packaging).
92
+ Always verify upstream license/terms at: https://huggingface.co/zai-org/GLM-OCR
chat_template.jinja ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [gMASK]<sop>
2
+ {%- if tools -%}
3
+ <|system|>
4
+ # Tools
5
+
6
+ You may call one or more functions to assist with the user query.
7
+
8
+ You are provided with function signatures within <tools></tools> XML tags:
9
+ <tools>
10
+ {% for tool in tools %}
11
+ {{ tool | tojson(ensure_ascii=False) }}
12
+ {% endfor %}
13
+ </tools>
14
+
15
+ For each function call, output the function name and arguments within the following XML format:
16
+ <tool_call>{function-name}
17
+ <arg_key>{arg-key-1}</arg_key>
18
+ <arg_value>{arg-value-1}</arg_value>
19
+ <arg_key>{arg-key-2}</arg_key>
20
+ <arg_value>{arg-value-2}</arg_value>
21
+ ...
22
+ </tool_call>{%- endif -%}
23
+ {%- macro visible_text(content) -%}
24
+ {%- if content is string -%}
25
+ {{- content }}
26
+ {%- elif content is iterable and content is not mapping -%}
27
+ {%- for item in content -%}
28
+ {%- if item is mapping and item.type == 'text' -%}
29
+ {{- item.text }}
30
+ {%- elif item is mapping and (item.type == 'image' or 'image' in item) -%}
31
+ <|begin_of_image|><|image|><|end_of_image|>
32
+ {%- elif item is mapping and (item.type == 'video' or 'video' in item) -%}
33
+ <|begin_of_video|><|video|><|end_of_video|>
34
+ {%- elif item is string -%}
35
+ {{- item }}
36
+ {%- endif -%}
37
+ {%- endfor -%}
38
+ {%- else -%}
39
+ {{- content }}
40
+ {%- endif -%}
41
+ {%- endmacro -%}
42
+ {%- set ns = namespace(last_user_index=-1) %}
43
+ {%- for m in messages %}
44
+ {%- if m.role == 'user' %}
45
+ {% set ns.last_user_index = loop.index0 -%}
46
+ {%- endif %}
47
+ {%- endfor %}
48
+ {% for m in messages %}
49
+ {%- if m.role == 'user' -%}<|user|>
50
+ {% if m.content is string %}
51
+ {{ m.content }}
52
+ {%- else %}
53
+ {%- for item in m.content %}
54
+ {% if item.type == 'video' or 'video' in item %}
55
+ <|begin_of_video|><|video|><|end_of_video|>{% elif item.type == 'image' or 'image' in item %}
56
+ <|begin_of_image|><|image|><|end_of_image|>{% elif item.type == 'text' %}
57
+ {{ item.text }}
58
+ {%- endif %}
59
+ {%- endfor %}
60
+ {%- endif %}
61
+ {{- '/nothink' if (enable_thinking is defined and not enable_thinking and not visible_text(m.content).endswith("/nothink")) else '' -}}
62
+ {%- elif m.role == 'assistant' -%}
63
+ <|assistant|>
64
+ {%- set reasoning_content = '' %}
65
+ {%- set content = visible_text(m.content) %}
66
+ {%- if m.reasoning_content is string %}
67
+ {%- set reasoning_content = m.reasoning_content %}
68
+ {%- else %}
69
+ {%- if '</think>' in content %}
70
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
71
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
72
+ {%- endif %}
73
+ {%- endif %}
74
+ {%- if loop.index0 > ns.last_user_index and reasoning_content -%}
75
+ {{ '\n<think>' + reasoning_content.strip() + '</think>'}}
76
+ {%- else -%}
77
+ {{ '\n<think></think>' }}
78
+ {%- endif -%}
79
+ {%- if content.strip() -%}
80
+ {{ '\n' + content.strip() }}
81
+ {%- endif -%}
82
+ {% if m.tool_calls %}
83
+ {% for tc in m.tool_calls %}
84
+ {%- if tc.function %}
85
+ {%- set tc = tc.function %}
86
+ {%- endif %}
87
+ {{ '\n<tool_call>' + tc.name }}
88
+ {% set _args = tc.arguments %}
89
+ {% for k, v in _args.items() %}
90
+ <arg_key>{{ k }}</arg_key>
91
+ <arg_value>{{ v | tojson(ensure_ascii=False) if v is not string else v }}</arg_value>
92
+ {% endfor %}
93
+ </tool_call>{% endfor %}
94
+ {% endif %}
95
+ {%- elif m.role == 'tool' -%}
96
+ {%- if m.content is string -%}
97
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
98
+ {{- '<|observation|>' }}
99
+ {%- endif %}
100
+ {{- '\n<tool_response>\n' }}
101
+ {{- m.content }}
102
+ {{- '\n</tool_response>' }}
103
+ {% elif m.content is iterable and m.content is not mapping %}
104
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
105
+ {{- '<|observation|>' }}
106
+ {%- endif %}
107
+ {{- '\n<tool_response>\n' }}
108
+ {%- for tr in m.content -%}
109
+ {%- if tr is mapping and tr.type is defined -%}
110
+ {%- set t = tr.type | lower -%}
111
+ {%- if t == 'text' and tr.text is defined -%}
112
+ {{ tr.text }}
113
+ {%- elif t in ['image', 'image_url'] -%}
114
+ <|begin_of_image|><|image|><|end_of_image|>
115
+ {%- elif t in ['video', 'video_url'] -%}
116
+ <|begin_of_video|><|video|><|end_of_video|>
117
+ {%- else -%}
118
+ {{ tr | tojson(ensure_ascii=False) }}
119
+ {%- endif -%}
120
+ {%- else -%}
121
+ {{ tr.output if tr.output is defined else tr }}
122
+ {%- endif -%}
123
+ {%- endfor -%}
124
+ {{- '\n</tool_response>' }}
125
+ {%- else -%}
126
+ <|observation|>{% for tr in m.content %}
127
+
128
+ <tool_response>
129
+ {{ tr.output if tr.output is defined else tr }}
130
+ </tool_response>{% endfor -%}
131
+ {% endif -%}
132
+ {%- elif m.role == 'system' -%}
133
+ <|system|>
134
+ {{ visible_text(m.content) }}
135
+ {%- endif -%}
136
+ {%- endfor -%}
137
+ {%- if add_generation_prompt -%}
138
+ <|assistant|>
139
+ {{'<think></think>\n' if (enable_thinking is defined and not enable_thinking) else ''}}
140
+ {%- endif -%}
config.json ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "GlmOcrForConditionalGeneration"
4
+ ],
5
+ "model_type": "glm_ocr",
6
+ "text_config": {
7
+ "model_type": "glm_ocr_text",
8
+ "pad_token_id": 59246,
9
+ "vocab_size": 59392,
10
+ "eos_token_id": [
11
+ 59246,
12
+ 59253
13
+ ],
14
+ "attention_bias": false,
15
+ "attention_dropout": 0.0,
16
+ "head_dim": 128,
17
+ "hidden_act": "silu",
18
+ "hidden_size": 1536,
19
+ "initializer_range": 0.02,
20
+ "intermediate_size": 4608,
21
+ "max_position_embeddings": 131072,
22
+ "num_attention_heads": 16,
23
+ "num_hidden_layers": 16,
24
+ "num_nextn_predict_layers": 1,
25
+ "num_key_value_heads": 8,
26
+ "rms_norm_eps": 1e-05,
27
+ "dtype": "bfloat16",
28
+ "rope_parameters": {
29
+ "rope_type": "default",
30
+ "mrope_section": [
31
+ 16,
32
+ 24,
33
+ 24
34
+ ],
35
+ "partial_rotary_factor": 1.0,
36
+ "rope_theta": 10000
37
+ },
38
+ "tie_word_embeddings": false,
39
+ "use_cache": true
40
+ },
41
+ "vision_config": {
42
+ "model_type": "glm_ocr_vision",
43
+ "hidden_size": 1024,
44
+ "depth": 24,
45
+ "num_heads": 16,
46
+ "attention_bias": true,
47
+ "intermediate_size": 4096,
48
+ "hidden_act": "silu",
49
+ "hidden_dropout_prob": 0.0,
50
+ "initializer_range": 0.02,
51
+ "image_size": 336,
52
+ "patch_size": 14,
53
+ "out_hidden_size": 1536,
54
+ "rms_norm_eps": 1e-05,
55
+ "spatial_merge_size": 2,
56
+ "temporal_patch_size": 2
57
+ },
58
+ "image_start_token_id": 59256,
59
+ "image_end_token_id": 59257,
60
+ "video_start_token_id": 59258,
61
+ "video_end_token_id": 59259,
62
+ "image_token_id": 59280,
63
+ "video_token_id": 59281,
64
+ "transformers_version": "5.0.1dev0"
65
+ }
fp16/glm_ocr_decode_prefill_kv.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e469aac93dff5835c621d1e7a8987aa802b112d8092b780d4742a317534cd627
3
+ size 2551204
fp16/glm_ocr_decode_prefill_kv.onnx.data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd63f01dac7b06ee4920b7c90d38cfc081988f1eb93b04eaa684c6e923e5f360
3
+ size 846466048
fp16/glm_ocr_decode_step_kv.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cea69c66eee2ca5e2e1e62185fd50bae0b431735027d107d070a4d8e02f4a318
3
+ size 4162536
fp16/glm_ocr_decode_step_kv.onnx.data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b3a254982459a269a566bdcaa574f9edb4c77fb470c0745e32a36e6ecc1ca927
3
+ size 2328349696
fp16/glm_ocr_embed.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:700497f7747ce77b2b34f519b662d2bee68f44e638de9391301a74011fd2bf20
3
+ size 1791
fp16/glm_ocr_embed.onnx.data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44c2c5e0a2a8d65605f06897249a03fb1d11051aee155ba598e1d1a302ababd0
3
+ size 364904448
fp16/glm_ocr_rope_document.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:57bbac5220e5828a5ea0bf901974bc44afa190e3e7d9927bceca3ca8a63c4dc3
3
+ size 4170
fp16/glm_ocr_rope_document.onnx.data ADDED
Binary file (98.3 kB). View file
 
fp16/glm_ocr_rope_formula.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de0c135e8dd941ec1a0246384d20c20984eb2bbed8fd08b43830ba40c081f232
3
+ size 4169
fp16/glm_ocr_rope_formula.onnx.data ADDED
Binary file (98.3 kB). View file
 
fp16/glm_ocr_rope_table.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:88faf6507c9baa52f4069b4a6469c5ab692038a538ef3d9df52ad2408648ba22
3
+ size 4167
fp16/glm_ocr_rope_table.onnx.data ADDED
Binary file (98.3 kB). View file
 
fp16/glm_ocr_rope_text.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b68daba410b29a635de18b135212569db1c28add28fbe7c5b63dcd0c7b3d0b63
3
+ size 4166
fp16/glm_ocr_rope_text.onnx.data ADDED
Binary file (98.3 kB). View file
 
fp16/glm_ocr_vision.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:efa009d7c358e4ebf83515b80a96fd828a05e40bd86be190dfabd9fc0f29bc73
3
+ size 715251
fp16/glm_ocr_vision.onnx.data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8691969b71702daabc378e031b66c62d13d054a7cfed17e2729ea707079d2b45
3
+ size 14571213824
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "do_sample": false,
4
+ "eos_token_id": [
5
+ 59246,
6
+ 59253
7
+ ],
8
+ "pad_token_id": 59246,
9
+ "transformers_version": "5.0.1dev0"
10
+ }
manifest.json ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_id": "zai-org/GLM-OCR",
3
+ "dtype": "float16",
4
+ "opset": 18,
5
+ "static": true,
6
+ "external_data": true,
7
+ "image_size": {
8
+ "width": 840,
9
+ "height": 840
10
+ },
11
+ "max_seq_len": 2048,
12
+ "image_token_id": 59280,
13
+ "eos_token_ids": [
14
+ 59246,
15
+ 59253
16
+ ],
17
+ "export_prompt": "Recognize the text in the image and output in Markdown format. Preserve the original layout (headings/paragraphs/tables/formulas). Do not fabricate content that does not exist in the image.",
18
+ "hidden_size": 1536,
19
+ "t_img": 900,
20
+ "export_devices": {
21
+ "vision": "cuda",
22
+ "text": "cuda"
23
+ },
24
+ "graphs": {
25
+ "vision": "fp16/glm_ocr_vision.onnx",
26
+ "embed": "fp16/glm_ocr_embed.onnx",
27
+ "rope": "fp16/glm_ocr_rope_document.onnx",
28
+ "decode_prefill_kv": "fp16/glm_ocr_decode_prefill_kv.onnx",
29
+ "decode_step_kv": "fp16/glm_ocr_decode_step_kv.onnx",
30
+ "vision_quant": "quant/glm_ocr_vision_quant.onnx"
31
+ },
32
+ "kv_cache": {
33
+ "num_layers": 16,
34
+ "num_key_value_heads": 8,
35
+ "head_dim": 96,
36
+ "max_cache_len": 2048
37
+ },
38
+ "default_profile": "document",
39
+ "prompt_profiles": {
40
+ "document": {
41
+ "prompt": "Recognize the text in the image and output in Markdown format. Preserve the original layout (headings/paragraphs/tables/formulas). Do not fabricate content that does not exist in the image.",
42
+ "rope": "fp16/glm_ocr_rope_document.onnx"
43
+ },
44
+ "text": {
45
+ "prompt": "Text Recognition:",
46
+ "rope": "fp16/glm_ocr_rope_text.onnx"
47
+ },
48
+ "table": {
49
+ "prompt": "Table Recognition:",
50
+ "rope": "fp16/glm_ocr_rope_table.onnx"
51
+ },
52
+ "formula": {
53
+ "prompt": "Formula Recognition:",
54
+ "rope": "fp16/glm_ocr_rope_formula.onnx"
55
+ }
56
+ },
57
+ "notes": [
58
+ "Vision wrapper handles packed [T,D] outputs by unsqueezing to [1,T,D].",
59
+ "Rope graphs are prompt-profile specific constants generated from get_rope_index (mRoPE).",
60
+ "Do splice in JS: replace contiguous image_token_id block of length t_img with image_embeds.",
61
+ "Decode outputs logits for last token only.",
62
+ "custom_w8: quantized MatMul/Gemm weights for graph 'decode_prefill_kv'.",
63
+ "dual-vision artifact: graphs.vision=fp16 and graphs.vision_quant=quantized."
64
+ ],
65
+ "vision": {
66
+ "onnx": "artifact_glm_ocr_web_split/fp16/glm_ocr_vision.onnx",
67
+ "sha256": "efa009d7c358e4ebf83515b80a96fd828a05e40bd86be190dfabd9fc0f29bc73",
68
+ "bytes": 715251,
69
+ "data": "artifact_glm_ocr_web_split/fp16/glm_ocr_vision.onnx.data",
70
+ "data_sha256": "8691969b71702daabc378e031b66c62d13d054a7cfed17e2729ea707079d2b45",
71
+ "data_bytes": 14571213824
72
+ },
73
+ "embed": {
74
+ "onnx": "artifact_glm_ocr_web_split/fp16/glm_ocr_embed.onnx",
75
+ "sha256": "700497f7747ce77b2b34f519b662d2bee68f44e638de9391301a74011fd2bf20",
76
+ "bytes": 1791,
77
+ "data": "artifact_glm_ocr_web_split/fp16/glm_ocr_embed.onnx.data",
78
+ "data_sha256": "44c2c5e0a2a8d65605f06897249a03fb1d11051aee155ba598e1d1a302ababd0",
79
+ "data_bytes": 364904448
80
+ },
81
+ "rope": {
82
+ "onnx": "artifact_glm_ocr_web_split/fp16/glm_ocr_rope_document.onnx",
83
+ "sha256": "57bbac5220e5828a5ea0bf901974bc44afa190e3e7d9927bceca3ca8a63c4dc3",
84
+ "bytes": 4170,
85
+ "data": "artifact_glm_ocr_web_split/fp16/glm_ocr_rope_document.onnx.data",
86
+ "data_sha256": "cb38103e3aceeb1adeb7104611bd035656dd8433b3c03eb96ac2b5e5df9b55b4",
87
+ "data_bytes": 98304
88
+ },
89
+ "decode": {
90
+ "onnx": "artifact_glm_ocr_web_split/fp16/glm_ocr_decode.onnx",
91
+ "sha256": "6d536a5b1e671e2229bb88a050c747ad6fdc9db3292927af4552c33928a46001",
92
+ "bytes": 2429565,
93
+ "data": "artifact_glm_ocr_web_split/fp16/glm_ocr_decode.onnx.data",
94
+ "data_sha256": "6847fe2bfe59df72975856dc61730b2ecb8a0f79455a898375fc4f7c2c7cb2da",
95
+ "data_bytes": 2328431616
96
+ },
97
+ "decode_prefill_kv": {
98
+ "onnx": "artifact_glm_ocr_web_split/fp16/glm_ocr_decode_prefill_kv.onnx",
99
+ "sha256": "27974f2680f37205f1a51244dbe7fc65e0eefbcf926a3fc9e7a34a5095d4a755",
100
+ "bytes": 2547577,
101
+ "data": "artifact_glm_ocr_web_split/fp16/glm_ocr_decode_prefill_kv.onnx.data",
102
+ "data_sha256": "6847fe2bfe59df72975856dc61730b2ecb8a0f79455a898375fc4f7c2c7cb2da",
103
+ "data_bytes": 2328431616
104
+ },
105
+ "decode_step_kv": {
106
+ "onnx": "artifact_glm_ocr_web_split/fp16/glm_ocr_decode_step_kv.onnx",
107
+ "sha256": "cea69c66eee2ca5e2e1e62185fd50bae0b431735027d107d070a4d8e02f4a318",
108
+ "bytes": 4162536,
109
+ "data": "artifact_glm_ocr_web_split/fp16/glm_ocr_decode_step_kv.onnx.data",
110
+ "data_sha256": "b3a254982459a269a566bdcaa574f9edb4c77fb470c0745e32a36e6ecc1ca927",
111
+ "data_bytes": 2328349696
112
+ },
113
+ "rope_document": {
114
+ "onnx": "artifact_glm_ocr_web_split/fp16/glm_ocr_rope_document.onnx",
115
+ "sha256": "57bbac5220e5828a5ea0bf901974bc44afa190e3e7d9927bceca3ca8a63c4dc3",
116
+ "bytes": 4170,
117
+ "data": "artifact_glm_ocr_web_split/fp16/glm_ocr_rope_document.onnx.data",
118
+ "data_sha256": "cb38103e3aceeb1adeb7104611bd035656dd8433b3c03eb96ac2b5e5df9b55b4",
119
+ "data_bytes": 98304
120
+ },
121
+ "rope_text": {
122
+ "onnx": "artifact_glm_ocr_web_split/fp16/glm_ocr_rope_text.onnx",
123
+ "sha256": "b68daba410b29a635de18b135212569db1c28add28fbe7c5b63dcd0c7b3d0b63",
124
+ "bytes": 4166,
125
+ "data": "artifact_glm_ocr_web_split/fp16/glm_ocr_rope_text.onnx.data",
126
+ "data_sha256": "4147cb50328e4bb79a289496b2d0dea536c02898fc62591fad72da0b636a33ee",
127
+ "data_bytes": 98304
128
+ },
129
+ "rope_table": {
130
+ "onnx": "artifact_glm_ocr_web_split/fp16/glm_ocr_rope_table.onnx",
131
+ "sha256": "88faf6507c9baa52f4069b4a6469c5ab692038a538ef3d9df52ad2408648ba22",
132
+ "bytes": 4167,
133
+ "data": "artifact_glm_ocr_web_split/fp16/glm_ocr_rope_table.onnx.data",
134
+ "data_sha256": "4147cb50328e4bb79a289496b2d0dea536c02898fc62591fad72da0b636a33ee",
135
+ "data_bytes": 98304
136
+ },
137
+ "rope_formula": {
138
+ "onnx": "artifact_glm_ocr_web_split/fp16/glm_ocr_rope_formula.onnx",
139
+ "sha256": "de0c135e8dd941ec1a0246384d20c20984eb2bbed8fd08b43830ba40c081f232",
140
+ "bytes": 4169,
141
+ "data": "artifact_glm_ocr_web_split/fp16/glm_ocr_rope_formula.onnx.data",
142
+ "data_sha256": "2929c9761dd6510fa6734a2ded0bd07d7b8f2705072a0542e76b7ccda9c0f713",
143
+ "data_bytes": 98304
144
+ }
145
+ }
manifest.web.json ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_id": "zai-org/GLM-OCR",
3
+ "dtype": "float16",
4
+ "opset": 18,
5
+ "max_seq_len": 2048,
6
+ "image_size": {
7
+ "width": 840,
8
+ "height": 840
9
+ },
10
+ "image_token_id": 59280,
11
+ "eos_token_ids": [
12
+ 59246,
13
+ 59253
14
+ ],
15
+ "kv_cache": {
16
+ "num_layers": 16,
17
+ "num_key_value_heads": 8,
18
+ "head_dim": 96,
19
+ "max_cache_len": 2048
20
+ },
21
+ "prompt_profile": "document",
22
+ "base_url": "./",
23
+ "graphs": {
24
+ "vision": "fp16/glm_ocr_vision.onnx",
25
+ "embed": "fp16/glm_ocr_embed.onnx",
26
+ "rope": "fp16/glm_ocr_rope_document.onnx",
27
+ "decode_prefill_kv": "fp16/glm_ocr_decode_prefill_kv.onnx",
28
+ "decode_step_kv": "fp16/glm_ocr_decode_step_kv.onnx",
29
+ "vision_quant": "quant/glm_ocr_vision_quant.onnx"
30
+ },
31
+ "runtime": {
32
+ "webgpu": {
33
+ "executionProviders": [
34
+ "webgpu"
35
+ ],
36
+ "logSeverityLevel": 3
37
+ },
38
+ "wasm": {
39
+ "executionProviders": [
40
+ "wasm"
41
+ ],
42
+ "logSeverityLevel": 3
43
+ }
44
+ },
45
+ "profiles": {
46
+ "full_browser_kv": {
47
+ "description": "All sessions in browser, KV prefill+step decoding.",
48
+ "graphs": [
49
+ "vision",
50
+ "embed",
51
+ "rope",
52
+ "decode_prefill_kv",
53
+ "decode_step_kv"
54
+ ],
55
+ "requires_image_embeds_input": false,
56
+ "estimated_weight_gb": 18.254
57
+ },
58
+ "hybrid_server_vision_client_kv": {
59
+ "description": "Vision/image embedding runs on server; browser runs text decode with KV.",
60
+ "graphs": [
61
+ "embed",
62
+ "rope",
63
+ "decode_prefill_kv",
64
+ "decode_step_kv"
65
+ ],
66
+ "requires_image_embeds_input": true,
67
+ "estimated_weight_gb": 4.683
68
+ },
69
+ "hybrid_server_vision_client_prefill_only": {
70
+ "description": "Vision on server; browser uses decode_prefill_kv only (simpler, slower token loop).",
71
+ "graphs": [
72
+ "embed",
73
+ "rope",
74
+ "decode_prefill_kv"
75
+ ],
76
+ "requires_image_embeds_input": true,
77
+ "estimated_weight_gb": 2.511
78
+ }
79
+ },
80
+ "load_order": [
81
+ "vision",
82
+ "vision_quant",
83
+ "embed",
84
+ "rope",
85
+ "decode_prefill_kv",
86
+ "decode_step_kv"
87
+ ],
88
+ "memory_budget_gb": {
89
+ "full_browser_kv": 18.254,
90
+ "full_browser_prefill_only": 16.082,
91
+ "hybrid_server_vision_client_kv": 4.683,
92
+ "hybrid_server_vision_client_prefill_only": 2.511
93
+ },
94
+ "per_graph_size_gb": {
95
+ "vision": 13.571,
96
+ "embed": 0.34,
97
+ "rope_profile": 0.0,
98
+ "decode_prefill_kv": 2.171,
99
+ "decode_step_kv": 2.172,
100
+ "vision_quant": 0.0
101
+ },
102
+ "warnings": [
103
+ "vision is 13.57 GB; likely too large for direct browser startup on most clients.",
104
+ "decode_prefill_kv is 2.17 GB; likely too large for direct browser startup on most clients.",
105
+ "decode_step_kv is 2.17 GB; likely too large for direct browser startup on most clients."
106
+ ],
107
+ "notes": [
108
+ "This manifest is for ORT Web (WebGPU/WASM) session wiring.",
109
+ "Prefer lazy session creation; do not load unused graphs.",
110
+ "Use rope graph matching the exported prompt profile.",
111
+ "For browser deployments, hybrid mode is usually required at current model size."
112
+ ]
113
+ }
preprocessor_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "size": {"shortest_edge": 12544, "longest_edge": 9633792},
3
+ "do_rescale": true,
4
+ "patch_size": 14,
5
+ "temporal_patch_size": 2,
6
+ "merge_size": 2,
7
+ "image_mean": [0.48145466, 0.4578275, 0.40821073],
8
+ "image_std": [0.26862954, 0.26130258, 0.27577711],
9
+ "image_processor_type": "Glm46VImageProcessor",
10
+ "processor_class": "Glm46VProcessor"
11
+ }
quant/glm_ocr_vision_quant.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3daf41d962e7878703682f8aed901bc697d1e9652e148c21decef39691750702
3
+ size 767365
quant/glm_ocr_vision_quant.onnx.data ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fdfd0d65846923674dc0ae0c18c30d09dfb4752125fb93c45b68ae6c4fb7b264
3
+ size 490746880
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "clean_up_tokenization_spaces": false,
4
+ "eos_token": "<|endoftext|>",
5
+ "extra_special_tokens": [
6
+ "<|endoftext|>",
7
+ "[MASK]",
8
+ "[gMASK]",
9
+ "[sMASK]",
10
+ "<sop>",
11
+ "<eop>",
12
+ "<|system|>",
13
+ "<|user|>",
14
+ "<|assistant|>",
15
+ "<|observation|>",
16
+ "<|begin_of_image|>",
17
+ "<|end_of_image|>",
18
+ "<|begin_of_video|>",
19
+ "<|end_of_video|>",
20
+ "<|begin_of_audio|>",
21
+ "<|end_of_audio|>",
22
+ "<|begin_of_transcription|>",
23
+ "<|end_of_transcription|>",
24
+ "<|code_prefix|>",
25
+ "<|code_middle|>",
26
+ "<|code_suffix|>",
27
+ "<think>",
28
+ "</think>",
29
+ "<tool_call>",
30
+ "</tool_call>",
31
+ "<tool_response>",
32
+ "</tool_response>",
33
+ "<arg_key>",
34
+ "</arg_key>",
35
+ "<arg_value>",
36
+ "</arg_value>",
37
+ "/nothink",
38
+ "<|begin_of_box|>",
39
+ "<|end_of_box|>",
40
+ "<|image|>",
41
+ "<|video|>"
42
+ ],
43
+ "is_local": true,
44
+ "model_max_length": 655380,
45
+ "pad_token": "<|endoftext|>",
46
+ "padding_side": "left",
47
+ "processor_class": "Glm46VProcessor",
48
+ "tokenizer_class": "TokenizersBackend"
49
+ }