Views
No views yet
Not affiliated with ByteDance. This repo is a format conversion of the upstream weights; it does not introduce new training data.
1dolphin_encoder.mlpackage/ # Vision encoder (fp16, static 896×896)
2dolphin_decoder.mlpackage/ # Decoder (fp16, stateful KV cache, logits-only)
3hf_model_main/ # Config/tokenizer + model.safetensors weights (included)
4ane_end_to_end.py # Two-stage pipeline (CoreML-only, JSON outputs)
5ane_dolphin_encoder_mil.py # Build encoder mlpackage from safetensors
6ane_dolphin_mil.py # Build decoder mlpackage from safetensors
7docs/*.md # CoreML I/O and usage notes
8requirements.txt # Runtime + conversion deps (coremltools, torch, transformers, pymupdf…)
9demo/2306.02572v1.pdf # Sample PDF (kept small; delete if you don’t need it)dolphin_encoder.mlpackage):pixel_values → float16[1, 3, 896, 896] (NCHW)encoder_hidden → float16[1, 784, 1024] (28×28 tokens)dolphin_decoder.mlpackage):dec_ids → int32[1, 1]pos → int32[1]enc_hidden → float16[1, ENC_SEQ, 1024] (padded from 784 tokens)enc_mask → float16[1, 1, 1, ENC_SEQ]logits → float16[1, 1, vocab]decoder.make_state()).ENC_SEQ and DEC_SEQ are compile-time constants (set when you run the conversion scripts).1python -m venv .venv
2source .venv/bin/activate
3
4pip install -r requirements.txt1DEC_COMPUTE_UNITS=CPU_AND_NE \
2SAVE_OUTPUTS=1 SAVE_INTERMEDIATE_JSON=1 \
3SAMPLE_IMG=./demo/2306.02572v1.pdf \
4python3 ane_end_to_end.pyoutputs/recognition_json/<page>.json (per-page stage2 results)outputs/intermediate_json/<page>.json (stage1 + stage2)outputs/pdf_renders/<page>.png (only if input was PDF; for inspection).mlpackage files)pip install -r requirements.txthf_model_main/model.safetensors1# Option A (simple, downloads the whole upstream repo including weights)
2git lfs install
3git clone https://huggingface.co/ByteDance/Dolphin hf_model_main
4
5# Option B (download only the safetensors via the HF CLI)
6huggingface-cli download \
7 --local-dir hf_model_main --local-dir-use-symlinks False \
8 ByteDance/Dolphin \
9 --include "model.safetensors"1# Encoder (static 896×896)
2python ane_dolphin_encoder_mil.py
3
4# Decoder (KV-cache state; defaults: ENC_SEQ=2048, DEC_SEQ=4096)
5python ane_dolphin_mil.pydolphin_encoder.mlpackagedolphin_decoder.mlpackageENC_SEQ=1024 DEC_SEQ=2048 python ane_dolphin_decoder.pyDEC_SEQ controls KV-cache size. With DEC_SEQ=4096, the KV state alone is ~160 MB (10 layers × (K+V) × 16×4096×64 FP16).ENC_SEQ must be ≥ 784 (the encoder produces 28×28=784 tokens).LICENSE).1@inproceedings{dolphin2025,
2 title={Dolphin: Document Image Parsing via Heterogeneous Anchor Prompting},
3 author={Feng, Hao and Wei, Shu and Fei, Xiang and Shi, Wei and Han, Yingdong and Liao, Lei and Lu, Jinghui and Wu, Binghong and Liu, Qi and Lin, Chunhui and Tang, Jingqun and Liu, Hao and Huang, Can},
4 year={2025},
5 booktitle={Proceedings of the 65rd Annual Meeting of the Association for Computational Linguistics (ACL)}
6}coremltoolstransformers