SOTA OCR with Core ML and dots.ocr
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.
Related posts
- WWDC 24: Running Mistral 7B with Core ML
Hugging Face mediumAdeptMistral 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. The conversion patches the transformers Mistral attention to use a pre-allocated, in-place kv-cache, traces it with torch.jit, and converts it with coremltools RangeDim inputs and StateType caches. Int4 per-block linear quantization (block size 32) shrinks the model from about 14GB in float16 to about 3.8GB. Inference then runs through the preview branch of swift-transformers.
- Supercharge your OCR Pipelines with Open Models
Hugging Face mediumAdeptVision-language-model-based OCR has moved well beyond plain transcription. Current open-weight models such as OlmOCR-2, Chandra, dots.ocr, DeepSeek-OCR, PaddleOCR-VL, Granite-Docling and Nanonets-OCR2 handle handwriting, tables, charts, formulas and layout grounding, and output DocTags, HTML, Markdown or JSON. Choose the output format by use case: layout-preserving formats for digital reconstruction, Markdown with image captions for LLM input, and JSON for programmatic use. Since performance varies widely by domain, evaluate candidates on your own representative documents alongside OmniDocBench, OlmOCR-Bench and CC-OCR. Open models are cheap to run, around $178 per million pages for OlmOCR-2 on an H100, and serve easily with vLLM behind an OpenAI-compatible client.
- Releasing Swift Transformers: Run On-Device LLMs in Apple Devices
Hugging Face mediumAdeptHugging 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. The post walks through converting Llama 2 to Core ML via three routes: the no-code Space, exporters, or raw coremltools. Lessons from those conversions include using coremltools 7.0b1, dropping softmax from outputs, and using fixed sequence lengths, because flexible shapes only run on the CPU. Planned optimizations are KV caching, discrete input shapes and palettization or mixed-bit quantization, and the library already supports Hub-configured BPE tokenizers plus greedy and top-k generation.
- Finetuning olmOCR to be a faithful OCR-Engine
Hugging Face mediumAdeptTNG fine-tuned olmOCR-7B-0225-preview so it no longer drops headers and footers. The original model omits them by design because its training data targets LLM pretraining text, which makes it unreliable for business documents like invoices. The team used Qwen2.5-VL-72B-Instruct to generate an 8,000-document dataset capturing all page content, then trained with the open-source olmOCR pipeline on an 8xH100 node: 2.5 epochs, default hyperparameters, about 6 hours, with roughly two GPUs likely enough. Qualitative comparisons show the fine-tune extracts header and footer data while still parsing simple tables and multi-column layouts, though output quality can vary noticeably with sampling temperature.
- Stable Diffusion XL on Mac with Advanced Core ML Quantization
Hugging Face mediumAdeptStable 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. The main technique is mixed-bit palettization, a post-training quantization method that picks a bit depth per layer (1, 2, 4, 8 or float16) based on each layer's measured PSNR impact against the float16 model. Recipes at 6.55, 4.50 and 3.41 bits per parameter all beat naive 8-bit linear quantization on PSNR, and the 4.5-bit recipe shrinks the UNet from 4.8 GB to 1.4 GB. Aggressive compression can degrade prompt adherence in ways PSNR does not capture. Analysis and apply scripts plus precomputed recipes for SD 1.5, 2.1 and XL are published.