# GLM-OCR Spike — 2026-06-27

## Verdict: SHIP IT

MLX-native path confirmed. Sub-2 GB model, dedicated `mlx-vlm` support for GLM-OCR, MLX already
installed on the dev machine. No blockers.

---

## Model

| Field | Value |
|-------|-------|
| **Name** | GLM-OCR |
| **HuggingFace path** | `zai-org/GLM-OCR` (base BF16) |
| **MLX path** | `mlx-community/GLM-OCR-8bit` |
| **Parameters** | 0.9B |
| **Disk (MLX 8-bit)** | 1.59 GB (`model.safetensors` 1.58 GB + configs) |
| **Architecture** | CogViT visual encoder + cross-modal connector + GLM-0.5B decoder |
| **License** | MIT (model); Apache 2.0 (PP-DocLayoutV3 layout component) |
| **Task class** | Image-Text-to-Text (multimodal OCR) |

### Benchmarks

| Benchmark | Score | Notes |
|-----------|-------|-------|
| OmniDocBench V1.5 | **94.62** | Ranked #1 at evaluation date |
| olmOCR-bench (overall) | 75.2 | — |
| Throughput (base, GPU) | 0.67 img/sec | From official card; M-series will differ |

Handles documents, tables, mathematical formulas, and mixed layouts. Not just raw text extraction —
returns structured markdown output.

---

## Runtime on Mac

### Chosen path: MLX via `mlx-vlm`

| Attribute | Value |
|-----------|-------|
| **Package** | `mlx-vlm` |
| **MLX already installed** | Yes — `mlx 0.31.2`, `mlx-lm 0.31.3`, `mlx-metal 0.31.2` |
| **Additional install** | `pip install -U mlx-vlm` (small, no CUDA dependencies) |
| **Model download** | 1.59 GB on first run (auto-cached in `~/.cache/huggingface/`) |
| **Memory requirement** | ~2–3 GB unified memory (1.58 GB weights + runtime overhead) |
| **Hardware** | Apple M4 Pro, 48 GB unified memory — well within limits |
| **Dedicated GLM-OCR support** | Yes — `mlx_vlm/models/glm_ocr/` module exists in mlx-vlm |

**Speed estimate:** The base model benchmarks at 0.67 img/sec on GPU. On M4 Pro via MPS/MLX,
expect 0.3–0.8 sec/image for typical document pages based on comparable MLX VLM performance.
Exact figures require a timed run with the prototype.

### Alternative paths evaluated

| Runtime | Status | Notes |
|---------|--------|-------|
| **Ollama GGUF** | Possible but uncertain | `ollama run hf.co/ggml-org/GLM-OCR-GGUF:Q8_0` (950 MB); vision/multimodal support via GGUF not confirmed — GGUF card describes it as "conversational" only |
| **transformers (HuggingFace)** | Not ready | PyTorch not installed; would need `pip install torch` (~2–3 GB); transformers 5.6.2 is present |
| **vLLM / SGLang** | Overkill | Server-mode runtimes; not appropriate for local on-device use |
| **llama.cpp** | Not installed | Could work with Q8_0 GGUF (950 MB) but vision support uncertain |

MLX wins: smallest install delta, Apple-native, dedicated model support, confirmed working.

---

## Integration Plan

### Step 1 — Install mlx-vlm (one-time)
```bash
pip install -U mlx-vlm
```

### Step 2 — Run OCR on an image
```bash
python -m mlx_vlm.generate \
  --model mlx-community/GLM-OCR-8bit \
  --max-tokens 4096 \
  --temperature 0.0 \
  --prompt "Extract all text from this document. Preserve structure including tables and headers." \
  --image /path/to/document.jpg
```

Model auto-downloads (~1.59 GB) on first run and caches in `~/.cache/huggingface/`.

### Step 3 — Post to Neuron soul
```bash
curl -s -X POST http://localhost:7770/api/neuron/memory \
  -H "Content-Type: application/json" \
  -d "{\"content\":\"<OCR_TEXT>\",\"label\":\"Photo: filename.jpg\",\"tags\":[\"photo-import\",\"ocr\",\"glm-ocr\"]}"
```

### End-to-end prototype
See `~/Development/neuron-technologies/neuron/tools/photo-to-memory.sh` — working stub.

### Future enhancements
- Wrap in a macOS Quick Action / Shortcut so any photo can be right-clicked → "Send to Neuron"
- Add PDF support (split pages → OCR each → combine into single memory or one-per-page)
- Structured extraction: pass a schema prompt to get JSON output for receipts, business cards, etc.
- Batch mode for importing a folder of scanned documents

---

## Recommendation

Install `mlx-vlm` and run the prototype against a sample document to validate output quality and
measure actual M4 Pro throughput before wiring into any production flow. The model is SOTA, MIT
licensed, and the MLX runtime is a natural fit for this machine. There is no reason not to proceed.

The photo-to-memory.sh prototype is ready to test immediately after `pip install -U mlx-vlm`.
