---
title: "SOTA OCR with Core ML and dots.ocr"
description: "Converting the dots.ocr vision encoder, a 1.2B NaViT-style model paired with a Qwen2.5-1.5B backbone, from PyTorch to Core ML is done by simplifying the model to single-image inference, then fixing conversion errors one by one."
url: "https://swe.quest/articles/sota-ocr-with-core-ml-and-dots-ocr-f35c7240fd943002"
canonical: "https://huggingface.co/blog/dots-ocr-ne"
source: "Hugging Face"
published: "2025-10-02"
difficulty: "medium"
kind: "How-to"
reading_minutes: 8
tags: ["inference","machine-learning","computer-vision","mobile","swift"]
---

# SOTA OCR with Core ML and dots.ocr

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2025-10-02, 8 min read, How-to. Original: [https://huggingface.co/blog/dots-ocr-ne](https://huggingface.co/blog/dots-ocr-ne)

## Summary

Converting the dots.ocr vision encoder, a 1.2B NaViT-style model paired with a Qwen2.5-1.5B backbone, from PyTorch to Core ML is done by simplifying the model to single-image inference, then fixing conversion errors one by one. The fixes are: casting arange output that coremltools forces to int32, removing repeat\_interleave and variable-length masking, using a float zero mask because the Neural Engine lacks bool support, and eliminating a data-dependent loop over grid\_thw. The resulting FLOAT32 GPU model matches PyTorch closely, but it is over 5GB and takes more than a second per vision-encoder forward pass. Later parts are slated to cover MLX integration for the LM backbone and Neural Engine optimization with quantization.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Computer vision](https://swe.quest/tags/computer-vision.md) (AI & ML)
- [Mobile](https://swe.quest/tags/mobile.md) (Web & mobile)
- [Swift](https://swe.quest/tags/swift.md) (Languages)

## Prerequisites

- PyTorch model tracing ([easy posts on Observability](https://swe.quest/tags/observability.md?difficulty=easy))
- transformer attention basics
- vision-language model structure ([easy posts on Computer vision](https://swe.quest/tags/computer-vision.md?difficulty=easy))

## Keywords

Core ML, coremltools, dots.ocr, MLX, Apple Neural Engine, torch.jit.trace, Qwen2.5

## Related posts

- [WWDC 24: Running Mistral 7B with Core ML](https://swe.quest/articles/wwdc-24-running-mistral-7b-with-core-ml-8ff5ba3b889a9bf2.md): Hugging Face · 2024-07-22 · Medium · 13 min read · Inference & serving, LLMs, Swift, Mobile
  Mistral 7B Instruct can run on a Mac with Core ML using features new in iOS 18 and macOS Sequoia: the MLTensor Swift type for tensor pre- and post-processing, stateful buffers that keep the kv-cache on the GPU instead of passing it in and out on every call, and block-wise 4-bit quantization.
- [Supercharge your OCR Pipelines with Open Models](https://swe.quest/articles/supercharge-your-ocr-pipelines-with-open-models-6c91417d0009054a.md): Hugging Face · 2025-10-21 · Medium · 16 min read · Computer vision, Inference & serving, Evaluation, RAG & retrieval
  Vision-language-model-based OCR has moved well beyond plain transcription.
- [Releasing Swift Transformers: Run On-Device LLMs in Apple Devices](https://swe.quest/articles/releasing-swift-transformers-run-on-device-llms-in-apple-devices-ee6106831bf892fd.md): Hugging Face · 2023-08-08 · Medium · 15 min read · Swift, Inference & serving, LLMs, Mobile
  Hugging Face released swift-transformers, an alpha Swift package with a transformers-like API for on-device text generation, along with the swift-chat demo app, updated exporters and transformers-to-coreml conversion tools, and pre-converted Llama 2 7B and Falcon 7B Core ML models.
- [Finetuning olmOCR to be a faithful OCR-Engine](https://swe.quest/articles/finetuning-olmocr-to-be-a-faithful-ocr-engine-2ef05ae56aeb87d1.md): Hugging Face · 2025-04-22 · Medium · 5 min read · Model training, Computer vision, LLMs
  TNG fine-tuned olmOCR-7B-0225-preview so it no longer drops headers and footers.
- [Stable Diffusion XL on Mac with Advanced Core ML Quantization](https://swe.quest/articles/stable-diffusion-xl-on-mac-with-advanced-core-ml-quantization-eb7e4e62c0405a93.md): Hugging Face · 2023-07-27 · Medium · 8 min read · Inference & serving, Computer vision, Mobile, Swift
  Stable Diffusion XL base has been ported to Core ML for Apple Silicon Macs (macOS 14 beta), with end-to-end latency ranging from 46 s on an M1 Max to 20 s on an M2 Ultra using CPU+GPU and the ORIGINAL attention implementation.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
