Add layout (1036 square) bundle + recognition pf64 for the 2-stage structured pipeline
Browse filesFiles changed (19)
- .gitattributes+4
- README.md+34-11
- decoder/mineru_decode_int8lin_pf64.aimodel/main.hashAdded+1
- decoder/mineru_decode_int8lin_pf64.aimodel/main.mlirbAdded+3
- decoder/mineru_decode_int8lin_pf64.aimodel/metadata.jsonAdded+3
- layout/decoder/metadata.jsonAdded+29
- layout/decoder/mineru_decode_int8lin_pf64.aimodel/main.hashAdded
- layout/decoder/mineru_decode_int8lin_pf64.aimodel/main.mlirbAdded+3
- layout/decoder/mineru_decode_int8lin_pf64.aimodel/metadata.jsonAdded+3
- layout/decoder/tokenizer/added_tokens.jsonAdded+33
- layout/decoder/tokenizer/chat_template.jinjaAdded+7
- layout/decoder/tokenizer/merges.txtAdded
- layout/decoder/tokenizer/special_tokens_map.jsonAdded+48
- layout/decoder/tokenizer/tokenizer.jsonAdded+3
- layout/decoder/tokenizer/tokenizer_config.jsonAdded+297
- layout/decoder/tokenizer/vocab.jsonAdded
- layout/vision/mineru_vision.aimodel/main.hashAdded+2
- layout/vision/mineru_vision.aimodel/main.mlirbAdded+3
- layout/vision/mineru_vision.aimodel/metadata.jsonAdded+3
36 unmodified lines37383936 unmodified linesdecoder/tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -texttokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -textvision/mineru_vision.aimodel/main.mlirb filter=lfs diff=lfs merge=lfs -text36 unmodified lines3738394041424336 unmodified linesdecoder/tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -texttokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -textvision/mineru_vision.aimodel/main.mlirb filter=lfs diff=lfs merge=lfs -textdecoder/mineru_decode_int8lin_pf64.aimodel/main.mlirb filter=lfs diff=lfs merge=lfs -textlayout/decoder/mineru_decode_int8lin_pf64.aimodel/main.mlirb filter=lfs diff=lfs merge=lfs -textlayout/decoder/tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -textlayout/vision/mineru_vision.aimodel/main.mlirb filter=lfs diff=lfs merge=lfs -text
17 unmodified lines181920212223242510 unmodified lines36373839404142438 unmodified lines525354555657585960616263646566676869707117 unmodified lines**⬇️ Converted `.aimodel` bundles:[mlboydaisuke/MinerU2.5-Pro-CoreAI](https://huggingface.co/mlboydaisuke/MinerU2.5-Pro-CoreAI)** —`vision/` (Qwen2-VL ViT, fp16) + `decoder/` (Qwen2 decoder, S=1 pipelined, int8lin) + `tokenizer/`.Apache-2.0.## Architecture10 unmodified lines+ `rope_shift_start` + `rope_shift_amount`. Zero embeds + `shift_start = 1<<30` → a plain Qwen2 textdecoder.## Verified (M4 Max, GPU, Core AI pipelined engine)- **End-to-end real generation on the engine (shipped portrait 768 config): the sample page readverbatim** — letterbox → CLIP-norm → non-square patchify → GPU vision `.aimodel` → `image_embeds`→ AOT-compiled (h16c) int8lin S=1 decoder, autoregressive greedy: title + paragraph + the **full8 unmodified lines- **int8lin vs fp16: 13 / 706 argmax flips, all at visual-token positions (0 in the text region)** —the OCR text is preserved. Greedy generation byte-identical to fp16.## Run in app — `KitMineruReader` (iPhone + Mac)The shipped bundle rides the kit's VL rope-shift runtime (`VLRuntime` + `VLArchitecture.mineru`).The page is letterboxed (aspect-fit + white pad) into a **fixed 672×896 portrait canvas**, CLIP-normalized, and non-square-patchified into a **32×24 merged grid (768 visual tokens)** — the`VLImagePreprocessor` non-square path added for Qwen2-VL. Two calls:```swiftlet reader = try await KitMineruReader(catalog: "mineru2.5-pro")let markdown = try await reader.read(imageAt: documentURL) // "Text Recognition:" whole-page```v1 is a single whole-page `"Text Recognition:"` pass (correct for clean single-column pages). The2-stage layout→region pipeline is a follow-up.## Pipeline (host side)17 unmodified lines18192021222324252610 unmodified lines373839404142434445464748498 unmodified lines5859606162636465666768697071727374757677787980818283848586878889909192939417 unmodified lines**⬇️ Converted `.aimodel` bundles:[mlboydaisuke/MinerU2.5-Pro-CoreAI](https://huggingface.co/mlboydaisuke/MinerU2.5-Pro-CoreAI)** —`vision/` + `decoder/` (768-token **recognition** grid, Qwen2-VL ViT fp16 + int8lin decoder, pf64chunked prefill) + `layout/` (a 1036² **square** recognition/detection grid for the 2-stage) +`tokenizer/`. Apache-2.0.## Architecture10 unmodified lines+ `rope_shift_start` + `rope_shift_amount`. Zero embeds + `shift_start = 1<<30` → a plain Qwen2 textdecoder.## Verified (M4 Max + iPhone 17 Pro, GPU, Core AI pipelined engine)- **iPhone 17 Pro, on-device, whole page read correctly** — the h18p AOT bundles run through`KitMineruReader` in a real app (ReadDoc): a page photo → structured text (headings, paragraphs,tables) with nothing leaving the device. **~4 s/page** (warm) via **chunked prefill**: the `pf64`multifunction bundle feeds the 768 image tokens in **static S=64 chunks** (the engine auto-discoversthe `prefill` function) then decodes S=1 — the S=1 prefill (~10 s) drops to **~2.9 s**, no token cut.- **End-to-end real generation on the engine (shipped portrait 768 config): the sample page readverbatim** — letterbox → CLIP-norm → non-square patchify → GPU vision `.aimodel` → `image_embeds`→ AOT-compiled (h16c) int8lin S=1 decoder, autoregressive greedy: title + paragraph + the **full8 unmodified lines- **int8lin vs fp16: 13 / 706 argmax flips, all at visual-token positions (0 in the text region)** —the OCR text is preserved. Greedy generation byte-identical to fp16.## Run in app — `KitMineruReader` (Mac; iPhone single-pass)Both grids ride the kit's VL rope-shift runtime (`VLRuntime`). Pages are CLIP-normalized andpatchified (the `VLImagePreprocessor` non-square + `.stretch`/`.aspectFitPad` paths added forQwen2-VL). Two entry points:```swift// Single-pass (768 grid): whole page → plain text (reading order). Runs on iPhone (chunked prefill).let reader = try await KitMineruReader(catalog: "mineru2.5-pro")let text = try await reader.read(imageAt: documentURL)// 2-stage (structured Markdown, tables as <table> HTML). Needs the layout bundle too.let reader = try await KitMineruReader(visionDir: rec.vision, decoderDir: rec.decoder,layoutVisionDir: layout.vision, layoutDecoderDir: layout.decoder)let markdown = try await reader.readStructured(imageAt: documentURL)```**2-stage** (`readStructured`, mirrors `mineru-vl-utils` `two_step_extract` + `json2md`):1. **Layout** on the page **stretched into 1036² square** (`VLArchitecture.mineruLayout`, 37×37 = 1369tokens) → `Layout Detection:` emits `<|box_start|>…<|ref_start|>type…` blocks. A 768 portrait gridmis-detects here — the square high-res grid is required. Boxes are 0–1 of the square, so they maplinearly onto the original page.2. **Recognition** per region on the **768 grid** (`.mineru`): each block is cropped from the originaland read by type — `Table Recognition:` emits **OTSL** (`<fcel>`/`<nl>`), kept (not skipped) andconverted to `<table>` HTML; `Formula Recognition:` → LaTeX; else plain text.3. **json2md** joins the region contents in reading order.Verified end-to-end in the ReadDoc Mac app: an 8-block page → title/paragraphs + a 5-row `<table>`,byte-identical to the reference. ~11 s load (both bundles) + ~11 s/page. The single-pass path alsoruns on iPhone; the 2-stage's 1036² layout grid is Mac-tier (two bundles, heavy).## Pipeline (host side)
1�6�]�����J�$<v5o��F`L�U�Ƃ��2�123version https://git-lfs.github.com/spec/v1oid sha256:a336f55dff7fb9c1b5c04afe243c76356ffe9646604c905595c682eba2f132e2size 653085537123{ "assetVersion" : "2.0"}1234567891011121314151617181920212223242526272829{ "metadata_version": "0.2", "kind": "llm", "name": "mineru_decode_int8lin_pf64", "assets": { "main": "mineru_decode_int8lin_pf64.aimodel" }, "language": { "tokenizer": "/Users/majimadaisuke/code/coreai/_mineru_dl", "vocab_size": 151936, "max_context_length": 4096, "embedded_tokenizer": true, "function_map": { "main": [ "main", "prefill" ] } }, "source": { "model_definition": "torch", "hf_model_id": "/Users/majimadaisuke/code/coreai/_mineru_dl" }, "compression": null, "compilation": { "date": "2026-07-06T07:41:10.859485+00:00", "targets": [] }}123version https://git-lfs.github.com/spec/v1oid sha256:aaf7110b227644975540b296a7fca01d625e3cc7edc394b9e1ec8b1a00c272b2size 653085540123{ "assetVersion" : "2.0"}123456789101112131415161718192021222324252627282930313233{ "<ched>": 151661, "<ecel>": 151662, "<fcel>": 151663, "<lcel>": 151664, "<nl>": 151667, "<ucel>": 151665, "<xcel>": 151666, "<|box_end|>": 151649, "<|box_start|>": 151648, "<|endoftext|>": 151643, "<|im_end|>": 151645, "<|im_start|>": 151644, "<|image_pad|>": 151655, "<|md_end|>": 151660, "<|md_start|>": 151659, "<|object_ref_end|>": 151647, "<|object_ref_start|>": 151646, "<|paratext|>": 151673, "<|quad_end|>": 151651, "<|quad_start|>": 151650, "<|ref_end|>": 151658, "<|ref_start|>": 151657, "<|rotate_down|>": 151669, "<|rotate_left|>": 151670, "<|rotate_right|>": 151671, "<|rotate_up|>": 151668, "<|txt_contd|>": 151672, "<|video_pad|>": 151656, "<|vision_end|>": 151653, "<|vision_pad|>": 151654, "<|vision_start|>": 151652}1234567{% set image_count = namespace(value=0) %}{% set video_count = namespace(value=0) %}{% for message in messages %}{% if loop.first and message['role'] != 'system' %}<|im_start|>systemYou are a helpful assistant.<|im_end|>{% endif %}<|im_start|>{{ message['role'] }}{% if message['content'] is string %}{{ message['content'] }}<|im_end|>{% else %}{% for content in message['content'] %}{% if content['type'] == 'image' or 'image' in content or 'image_url' in content %}{% set image_count.value = image_count.value + 1 %}{% if add_vision_id %}Picture {{ image_count.value }}: {% endif %}<|vision_start|><|image_pad|><|vision_end|>{% elif content['type'] == 'video' or 'video' in content %}{% set video_count.value = video_count.value + 1 %}{% if add_vision_id %}Video {{ video_count.value }}: {% endif %}<|vision_start|><|video_pad|><|vision_end|>{% elif 'text' in content %}{{ content['text'] }}{% endif %}{% endfor %}<|im_end|>{% endif %}{% endfor %}{% if add_generation_prompt %}<|im_start|>assistant{% endif %}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748{ "additional_special_tokens": [ "<|im_start|>", "<|im_end|>", "<|object_ref_start|>", "<|object_ref_end|>", "<|box_start|>", "<|box_end|>", "<|quad_start|>", "<|quad_end|>", "<|vision_start|>", "<|vision_end|>", "<|vision_pad|>", "<|image_pad|>", "<|video_pad|>", "<|ref_start|>", "<|ref_end|>", "<|md_start|>", "<|md_end|>", "<ched>", "<ecel>", "<fcel>", "<lcel>", "<ucel>", "<xcel>", "<nl>", "<|rotate_up|>", "<|rotate_down|>", "<|rotate_left|>", "<|rotate_right|>", "<|txt_contd|>", "<|paratext|>" ], "eos_token": { "content": "<|im_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }, "pad_token": { "content": "<|endoftext|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }}123version https://git-lfs.github.com/spec/v1oid sha256:dceac5fc54a795ee7570d17902b47bd05412dc2afa62bdf325c3f97fcb5b87fesize 11423550123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297{ "add_prefix_space": false, "added_tokens_decoder": { "151643": { "content": "<|endoftext|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151644": { "content": "<|im_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151645": { "content": "<|im_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151646": { "content": "<|object_ref_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151647": { "content": "<|object_ref_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151648": { "content": "<|box_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151649": { "content": "<|box_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151650": { "content": "<|quad_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151651": { "content": "<|quad_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151652": { "content": "<|vision_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151653": { "content": "<|vision_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151654": { "content": "<|vision_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151655": { "content": "<|image_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151656": { "content": "<|video_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151657": { "content": "<|ref_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151658": { "content": "<|ref_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151659": { "content": "<|md_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151660": { "content": "<|md_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151661": { "content": "<ched>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151662": { "content": "<ecel>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151663": { "content": "<fcel>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151664": { "content": "<lcel>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151665": { "content": "<ucel>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151666": { "content": "<xcel>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151667": { "content": "<nl>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151668": { "content": "<|rotate_up|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151669": { "content": "<|rotate_down|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151670": { "content": "<|rotate_left|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151671": { "content": "<|rotate_right|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151672": { "content": "<|txt_contd|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151673": { "content": "<|paratext|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true } }, "additional_special_tokens": [ "<|im_start|>", "<|im_end|>", "<|object_ref_start|>", "<|object_ref_end|>", "<|box_start|>", "<|box_end|>", "<|quad_start|>", "<|quad_end|>", "<|vision_start|>", "<|vision_end|>", "<|vision_pad|>", "<|image_pad|>", "<|video_pad|>", "<|ref_start|>", "<|ref_end|>", "<|md_start|>", "<|md_end|>", "<ched>", "<ecel>", "<fcel>", "<lcel>", "<ucel>", "<xcel>", "<nl>", "<|rotate_up|>", "<|rotate_down|>", "<|rotate_left|>", "<|rotate_right|>", "<|txt_contd|>", "<|paratext|>" ], "bos_token": null, "clean_up_tokenization_spaces": false, "eos_token": "<|im_end|>", "errors": "replace", "extra_special_tokens": {}, "model_max_length": 16384, "pad_token": "<|endoftext|>", "padding_side": "left", "processor_class": "Qwen2VLProcessor", "split_special_tokens": false, "tokenizer_class": "Qwen2Tokenizer", "unk_token": null}12�9���K�����:{=�$i���IWI�!N�123version https://git-lfs.github.com/spec/v1oid sha256:a2399fa8bd4bea90f2d7f8a23a0a7b1b023dee246989bad249574908f7214e97size 1325968609123{ "assetVersion" : "2.0"}.gitattributes+4
README.md+34-11
decoder/mineru_decode_int8lin_pf64.aimodel/main.hashAdded+1
decoder/mineru_decode_int8lin_pf64.aimodel/main.mlirbAdded+3
decoder/mineru_decode_int8lin_pf64.aimodel/metadata.jsonAdded+3
layout/decoder/metadata.jsonAdded+29
layout/decoder/mineru_decode_int8lin_pf64.aimodel/main.hashAdded
layout/decoder/mineru_decode_int8lin_pf64.aimodel/main.mlirbAdded+3
layout/decoder/mineru_decode_int8lin_pf64.aimodel/metadata.jsonAdded+3
layout/decoder/tokenizer/added_tokens.jsonAdded+33
layout/decoder/tokenizer/chat_template.jinjaAdded+7
layout/decoder/tokenizer/merges.txtAdded
layout/decoder/tokenizer/special_tokens_map.jsonAdded+48
layout/decoder/tokenizer/tokenizer.jsonAdded+3
layout/decoder/tokenizer/tokenizer_config.jsonAdded+297
layout/decoder/tokenizer/vocab.jsonAdded
layout/vision/mineru_vision.aimodel/main.hashAdded+2
layout/vision/mineru_vision.aimodel/main.mlirbAdded+3
layout/vision/mineru_vision.aimodel/metadata.jsonAdded+3