Image-Text-to-Text
MLX
Safetensors
multilingual
deepseekocr
mlx-vlm
quantized
apple-silicon
deepseek-ocr
ocr
vision-language
multimodal
document-parsing
conversational
4-bit precision
Instructions to use sahilchachra/unlimited-ocr-4bit-mlx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use sahilchachra/unlimited-ocr-4bit-mlx with MLX:
# Make sure mlx-vlm is installed # pip install --upgrade 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 the model model, processor = load("sahilchachra/unlimited-ocr-4bit-mlx") config = load_config("sahilchachra/unlimited-ocr-4bit-mlx") # Prepare input image = ["http://images.cocodataset.org/val2017/000000039769.jpg"] prompt = "Describe this image." # Apply chat template formatted_prompt = apply_chat_template( processor, config, prompt, num_images=1 ) # Generate output output = generate(model, processor, formatted_prompt, image) print(output) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,44 +1,61 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
base_model: baidu/Unlimited-OCR
|
|
|
|
|
|
|
| 4 |
tags:
|
| 5 |
- mlx
|
|
|
|
| 6 |
- quantized
|
| 7 |
- apple-silicon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
#
|
| 11 |
|
| 12 |
-
MLX quantization of [baidu/Unlimited-OCR](https://huggingface.co/baidu/Unlimited-OCR)
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
**Variant**: Affine int4
|
| 15 |
-
**Disk size**: 2347 MB
|
| 16 |
**Quantized by**: [sahilchachra](https://huggingface.co/sahilchachra)
|
| 17 |
|
| 18 |
-
> **Note on effective bpw**: mlx-vlm's quantizers only act on the
|
| 19 |
-
>
|
| 20 |
-
>
|
| 21 |
-
> reflects the LM-tower quantization while the on-disk size averages
|
| 22 |
-
> the two halves of the model.
|
| 23 |
|
| 24 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
|
| 30 |
-
| |
|
| 31 |
|---|---:|---:|
|
| 32 |
-
|
|
| 33 |
-
|
|
| 34 |
-
|
|
|
|
|
| 35 |
|
| 36 |
-
###
|
| 37 |
|
| 38 |
-
|
|
| 39 |
-
|---|---:|---:|---:|
|
| 40 |
-
|
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
## Usage
|
| 44 |
|
|
@@ -58,34 +75,69 @@ response = generate(model, processor,
|
|
| 58 |
max_tokens=4096, verbose=True)
|
| 59 |
```
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
> block, and set `processor_config.json` → `"processor_class": "DeepseekOCRProcessor"`
|
| 71 |
-
> (was `"UnlimitedOCRHFProcessor"`).
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
## All variants in this collection
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|---|---|
|
| 78 |
-
| [sahilchachra/unlimited-ocr-4bit-mlx](https://huggingface.co/sahilchachra/unlimited-ocr-4bit-mlx) | Affine int4 ← this model |
|
| 79 |
-
| [sahilchachra/unlimited-ocr-8bit-mlx](https://huggingface.co/sahilchachra/unlimited-ocr-8bit-mlx) | Affine int8 |
|
| 80 |
-
| [sahilchachra/unlimited-ocr-mxfp4-mlx](https://huggingface.co/sahilchachra/unlimited-ocr-mxfp4-mlx) | Block float MX FP4 |
|
| 81 |
-
| [sahilchachra/unlimited-ocr-mxfp8-mlx](https://huggingface.co/sahilchachra/unlimited-ocr-mxfp8-mlx) | Block float MX FP8 |
|
| 82 |
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
| 88 |
|
| 89 |
-
##
|
| 90 |
|
| 91 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
base_model: baidu/Unlimited-OCR
|
| 4 |
+
base_model_relation: quantized
|
| 5 |
+
pipeline_tag: image-text-to-text
|
| 6 |
tags:
|
| 7 |
- mlx
|
| 8 |
+
- mlx-vlm
|
| 9 |
- quantized
|
| 10 |
- apple-silicon
|
| 11 |
+
- deepseek-ocr
|
| 12 |
+
- ocr
|
| 13 |
+
- vision-language
|
| 14 |
+
- multimodal
|
| 15 |
+
- document-parsing
|
| 16 |
+
language:
|
| 17 |
+
- multilingual
|
| 18 |
---
|
| 19 |
|
| 20 |
+
# Unlimited-OCR — MLX Affine int4 (group size 64)
|
| 21 |
|
| 22 |
+
MLX quantization of [**baidu/Unlimited-OCR**](https://huggingface.co/baidu/Unlimited-OCR),
|
| 23 |
+
a 3B vision-language OCR model that pushes **DeepSeek-OCR** one step further (one-shot,
|
| 24 |
+
long-horizon document parsing). This variant uses **Affine int4 (group size 64)** quantization
|
| 25 |
+
(5.88 effective bits/weight).
|
| 26 |
|
|
|
|
|
|
|
| 27 |
**Quantized by**: [sahilchachra](https://huggingface.co/sahilchachra)
|
| 28 |
|
| 29 |
+
> **Note on effective bpw**: mlx-vlm's quantizers only act on the language tower's linear
|
| 30 |
+
> weights. The vision encoder and embeddings stay at bf16, so the on-disk size averages
|
| 31 |
+
> the quantized text decoder with the full-precision vision components.
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
## About the model
|
| 34 |
+
|
| 35 |
+
- **Architecture:** *DeepEncoder* vision (SAM-ViT-B + CLIP-L/14, 1024×1024 input, 16× downsample) → linear projector → **DeepSeek-V2 MoE** text decoder (12 layers, hidden 1280, 64 routed + 2 shared experts, 6 experts/token).
|
| 36 |
+
- **Task:** multilingual OCR / document parsing — single image, multi-page, and PDF (one-shot long-horizon parsing). Supports *gundam* (crop) and *base* resolution modes.
|
| 37 |
+
- **License:** MIT (inherited from the base model).
|
| 38 |
|
| 39 |
+
## Benchmark results
|
| 40 |
|
| 41 |
+
Evaluated on Apple M4 Pro (24 GB) with MLX on the [FUNSD](https://huggingface.co/datasets/nielsr/funsd) test set (50 scanned form images).
|
| 42 |
|
| 43 |
+
| | Affine int4 (group size 64) | FP16 baseline |
|
| 44 |
|---|---:|---:|
|
| 45 |
+
| **FUNSD CER ↓** | **2.2879** | 1.7588 |
|
| 46 |
+
| Decode tok/s | 252.6 | 146.2 |
|
| 47 |
+
| Peak memory | 3.7 GB | 7.62 GB |
|
| 48 |
+
| Disk size | 2347 MB | 6464 MB |
|
| 49 |
|
| 50 |
+
### All variants compared
|
| 51 |
|
| 52 |
+
| Variant | CER ↓ | Tok/s | Memory | Disk |
|
| 53 |
+
|---|---:|---:|---:|---:|
|
| 54 |
+
| FP16 (baseline) | 1.7588 | 146.2 | 7.62 GB | 6464 MB |
|
| 55 |
+
| MXFP8 | 1.4556 | 205.6 | 4.98 GB | 3660 MB |
|
| 56 |
+
| Int8 | 1.5720 | 205.2 | 5.06 GB | 3747 MB |
|
| 57 |
+
| MXFP4 | 2.3944 | 251.9 | 3.61 GB | 2260 MB |
|
| 58 |
+
| Int4 | 2.2879 | 252.6 | 3.7 GB | 2347 MB |
|
| 59 |
|
| 60 |
## Usage
|
| 61 |
|
|
|
|
| 75 |
max_tokens=4096, verbose=True)
|
| 76 |
```
|
| 77 |
|
| 78 |
+
## Prompting guide
|
| 79 |
+
|
| 80 |
+
Unlimited-OCR uses the **DeepSeek-OCR** prompt vocabulary. The prompt is just an instruction;
|
| 81 |
+
prefix it with `<|grounding|>` whenever you also want **bounding boxes** for what was read.
|
| 82 |
+
|
| 83 |
+
| Task | Prompt |
|
| 84 |
+
|---|---|
|
| 85 |
+
| **Document → Markdown** (layout-aware, with boxes) | `<image><|grounding|>Convert the document to markdown.` |
|
| 86 |
+
| **Plain text OCR** (just the text, no layout) | `<image>Free OCR.` |
|
| 87 |
+
| **OCR with bounding boxes** | `<image><|grounding|>OCR this image.` |
|
| 88 |
+
| **Native parse** | `<image>document parsing.` |
|
| 89 |
+
| **Parse a figure / chart / diagram** | `<image>Parse the figure.` |
|
| 90 |
+
| **Describe the image** (general VQA) | `<image>Describe this image in detail.` |
|
| 91 |
+
|
| 92 |
+
> **Note:** Unlike the GGUF/llama.cpp workflow, mlx-vlm requires the literal `<image>` token
|
| 93 |
+
> in the prompt and a separate `image=` argument pointing to the file path.
|
| 94 |
+
|
| 95 |
+
### Understanding the output (grounding tokens)
|
| 96 |
+
|
| 97 |
+
With `<|grounding|>`, the model interleaves the recognized text with detection boxes:
|
| 98 |
+
|
| 99 |
+
```
|
| 100 |
+
<|det|>title [37, 64, 464, 132]<|/det|>INVOICE #2026-0623
|
| 101 |
+
<|det|>text [37, 194, 350, 247]<|/det|>Bill To: Sahil Chachra
|
| 102 |
+
<|det|>text [37, 483, 329, 543]<|/det|>Total Due: $44.00
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
Each `[x1, y1, x2, y2]` is the bounding box (top-left → bottom-right) of that span. Drop the
|
| 106 |
+
`<|det|>...<|/det|>` tags if you only want the text, or parse them to overlay boxes / build a layout.
|
| 107 |
+
|
| 108 |
+
> **Tip — long documents:** For multi-page scans, run page-by-page and concatenate.
|
| 109 |
+
|
| 110 |
+
## Important — model_type mapping
|
| 111 |
|
| 112 |
+
The original `baidu/Unlimited-OCR` uses `model_type: "unlimited-ocr"` which is not directly
|
| 113 |
+
recognized by mlx-vlm. This quantized variant ships with the config already patched:
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
- `config.json` → `"model_type": "deepseekocr"` (was `"unlimited-ocr"`), `auto_map` removed
|
| 116 |
+
- `processor_config.json` → `"processor_class": "DeepseekOCRProcessor"` (was `"UnlimitedOCRHFProcessor"`)
|
| 117 |
+
|
| 118 |
+
**No manual patching needed** — just `load()` and go.
|
| 119 |
+
|
| 120 |
+
If you are converting the original model yourself, apply these two changes before running
|
| 121 |
+
`mlx_vlm convert`.
|
| 122 |
|
| 123 |
## All variants in this collection
|
| 124 |
|
| 125 |
+
### MLX (Apple Silicon — this collection)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
| Model | Variant | Disk |
|
| 128 |
+
|---|---|---:|
|
| 129 |
+
| [sahilchachra/unlimited-ocr-4bit-mlx](https://huggingface.co/sahilchachra/unlimited-ocr-4bit-mlx) | Affine int4 ← this model | 2347 MB |
|
| 130 |
+
| [sahilchachra/unlimited-ocr-8bit-mlx](https://huggingface.co/sahilchachra/unlimited-ocr-8bit-mlx) | Affine int8 | 3747 MB |
|
| 131 |
+
| [sahilchachra/unlimited-ocr-mxfp4-mlx](https://huggingface.co/sahilchachra/unlimited-ocr-mxfp4-mlx) | Block float MX FP4 | 2260 MB |
|
| 132 |
+
| [sahilchachra/unlimited-ocr-mxfp8-mlx](https://huggingface.co/sahilchachra/unlimited-ocr-mxfp8-mlx) | Block float MX FP8 | 3660 MB |
|
| 133 |
|
| 134 |
+
### GGUF (llama.cpp — cross-platform)
|
| 135 |
+
|
| 136 |
+
| Model | Notes |
|
| 137 |
+
|---|---|
|
| 138 |
+
| [sahilchachra/Unlimited-OCR-GGUF](https://huggingface.co/sahilchachra/Unlimited-OCR-GGUF) | K-quants & i-quants (BF16 → IQ2_M). Requires llama.cpp PR #17400. |
|
| 139 |
|
| 140 |
+
## Credits
|
| 141 |
|
| 142 |
+
- Base model: [baidu/Unlimited-OCR](https://huggingface.co/baidu/Unlimited-OCR) (MIT) — builds on [deepseek-ai/DeepSeek-OCR](https://github.com/deepseek-ai/DeepSeek-OCR).
|
| 143 |
+
- Quantized by [sahilchachra](https://huggingface.co/sahilchachra).
|