Downloads · 30 days
0
0% of all-time downloads
pkhairkh/bytedance-dolphin1.5-coreml
bytedance-dolphin1.5-coreml is a image-text-to-text model from pkhairkh. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product. It is set up for coreml. The card lists the license as mit.
This repository packages an Apple Neural Engine–friendly Core ML export of ByteDance’s Dolphin document image parsing model (Donut-Swin encoder + mBART decoder), plus minimal Python code to run the analyze → parse pip…
Downloads · 30 days
0
0% of all-time downloads
All-time downloads
29
Public
Repo size
721 MB
Likes
0
Public
Click a slice to open those files.
.bin719 MB · 98%
From the Hugging Face model README
This repository packages an Apple Neural Engine–friendly Core ML export of ByteDance’s Dolphin document image parsing model (Donut-Swin encoder + mBART decoder), plus minimal Python code to run the analyze → parse pipeline (JSON outputs only).
It is intended for local / on‑device inference on macOS / iOS with Core ML (iOS 18 deployment target in the conversion scripts).
Not affiliated with ByteDance. This repo is a format conversion of the upstream weights; it does not introduce new training data.
Repository layout (what’s actually here):
dolphin_encoder.mlpackage/ # Vision encoder (fp16, static 896×896)
dolphin_decoder.mlpackage/ # Decoder (fp16, stateful KV cache, logits-only)
hf_model_main/ # Config/tokenizer + model.safetensors weights (included)
ane_end_to_end.py # Two-stage pipeline (CoreML-only, JSON outputs)
ane_dolphin_encoder_mil.py # Build encoder mlpackage from safetensors
ane_dolphin_mil.py # Build decoder mlpackage from safetensors
docs/*.md # CoreML I/O and usage notes
requirements.txt # Runtime + conversion deps (coremltools, torch, transformers, pymupdf…)
demo/2306.02572v1.pdf # Sample PDF (kept small; delete if you don’t need it)
Encoder (dolphin_encoder.mlpackage):
pixel_values → float16[1, 3, 896, 896] (NCHW)encoder_hidden → float16[1, 784, 1024] (28×28 tokens)Decoder (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).
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
DEC_COMPUTE_UNITS=CPU_AND_NE \
SAVE_OUTPUTS=1 SAVE_INTERMEDIATE_JSON=1 \
SAMPLE_IMG=./demo/2306.02572v1.pdf \
python3 ane_end_to_end.py
Outputs:
outputs/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)The conversion scripts build Core ML “mlprogram” models directly in MIL and embed the upstream weights.
pip install -r requirements.txt
The scripts expect a safetensors weight file at:
hf_model_main/model.safetensors
Two common options:
# Option A (simple, downloads the whole upstream repo including weights)
git lfs install
git clone https://huggingface.co/ByteDance/Dolphin hf_model_main
# Option B (download only the safetensors via the HF CLI)
huggingface-cli download \
--local-dir hf_model_main --local-dir-use-symlinks False \
ByteDance/Dolphin \
--include "model.safetensors"
# Encoder (static 896×896)
python ane_dolphin_encoder_mil.py
# Decoder (KV-cache state; defaults: ENC_SEQ=2048, DEC_SEQ=4096)
python ane_dolphin_mil.py
Outputs:
dolphin_encoder.mlpackagedolphin_decoder.mlpackageYou can reduce memory/latency by compiling with smaller constants:
ENC_SEQ=1024 DEC_SEQ=2048 python ane_dolphin_decoder.py
Notes:
DEC_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).@inproceedings{dolphin2025,
title={Dolphin: Document Image Parsing via Heterogeneous Anchor Prompting},
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},
year={2025},
booktitle={Proceedings of the 65rd Annual Meeting of the Association for Computational Linguistics (ACL)}
}
coremltoolstransformers