Downloads · 30 days
190
8% of all-time downloads
jason1966/Qianfan-OCR-MLX-4bit
Qianfan-OCR-MLX-4bit is a image-text-to-text model from jason1966. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product. It is set up for mlx. The card lists the license as apache-2.0.
Downloads · 30 days
190
8% of all-time downloads
All-time downloads
2.5K
Public
Parameters
4.7B
3.1 GB on disk
Likes
5
Public
Click a slice to open those files.
.safetensors3.1 GB · 99%
How the weights are stored.
U324.4B · 94%
From the Hugging Face model README
🤗 Original Model | 📄 Technical Report | 💻 GitHub | 🍎 MLX-VLM
</div>This is a 4-bit quantized version of Qianfan-OCR optimized for Apple Silicon using the MLX framework. It delivers 2x faster generation speed with half the memory footprint while maintaining full OCR accuracy.
Qianfan-OCR is a 4B-parameter end-to-end document intelligence model developed by Baidu Qianfan Team, achieving #1 ranking on OmniDocBench v1.5 (93.12) and OlmOCR Bench (79.8) among end-to-end models.
| Metric | Original (bfloat16) | MLX 4-bit | Improvement |
|---|---|---|---|
| Model Size | 9.5GB | 2.9GB | -69% 🎉 |
| Prefill Speed | ~1,250 tok/s | ~1,252 tok/s | Maintained |
| Generation Speed | ~65-69 tok/s | 145 tok/s | +111% 🚀 |
| Peak Memory | ~10.6GB | 4.7GB | -56% 💾 |
| OCR Accuracy | Perfect | Perfect | No Loss ✅ |
Benchmarked on Apple Silicon Mac with mlx-vlm
All tasks from the original Qianfan-OCR model are fully supported:
pip install mlx-vlm
from mlx_vlm import load, generate
from mlx_vlm.prompt_utils import apply_chat_template
from mlx_vlm.utils import load_config
# Load 4-bit quantized model
model, processor = load("jason1966/Qianfan-OCR-MLX-4bit", trust_remote_code=True)
config = load_config("jason1966/Qianfan-OCR-MLX-4bit")
# Process image
image = ["your_document.png"]
prompt = "Parse this document to Markdown."
formatted_prompt = apply_chat_template(processor, config, prompt, num_images=1)
# Generate
output = generate(model, processor, formatted_prompt, image, max_tokens=2000)
print(output)
python -m mlx_vlm.generate \
--model jason1966/Qianfan-OCR-MLX-4bit \
--max-tokens 2000 \
--prompt "Parse this document to Markdown." \
--image your_document.png \
--trust-remote-code
Enable structured layout analysis by adding <think> to your prompt:
prompt = "Parse this document to Markdown.<think>"
formatted_prompt = apply_chat_template(processor, config, prompt, num_images=1)
output = generate(model, processor, formatted_prompt, ["complex_doc.jpg"], max_tokens=2000)
The model will first generate structured layout analysis (bounding boxes, element types, reading order), then produce the final Markdown output.
prompt = "Extract the following fields from the image: Name, Date, Total Amount. Output in standard JSON format."
formatted_prompt = apply_chat_template(processor, config, prompt, num_images=1)
output = generate(model, processor, formatted_prompt, ["invoice.jpg"], max_tokens=2000)
| Operation | Original Model | MLX 4-bit | Speedup |
|---|---|---|---|
| Prefill (prompt processing) | 1,250 tok/s | 1,252 tok/s | 1.00x |
| Generation (output) | 65-69 tok/s | 145 tok/s | 2.11x |
| End-to-End (real-world) | - | - | ~2x faster |
| Model Variant | Disk Size | Peak Memory | Min. Unified Memory |
|---|---|---|---|
| Original (bfloat16) | 9.5GB | 10.6GB | 16GB recommended |
| MLX 4-bit | 2.9GB | 4.7GB | 8GB sufficient |
We tested the 4-bit model on diverse documents:
| Test Case | Result |
|---|---|
| English technical document | ✅ Perfect - All text, formulas, and tables correctly parsed |
| Chinese invoice | ✅ Perfect - All fields, amounts, and dates extracted accurately |
| Complex multi-column layout | ✅ Perfect - Reading order and structure preserved |
| Handwritten notes | ✅ Perfect - Same quality as original model |
Conclusion: 4-bit quantization achieves lossless OCR accuracy while delivering 2x performance improvement.
This model inherits the architecture from Qianfan-OCR:
| Component | Details |
|---|---|
| Vision Encoder | InternViT-6B (24 layers, 1024 hidden dim, 448×448 patches) |
| Language Model | Qwen3-4B (36 layers, 2560 hidden dim, GQA 32/8 heads) |
| Cross-Modal Adapter | 2-layer MLP with GELU (1024→2560 dim) |
| Total Parameters | ~4.3B |
| Quantization | 4-bit with 5.239 bits per weight (group size optimization) |
| Vocabulary | 153,678 tokens (includes 1000 coordinate tokens <COORD_000>-<COORD_999>) |
mlx_vlm.convert --quantizeQianfan-OCR uses the internvl_chat architecture, which mlx-vlm already fully supports:
model_type: "internvl_chat" - Auto-detected by mlx-vlmattention_bias: false<img>, </img>, <IMG_CONTEXT> tokenschat_template.jinjaThe base Qianfan-OCR model achieved state-of-the-art results:
See original model page for full benchmark details.
prompt = """Extract all fields from this invoice:
- Invoice number
- Date
- Vendor name
- Line items (description, quantity, price)
- Subtotal, tax, total
Output as JSON."""
prompt = """Parse this academic paper and:
1. Extract title, authors, abstract
2. Convert all formulas to LaTeX
3. Preserve table structures
4. Generate outline from section headings
Output in Markdown."""
# Automatically detects and transcribes 192 languages
prompt = "Transcribe all text from this multilingual document."
@misc{dong2026qianfanocrunifiedendtoendmodel,
title={Qianfan-OCR: A Unified End-to-End Model for Document Intelligence},
author={Daxiang Dong and Mingming Zheng and Dong Xu and Chunhua Luo and Bairong Zhuang and Yuxuan Li and Ruoyun He and Haoran Wang and Wenyu Zhang and Wenbo Wang and Yicheng Wang and Xue Xiong and Ayong Zheng and Xiaoying Zuo and Ziwei Ou and Jingnan Gu and Quanhao Guo and Jianmin Wu and Dawei Yin and Dou Shen},
year={2026},
eprint={2603.13398},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2603.13398},
}
This model inherits the Apache License 2.0 from the original Qianfan-OCR model.