Skip to content

feat(models): complete DeepSeek-OCR VLM (connector, processor, loader, runtime) - #655

Merged
inureyes merged 1 commit into
mainfrom
feat/issue-540-deepseek-ocr-model
Jul 4, 2026
Merged

inureyes merged 1 commit into
mainfrom
feat/issue-540-deepseek-ocr-model

Conversation

@inureyes

@inureyes inureyes commented Jul 4, 2026

Copy link
Copy Markdown
Member

Completes the DeepSeek-OCR port (#540), building on the SAM + CLIP encoders and decoder hooks merged in #651.

Connector / wrapper (vision::deepseekocr)

Per view, channel-fuses [CLIP(drop CLS), SAM(flattened)], projects 2048 -> 1280 (quantized linear), then assembles the 2D tile mosaic: the global view becomes a 16x17 grid with image_newline columns (272 rows), tiles become an (h*10) x (w*10 + 1) grid, and each image's [tiles, global, view_separator] rows scatter into the <image> placeholder positions of the embedded prompt (merge_llava). The placeholder tokens are all id 128815, so the scatter fills them in feature order.

Processor (vision::processors::deepseekocr)

Pads a global 1024 view (aspect-preserving, grey pad) and, for images larger than a tile, selects a closest-aspect-ratio grid of 640 tiles (product 2..9). Channels-last (x/255 - 0.5)/0.5 normalization. Computes the flat placeholder count per image: (16+1)*16 + 1, plus (10w+1)*10h when tiled.

Loader + runtime

vlm_deepseekocr parses language_config (injecting the root quantization block and a model_type), loads the SAM / CLIP / projector / image_newline / view_separator by ref, and hands the model.* keys to the shared deepseek decoder. Both on-disk layouts are handled (view_seperator spelling, model. prefix). Detection, the ModelType / LoadedModel / VlmRuntimeRef arms, <image> (128815) expansion, and image-token output suppression complete the runtime.

Validation (mlx-community/DeepSeek-OCR-4bit)

Free OCR converts a price table to markdown on both the no-tile path (273 placeholders) and the 3x2-tile path (893 = 273 + 31*20 placeholders):

| Name | Qty | Price |
| Apple | 3 | 1.50 |
| Bread | 2 | 2.00 |

<|grounding|> prompts emit <|ref|>...<|/ref|><|det|>[[x1, y1, x2, y2]]<|/det|> boxes (coords 0-1000). The vision towers were numerically validated against mlx-vlm in #651.

Closes #540

…, runtime)

Wires the SAM + CLIP encoders (PR #651) and the shared DeepSeek MoE decoder into a working DeepSeek-OCR model end to end.

Processor: pad-to-square 1024 global view plus a dynamic closest-aspect-ratio grid of 640 tiles, channels-last (x/255 - 0.5)/0.5 normalization, and the flat placeholder count each image expands to.

Wrapper: per-view fuse [CLIP(drop CLS), SAM(flattened)] into a quantized linear projector, assemble the 2D tile mosaic with image_newline columns and a trailing view_separator, and scatter each image's [tiles, global, view_separator] rows into the <image> positions of the embedded prompt.

Loader and runtime: two on-disk layouts (view_seperator spelling, model. prefix), language_config with root-quantization and model_type injection, detection plus ModelType / LoadedModel / VlmRuntimeRef arms, <image> (128815) placeholder expansion, and image-token output suppression.

Validated on mlx-community/DeepSeek-OCR-4bit: converts a price table to a markdown table on both the no-tile path (273 placeholders) and the 3x2-tile path (893 placeholders), and emits grounding boxes for <|grounding|> prompts.

Closes #540
@inureyes inureyes added the area:models Model architectures, weights, loading, metadata label Jul 4, 2026
@inureyes
inureyes merged commit d2842b7 into main Jul 4, 2026
4 checks passed
@inureyes
inureyes deleted the feat/issue-540-deepseek-ocr-model branch July 4, 2026 12:50
@inureyes inureyes self-assigned this Aug 31, 2026
@inureyes inureyes added status:done Completed type:enhancement New features, capabilities, or significant additions priority:low Low priority labels Sep 6, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…, runtime) (lablup#655)

Wires the SAM + CLIP encoders (PR lablup#651) and the shared DeepSeek MoE decoder into a working DeepSeek-OCR model end to end.

Processor: pad-to-square 1024 global view plus a dynamic closest-aspect-ratio grid of 640 tiles, channels-last (x/255 - 0.5)/0.5 normalization, and the flat placeholder count each image expands to.

Wrapper: per-view fuse [CLIP(drop CLS), SAM(flattened)] into a quantized linear projector, assemble the 2D tile mosaic with image_newline columns and a trailing view_separator, and scatter each image's [tiles, global, view_separator] rows into the <image> positions of the embedded prompt.

Loader and runtime: two on-disk layouts (view_seperator spelling, model. prefix), language_config with root-quantization and model_type injection, detection plus ModelType / LoadedModel / VlmRuntimeRef arms, <image> (128815) placeholder expansion, and image-token output suppression.

Validated on mlx-community/DeepSeek-OCR-4bit: converts a price table to a markdown table on both the no-tile path (273 placeholders) and the 3x2-tile path (893 placeholders), and emits grounding boxes for <|grounding|> prompts.

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

Labels

area:models Model architectures, weights, loading, metadata priority:low Low priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(models): port DeepSeek-OCR (vision encoder + text decoder OCR)

1 participant