MinerU2.5-Pro -> Core AI: vision (fp16) + decoder (int8lin S=1) + tokenizer
Browse files
README.md
CHANGED
|
@@ -38,11 +38,13 @@ Apache-2.0.
|
|
| 38 |
|
| 39 |
## Verified (M4 Max, GPU, Core AI pipelined engine)
|
| 40 |
|
| 41 |
-
- **End-to-end real generation on the engine: the sample page read
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
- Torch ladder vs HF fp32: text-only + vision + full-VLM argmax **706/706 exact**, max logit diff
|
| 47 |
**0.0001**, the generation-driving token bit-identical.
|
| 48 |
- Engine gate (Mac GPU): vision `image_embeds` cos **1.0002**; AOT int8lin decoder teacher-forced over
|
|
@@ -50,23 +52,37 @@ Apache-2.0.
|
|
| 50 |
- **int8lin vs fp16: 13 / 706 argmax flips, all at visual-token positions (0 in the text region)** —
|
| 51 |
the OCR text is preserved. Greedy generation byte-identical to fp16.
|
| 52 |
|
| 53 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
```
|
| 56 |
-
page image
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
shift_amount=N−max(gh,gw))
|
| 63 |
-
prompt by type: text → "Text Recognition:" · table → "Table Recognition:"
|
| 64 |
-
formula → "Formula Recognition:" · figure → "Image Analysis:"
|
| 65 |
-
→ assemble content_list (type + text) in reading order → json2md → Markdown / JSON
|
| 66 |
```
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
## Use / reproduce
|
| 72 |
|
|
|
|
| 38 |
|
| 39 |
## Verified (M4 Max, GPU, Core AI pipelined engine)
|
| 40 |
|
| 41 |
+
- **End-to-end real generation on the engine (shipped portrait 768 config): the sample page read
|
| 42 |
+
verbatim** — letterbox → CLIP-norm → non-square patchify → GPU vision `.aimodel` → `image_embeds`
|
| 43 |
+
→ AOT-compiled (h16c) int8lin S=1 decoder, autoregressive greedy: title + paragraph + the **full
|
| 44 |
+
table reconstructed row-by-row** (*"Quarterly Report / On-device inference shipped across all
|
| 45 |
+
product lines this quarter… / Whisper 809M 0.18 s/token / …"*), matching the fp32 reference.
|
| 46 |
+
**211.7 tok/s** decode (int8lin S=1, AOT h16c GPU). Portrait vision vs HF: per-token cos min
|
| 47 |
+
**0.9975**.
|
| 48 |
- Torch ladder vs HF fp32: text-only + vision + full-VLM argmax **706/706 exact**, max logit diff
|
| 49 |
**0.0001**, the generation-driving token bit-identical.
|
| 50 |
- Engine gate (Mac GPU): vision `image_embeds` cos **1.0002**; AOT int8lin decoder teacher-forced over
|
|
|
|
| 52 |
- **int8lin vs fp16: 13 / 706 argmax flips, all at visual-token positions (0 in the text region)** —
|
| 53 |
the OCR text is preserved. Greedy generation byte-identical to fp16.
|
| 54 |
|
| 55 |
+
## Run in app — `KitMineruReader` (iPhone + Mac)
|
| 56 |
+
|
| 57 |
+
The shipped bundle rides the kit's VL rope-shift runtime (`VLRuntime` + `VLArchitecture.mineru`).
|
| 58 |
+
The page is letterboxed (aspect-fit + white pad) into a **fixed 672×896 portrait canvas**, CLIP-
|
| 59 |
+
normalized, and non-square-patchified into a **32×24 merged grid (768 visual tokens)** — the
|
| 60 |
+
`VLImagePreprocessor` non-square path added for Qwen2-VL. Two calls:
|
| 61 |
+
|
| 62 |
+
```swift
|
| 63 |
+
let reader = try await KitMineruReader(catalog: "mineru2.5-pro")
|
| 64 |
+
let markdown = try await reader.read(imageAt: documentURL) // "Text Recognition:" whole-page
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
v1 is a single whole-page `"Text Recognition:"` pass (correct for clean single-column pages). The
|
| 68 |
+
2-stage layout→region pipeline is a follow-up.
|
| 69 |
+
|
| 70 |
+
## Pipeline (host side)
|
| 71 |
|
| 72 |
```
|
| 73 |
+
page image → letterbox into 672×896 (aspect-fit + white pad) → CLIP-normalize
|
| 74 |
+
→ non-square patchify [3072, 1176] (block-major, 64×48 patches)
|
| 75 |
+
→ vision .aimodel → image_embeds [768, 896]
|
| 76 |
+
→ prompt: [ <|vision_start|>, <image>×768, <|vision_end|>, "Text Recognition:" ]
|
| 77 |
+
(image ids → V+slot; shift_start = img_start+768, shift_amount = 768−32 = 736)
|
| 78 |
+
→ decoder S=1 pipelined greedy decode → tokens → detokenize → markdown / <table>HTML / LaTeX
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
```
|
| 80 |
|
| 81 |
+
The full 2-stage whole-page mode (layout boxes → per-region crop → recognition → `json2md`) follows
|
| 82 |
+
[`opendatalab/mineru-vl-utils`](https://github.com/opendatalab/mineru-vl-utils)
|
| 83 |
+
(`MinerUClient.two_step_extract` + `post_process.json2md`) — prompts by type: text →
|
| 84 |
+
`"Text Recognition:"` · table → `"Table Recognition:"` · formula → `"Formula Recognition:"` ·
|
| 85 |
+
figure → `"Image Analysis:"`.
|
| 86 |
|
| 87 |
## Use / reproduce
|
| 88 |
|
decoder/metadata.json
CHANGED
|
@@ -22,7 +22,7 @@
|
|
| 22 |
},
|
| 23 |
"compression": null,
|
| 24 |
"compilation": {
|
| 25 |
-
"date": "2026-07-
|
| 26 |
"targets": []
|
| 27 |
}
|
| 28 |
}
|
|
|
|
| 22 |
},
|
| 23 |
"compression": null,
|
| 24 |
"compilation": {
|
| 25 |
+
"date": "2026-07-04T12:29:12.769162+00:00",
|
| 26 |
"targets": []
|
| 27 |
}
|
| 28 |
}
|
decoder/mineru_decode_int8lin_s1.aimodel/main.hash
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
�|��U�Пv8Yΰ������t�`�-�C
|
decoder/mineru_decode_int8lin_s1.aimodel/main.mlirb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e77cc08b55e8d09f763859ceb08adffe07f7bec374d01d60d82de9430804181d
|
| 3 |
+
size 652928607
|
vision/mineru_vision.aimodel/main.hash
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
�
|
|
|
|
| 1 |
+
%@d��蠹(Z�7�VS��G�U�Q����R�!
|
vision/mineru_vision.aimodel/main.mlirb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:254064daf8e8a0b90f285aeb37d55653abc847ae1a559551bb81dcecb0529a21
|
| 3 |
+
size 1325199338
|