自托管需先单独下载 zai-org/GLM-OCR 模型权重并启动 vLLM/SGLang 服务,SDK 本身不含模型;vLLM 需 transformers>=5.3.0 且版本不低于 0.19.0;MaaS 模式需在 config.yaml 填 api_key,自托管则要把 maas.enabled 设为 false 并配置 ocr_api 地址端口。
pip install glmocr
pip install "glmocr[selfhosted]"自托管需 GPU,可用 vLLM/SGLang 部署,需按机器调整 max-model-len 与显存占用;版面检测可单独放 CPU(--layout-device cpu)以腾出 GPU 给 OCR 模型;Apple Silicon 可用 mlx-vlm,也可走云端 MaaS API 完全不需要 GPU。
0.9B 参数的多模态 OCR 模型,面向复杂文档解析,兼顾精度与推理成本
GLM-OCR 是一个基于 GLM 的图片转文字 OCR 工具,主打高精度、高速度与全面覆盖,适合文档解析和 RAG 场景下的文字提取。
核心能力
- 基于 GLM-V 编解码架构,引入多 Token 预测损失
- 两阶段流水线:PP-DocLayout-V3 版面分析加并行区域识别
- OmniDocBench V1.5 得分 94.62,公式表格识别领先
- 支持 vLLM、SGLang、Ollama 与 MLX 多种部署方式
- 提供 SDK 一行调用,输出 Markdown 与 JSON 版面结果
容易踩的坑
- v0.1.5最新正式版2026-04-08 · 2026-04-08 06:22 UTC
What's Changed
- Update SKILL for Safety by @JaredforReal in https://github.com/zai-org/GLM-OCR/pull/148
- optimize md content by @SuperDongdongYan in https://github.com/zai-org/GLM-OCR/pull/150
- fix the skill markdown link by @dr-data in https://github.com/zai-org/GLM-OCR/pull/154
- Fix link path for GLM-OCR Skill mode update by @dr-data in https://github.com/zai-org/GLM-OCR/pull/155
- Fix reading maxsize values from config.py by @keefir in https://github.com/zai-org/GLM-OCR/pull/146
- add
modelto self-hosted mode by @JaredforReal in https://github.com/zai-org/GLM-OCR/pull/162 - Reconstruct pipeline by @Ataraxy33 in https://github.com/zai-org/GLM-OCR/pull/167
- fix(layout): repair self-hosted ENABLE_LAYOUT startup for PP-DocLayoutV3 by @stephan271c in https://github.com/zai-org/GLM-OCR/pull/186
- fix(layout): add
id2labelto LayoutConfig and guard missinglabel_task_mappingby @Manitchahar in https://github.com/zai-org/GLM-OCR/pull/104 - release v0.1.5 by @JaredforReal in https://github.com/zai-org/GLM-OCR/pull/188
New Contributors
- @dr-data made their first contribution in https://github.com/zai-org/GLM-OCR/pull/154
- @keefir made their first contribution in https://github.com/zai-org/GLM-OCR/pull/146
- @stephan271c made their first contribution in https://github.com/zai-org/GLM-OCR/pull/186
- @Manitchahar made their first contribution in https://github.com/zai-org/GLM-OCR/pull/104
Full Changelog: https://github.com/zai-org/GLM-OCR/compare/v0.1.4...v0.1.5
- v0.1.42026-03-19 · 2026-03-19 02:38 UTC
查看更新说明
What's Changed
- [Bug fix] Handle numpy arrays in polygon_points visualization by @VooDisss in https://github.com/zai-org/GLM-OCR/pull/135
- [Bug fix] Sanitize output directory and file names for Windows compatibility by @VooDisss in https://github.com/zai-org/GLM-OCR/pull/133
- Skill by @JaredforReal in https://github.com/zai-org/GLM-OCR/pull/139
- add meta data and requires by @JaredforReal in https://github.com/zai-org/GLM-OCR/pull/142
- [skill] update
ZHIPU_API_KEYby @JaredforReal in https://github.com/zai-org/GLM-OCR/pull/145 - feat: add skills about table, formula and handwriting by @SuperDongdongYan in https://github.com/zai-org/GLM-OCR/pull/143
- feat: add layout.device option for explicit device placement by @VooDisss in https://github.com/zai-org/GLM-OCR/pull/131
- Release by @JaredforReal in https://github.com/zai-org/GLM-OCR/pull/147
New Contributors
- @VooDisss made their first contribution in https://github.com/zai-org/GLM-OCR/pull/135
- @SuperDongdongYan made their first contribution in https://github.com/zai-org/GLM-OCR/pull/143
Full Changelog: https://github.com/zai-org/GLM-OCR/compare/v0.1.3...v0.1.4
- v0.1.32026-03-13 · 2026-03-13 04:40 UTC
查看更新说明
What's Changed
- clean up dependency by @JaredforReal in https://github.com/zai-org/GLM-OCR/pull/129
Full Changelog: https://github.com/zai-org/GLM-OCR/compare/v0.1.2...v0.1.3
- v0.1.22026-03-12 · 2026-03-12 10:32 UTC
查看更新说明
What's Changed
- add skills by @JaredforReal in https://github.com/zai-org/GLM-OCR/pull/126
- Cli by @JaredforReal in https://github.com/zai-org/GLM-OCR/pull/127
Full Changelog: https://github.com/zai-org/GLM-OCR/compare/v0.1.1...v0.1.2
- v0.1.12026-03-12 · 2026-03-12 07:24 UTC
查看更新说明
Full Changelog: https://github.com/zai-org/GLM-OCR/compare/1.1.0...v0.1.1
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
GLM-OCR
Model Introduction
GLM-OCR is a multimodal OCR model for complex document understanding, built on the GLM-V encoder–decoder architecture. It introduces Multi-Token Prediction (MTP) loss and stable full-task reinforcement learning to improve training efficiency, recognition accuracy, and generalization. The model integrates the CogViT visual encoder pre-trained on large-scale image–text data, a lightweight cross-modal connector with efficient token downsampling, and a GLM-0.5B language decoder. Combined with a two-stage pipeline of layout analysis and parallel recognition based on PP-DocLayout-V3, GLM-OCR delivers robust and high-quality OCR performance across diverse document layouts.
Key Features
-
State-of-the-Art Performance: Achieves a score of 94.62 on OmniDocBench V1.5, ranking #1 overall, and delivers state-of-the-art results across major document understanding benchmarks, including formula recognition, table recognition, and information extraction.
-
Optimized for Real-World Scenarios: Designed and optimized for practical business use cases, maintaining robust performance on complex tables, code-heavy documents, seals, and other challenging real-world layouts.
-
Efficient Inference: With only 0.9B parameters, GLM-OCR supports deployment via vLLM, SGLang, and Ollama, significantly reducing inference latency and compute cost, making it ideal for high-concurrency services and edge deployments.
-
Easy to Use: Fully open-sourced and equipped with a comprehensive SDK and inference toolchain, offering simple installation, one-line invocation, and smooth integration into existing production pipelines.
News & Updates
- [2026.3.12] GLM-OCR SDK now supports agent-friendly Skill mode — just
pip install glmocr+ set API key, ready to use via CLI or Python with no GPU or YAML config needed. See: GLM-OCR Skill - [2026.3.12] GLM-OCR Technical Report is now available. See: GLM-OCR Technical Report
- [2026.2.12] Fine-tuning tutorial based on LLaMA-Factory is now available. See: GLM-OCR Fine-tuning Guide
Download Model
| Model | Download Links | Precision |
|---|---|---|
| GLM-OCR | 🤗 Hugging Face 🤖 ModelScope | BF16 |
GLM-OCR SDK
We provide an SDK for using GLM-OCR more efficiently and conveniently.
Install SDK
Choose the lightest installation that matches your scenario:
# Cloud / MaaS + local images / PDFs (fastest install)
pip install glmocr
# Self-hosted pipeline (layout detection)
pip install "glmocr[selfhosted]"
# Flask service support
pip install "glmocr[server]"
Install from source for development:
# Install from source
git clone https://github.com/zai-org/glm-ocr.git
cd glm-ocr
uv venv --python 3.12 --seed && source .venv/bin/activate
uv pip install -e .
Model Deployment
Two ways to use GLM-OCR:
Option 1: Zhipu MaaS API (Recommended for Quick Start)
Use the hosted cloud API – no GPU needed. The cloud service runs the complete GLM-OCR pipeline internally, so the SDK simply forwards your request and returns the result.
- Get an API key from https://open.bigmodel.cn
- Configure
config.yaml:
pipeline:
maas:
enabled: true # Enable MaaS mode
api_key: your-api-key # Required
That's it! When maas.enabled=true, the SDK acts as a thin wrapper that:
- Forwards your documents to the Zhipu cloud API
- Returns the results directly (Markdown + JSON layout details)
- No local processing, no GPU required
Input note (MaaS): the upstream API accepts file as a URL or a data:<mime>;base64,... data URI.
If you have raw base64 without the data: prefix, wrap it as a data URI (recommended). The SDK will
auto-wrap local file paths / bytes / raw base64 into a data URI when calling MaaS.
API documentation: https://docs.bigmodel.cn/cn/guide/models/vlm/glm-ocr
Option 2: Self-host with vLLM / SGLang
Deploy the GLM-OCR model locally for full control. The SDK provides the complete pipeline: layout detection, parallel region OCR, and result formatting.
Install the self-hosted extra first:
pip install "glmocr[selfhosted]"
Using vLLM
Install vLLM:
docker pull vllm/vllm-openai:v0.19.0-ubuntu2404
Or using with pip:
pip install -U "vllm>=0.19.0"
Launch the service:
pip install "transformers>=5.3.0"
vllm serve zai-org/GLM-OCR --port 8080 --speculative-config '{"method": "mtp", "num_speculative_tokens": 3}' --served-model-name glm-ocr
Note Add
--max-model-lenand--gpu-memory-utilizationaccording to Your own machine to handle large image/pdf
Using SGLang
Install SGLang:
docker pull lmsysorg/sglang:v0.5.10
Or using with pip:
pip install "sglang>=0.5.10"
Launch the service:
SGLANG_ENABLE_SPEC_V2=1 sglang serve --model-path zai-org/GLM-OCR --port 8080 --speculative-algorithm NEXTN --speculative-num-steps 3 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4 --served-model-name glm-ocr
Note Add
--context-lenand--mem-fraction-staticaccording to Your own machine to handle large image/pdf
Option 3: Ollama/MLX
For specialized deployment scenarios, see the detailed guides:
- Apple Silicon with mlx-vlm - Optimized for Apple Silicon Macs
- Ollama Deployment - Simple local deployment with Ollama
Option 4: SDK Server + Client (GPU-less Client)
Deploy the SDK Server on a GPU machine, then use any machine as a client — no GPU needed on the client side. The client connects via the MaaS-compatible protocol, pointing api_url at your self-hosted server.
# Client config.yaml
pipeline:
maas:
enabled: true
api_url: http://<SERVER_IP>:5002/glmocr/parse
api_key: any-string # self-hosted server does not validate keys
verify_ssl: false
See the full guide: Self-hosted SDK Server + Client
Update Configuration
After launching the service, configure config.yaml:
pipeline:
maas:
enabled: false # Disable MaaS mode (default)
ocr_api:
api_host: localhost # or your vLLM/SGLang server address
api_port: 8080
SDK Usage Guide
CLI
# Parse a single image
glmocr parse examples/source/code.png
# Parse a directory
glmocr parse examples/source/
# Set output directory
glmocr parse examples/source/code.png --output ./results/
# Use a custom config
glmocr parse examples/source/code.png --config my_config.yaml
# Enable debug logging with profiling
glmocr parse examples/source/code.png --log-level DEBUG
# Run layout detection on CPU (keep GPU free for OCR model)
glmocr parse examples/source/code.png --layout-device cpu
# Run layout detection on a specific GPU
glmocr parse examples/source/code.png --layout-device cuda:1
# Override any config value via --set (dotted path, repeatable)
glmocr parse examples/source/code.png --set pipeline.ocr_api.api_port 8080
glmocr parse examples/source/ --set pipeline.layout.use_polygon true --set logging.level DEBUG
Python API
from glmocr import GlmOcr, parse
# Simple function
result = parse("image.png")
result = parse(["img1.png", "img2.jpg"])
result = parse("https://example.com/image.png")
result.save(output_dir="./results")
# Note: a list is treated as pages of a single document.
# Class-based API
with GlmOcr() as parser:
result = parser.parse("image.png")
print(result.json_result)
result.save()
# Place layout model on CPU (useful when GPU is reserved for OCR)
with GlmOcr(layout_device="cpu") as parser:
result = parser.parse("image.png")
# Place layout model on a specific GPU
with GlmOcr(layout_device="cuda:1") as parser:
result = parser.parse("image.png")
Flask Service
Install the optional server dependency first:
pip install "glmocr[server]"
# Start service
python -m glmocr.server
# With debug logging
python -m glmocr.server --log-level DEBUG
# Call API
curl -X POST http://localhost:5002/glmocr/parse \
-H "Content-Type: application/json" \
-d '{"images": ["./example/source/code.png"]}'
Semantics:
imagescan be a string or a list.- A list is treated as pages of a single document.
- For multiple independent documents, call the endpoint multiple times (one document per request).
Modular Architecture
GLM-OCR uses composable modules for easy customization:
| Component | Description |
|---|---|
PageLoader | Preprocessing and image encoding |
OCRClient | Calls the GLM-OCR model service |
PPDocLayoutDetector | PP-DocLayout layout detection |
ResultFormatter | Post-processing, outputs JSON/Markdown |
You can extend the behavior by creating custom pipelines:
from glmocr.dataloader import PageLoader
from glmocr.ocr_client import OCRClient
from glmocr.postprocess import ResultFormatter
class MyPipeline:
def __init__(self, config):
self.page_loader = PageLoader(config)
self.ocr_client = OCRClient(config)
self.formatter = ResultFormatter(config)
def process(self, request_data):
# Implement your own processing logic
pass
Star History
Acknowledgement
This project is inspired by the excellent work of the following projects and communities:
License
The Code of this repo is under Apache License 2.0.
The GLM-OCR model is released under the MIT License.
The complete OCR pipeline integrates PP-DocLayoutV3 for document layout analysis, which is licensed under the Apache License 2.0. Users should comply with both licenses when using this project.
Citation
If you find GLM-OCR useful in your research, please cite our technical report:
@misc{duan2026glmocrtechnicalreport,
title={GLM-OCR Technical Report},
author={Shuaiqi Duan and Yadong Xue and Weihan Wang and Zhe Su and Huan Liu and Sheng Yang and Guobing Gan and Guo Wang and Zihan Wang and Shengdong Yan and Dexin Jin and Yuxuan Zhang and Guohong Wen and Yanfeng Wang and Yutao Zhang and Xiaohan Zhang and Wenyi Hong and Yukuo Cen and Da Yin and Bin Chen and Wenmeng Yu and Xiaotao Gu and Jie Tang},
year={2026},
eprint={2603.10910},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2603.10910},
}