Skip to content

[Perf] Text OCR-det forced to CPU on MPS is ~12x slower in the batch path (Apple Silicon, torch backend) #5632

Closed

Description

@yanhuixie

🔎 Search before asking | 提交之前请先搜索

  • I have searched the MinerU Readme and found no similar bug report.
  • I have searched the MinerU Issues and found no similar bug report.
  • I have searched the MinerU Discussions and found no similar bug report.

🤖 Consult the online AI assistant for assistance | 在线 AI 助手咨询

Description of the bug | 错误描述

phase ocr-det is too slow on Apple Silicon MacOS.

How to reproduce the bug | 如何复现

Commit 1cbdeba forces self.device = "cpu" for text det when device is MPS (mineru/model/_internal/pytorchocr/infer/predict_det.py L19-24), citing cold-start overhead, with no config/env toggle.

Environment: MacBook M2, mineru 4.0.12, small_backend=torch (MinerU-4_models_torch), VLM engine llama-cpp, 70-page PDF, standard tier.

Same PDF, same machine:

det device OCR-det end-to-end
CPU (stock) 3.69 it/s, 1140 crops ≈ 5 min —
MPS (patched use_cpu_det = False and () 43.46 it/s (26 s) 70 pages in 50.9 s (1.38 page/s)

The batch path pads crops to a uniform shape, so MPS kernel compilation is paid once per shape, not per crop — the cold-start rationale mainly applies to the non-batch path. Could you re-evaluate for the batch path, or expose a switch (e.g. MINERU_OCR_DET_DEVICE), or force CPU only during warmup?

Operating System Mode | 操作系统类型

MacOS

Operating System Version| 操作系统版本

Darwin blabla-Studio.local 27.0.0 Darwin Kernel Version 27.0.0: Tue Aug 11 21:20:40 PDT 2026; root:xnu-13432.1.9~1/RELEASE_ARM64_T6020 arm64

Python version | Python 版本

3.12

Software version | 软件版本 (mineru --version)

4.0.0.dev20260626

Backend name | 解析后端

vlm

Device mode | 设备模式

mps

Activity

  1. myhloli commented on Oct 12, 2026

    @myhloli
    Collaborator

    Thanks for the report. We re-evaluated OCR text detection on Apple Silicon, including the batch path. MPS can be faster once warmed up, but its first inference still takes too long. The approaches we tested have not provided a satisfactory balance between startup latency, memory usage, and output consistency.

    We will therefore keep ordinary OCR text detection on CPU when MPS is selected. This CPU fallback is specific to MPS. On other supported non-MPS accelerators, such as CUDA, det will continue to use the selected accelerator normally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions