Skip to content

feat(model): support MonkeyOCR - #5475

Merged
qinxuye merged 7 commits into
xorbitsai:mainfrom
llyycchhee:feat/support-monkeyocr-model
Sep 4, 2026
Merged

feat(model): support MonkeyOCR#5475
qinxuye merged 7 commits into
xorbitsai:mainfrom
llyycchhee:feat/support-monkeyocr-model

Conversation

@llyycchhee

Copy link
Copy Markdown
Collaborator

Support MonkeyOCR.

@XprobeBot XprobeBot added this to the v3.x milestone Sep 2, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for the MonkeyOCR model, registering it as a built-in OCR engine and adding the necessary third-party model wrapper and image loading utilities. The review feedback highlights several critical issues: a potential runtime crash when forcing FlashAttention-2 on CUDA without checking if the package is installed, inconsistent image preprocessing in single-image inference that could lead to OOM errors, a potential AttributeError if model_spec is None, and a device-matching bug that prevents CUDA cache clearing when specific device indices (e.g., 'cuda:0') are used.

Comment thread xinference/thirdparty/monkeyocr/magic_pdf/model/custom_model.py
Comment thread xinference/thirdparty/monkeyocr/magic_pdf/model/custom_model.py
Comment thread xinference/model/image/ocr/monkeyocr.py Outdated
Comment thread xinference/thirdparty/monkeyocr/magic_pdf/model/custom_model.py Outdated
@llyycchhee

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the MonkeyOCR model, adding its specification, registering it as a built-in OCR engine, and implementing its wrapper and custom inference logic. Feedback on the implementation highlights several key improvements: resolving potential runtime crashes on CPU by falling back to torch.float32 instead of torch.float16, adding qwen_vl_utils to the required libraries, safely handling None values for model_path, clearing the CUDA cache prior to single-processing fallbacks to prevent OOM errors, and using the configured max_new_tokens instead of a hardcoded value during single-item inference.

Comment thread xinference/thirdparty/monkeyocr/magic_pdf/model/custom_model.py Outdated
Comment thread xinference/thirdparty/monkeyocr/magic_pdf/model/custom_model.py
Comment thread xinference/model/image/ocr/monkeyocr.py Outdated
Comment thread xinference/model/image/ocr/monkeyocr.py
Comment thread xinference/thirdparty/monkeyocr/magic_pdf/model/custom_model.py
Comment thread xinference/thirdparty/monkeyocr/magic_pdf/model/custom_model.py Outdated

@qinxuye qinxuye left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also correct the PR title from monkeycor to MonkeyOCR. git diff --check currently reports trailing whitespace throughout the newly vendored custom_model.py; please clean that up as part of the revision.

Comment thread xinference/thirdparty/monkeyocr/magic_pdf/model/custom_model.py Outdated
Comment thread xinference/model/image/ocr/monkeyocr.py Outdated
Comment thread doc/source/models/builtin/image/monkeyocr.rst
@llyycchhee llyycchhee changed the title feat(model): support monkeycor feat(model): support MonkeyOCR Sep 3, 2026
Comment thread xinference/thirdparty/monkeyocr/magic_pdf/utils/load_image.py Outdated
@qinxuye
qinxuye merged commit fd6b6ef into xorbitsai:main Sep 4, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants