Downloads ยท 30 days
27
4% of all-time downloads
gamhtoi/PaddleOCR-VL-MLX
PaddleOCR-VL-MLX is a machine learning model from gamhtoi. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
๐ World's First MLX-Native Implementation of PaddleOCR-VL
Downloads ยท 30 days
27
4% of all-time downloads
All-time downloads
645
Public
Repo size
7.7 GB
Likes
3
Public
Click a slice to open those files.
.npz3.8 GB ยท 50%
From the Hugging Face model README
๐ World's First MLX-Native Implementation of PaddleOCR-VL
This is a high-performance MLX conversion of PaddlePaddle/PaddleOCR-VL, optimized for Apple Silicon (M1/M2/M3/M4) chips. It delivers native NPU acceleration for optical character recognition tasks.
| Device | Framework | Inference Speed | Memory Usage |
|---|---|---|---|
| M4 Max | MLX (This) | ~2-3s/image | ~4GB |
| M4 Max | PyTorch | ~5-8s/image | ~8GB |
| RTX 4090 | PyTorch | ~1-2s/image | ~6GB |
Tested on 384x384 images with default settings
pip install mlx transformers pillow
import mlx.core as mx
from PIL import Image
from transformers import AutoTokenizer
from modeling_paddleocr_vl import PaddleOCRVLForConditionalGeneration
# Load model and tokenizer
model = PaddleOCRVLForConditionalGeneration.from_pretrained(
"gamhtoi/PaddleOCR-VL-MLX",
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(
"gamhtoi/PaddleOCR-VL-MLX",
trust_remote_code=True
)
# Load and process image
image = Image.open("document.jpg")
inputs = tokenizer(
text="OCR:",
images=image,
return_tensors="np"
)
# Convert to MLX arrays
input_ids = mx.array(inputs['input_ids'])
pixel_values = mx.array(inputs['pixel_values'])
# Generate OCR result
outputs = model.generate(
input_ids=input_ids,
pixel_values=pixel_values,
max_new_tokens=512
)
# Decode result
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(result)
# For real-time OCR with progress tracking
def ocr_with_progress(image_path, prompt="OCR:"):
image = Image.open(image_path)
inputs = tokenizer(text=prompt, images=image, return_tensors="np")
input_ids = mx.array(inputs['input_ids'])
pixel_values = mx.array(inputs['pixel_values'])
# Stream generation
for token in model.generate_stream(
input_ids=input_ids,
pixel_values=pixel_values,
max_new_tokens=1024
):
yield tokenizer.decode(token, skip_special_tokens=True)
# Usage
for partial_result in ocr_with_progress("complex_document.pdf"):
print(partial_result, end='', flush=True)
This model consists of:
Key features:
model-00001-of-00002.safetensors: Vision encoder weightsmodel-00002-of-00002.safetensors: Language model weightsmodeling_paddleocr_vl.py: MLX implementationconfiguration_paddleocr_vl.py: Model configurationtokenizer.json: Fast tokenizerconfig.json: Model metadataThis model was converted from PyTorch to MLX using a custom conversion pipeline:
mlx >= 0.4.0transformers >= 4.40.0Pillow >= 10.0.0If you use this model in your research, please cite:
@misc{paddleocr-vl-mlx-2024,
author = {gamhtoi},
title = {PaddleOCR-VL MLX: Apple Silicon Native OCR},
year = {2024},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/gamhtoi/PaddleOCR-VL-MLX}}
}
@article{paddleocr-vl-2024,
title={PaddleOCR-VL: A Vision-Language Model for Optical Character Recognition},
author={PaddlePaddle Team},
year={2024}
}
This model inherits the license from the original PaddleOCR-VL model. Please refer to the original repository for license details.
Found a bug or want to contribute? Please open an issue or PR on the GitHub repository.
Made with โค๏ธ for the Apple Silicon community