Skip to content
Back to search

GLM-OCR

GLM-OCR: Accurate × Fast × Comprehensive

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/zai-org--glm-ocr/badge.svg)](/listings/zai-org--glm-ocr)

HTML

<a href="/listings/zai-org--glm-ocr"><img src="/api/listings/zai-org--glm-ocr/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

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 .

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 353 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. ## GLM-OCR
  2. [中文阅读](README_zh.md)
  3. <div align="center">
  4. <img src=resources/logo.svg width="40%"/>
  5. </div>
  6. <p align="center">
  7. 👋 Join our <a href="resources/WECHAT.md" target="_blank">WeChat</a> and <a href="https://discord.gg/QR7SARHRxK" target="_blank">Discord</a> community
  8. <br>
  9. 📖 Check out the GLM-OCR <a href="https://arxiv.org/abs/2603.10910" target="_blank">technical report</a>
  10. <br>
  11. 📍 Use GLM-OCR's <a href="https://docs.z.ai/guides/vlm/glm-ocr" target="_blank">API</a>
  12. </p>
  13. ### Model Introduction
  14. 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.
  15. **Key Features**
  16. - **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.
  17. - **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.
  18. - **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.
  19. - **Easy to Use**: Fully open-sourced and equipped with a comprehensive [SDK](https://github.com/zai-org/GLM-OCR) and inference toolchain, offering simple installation, one-line invocation, and smooth integration into existing production pipelines.
  20. ### News & Updates
  21. - **[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](skills/glmocr/SKILL.md)
  22. - **[2026.3.12]** GLM-OCR Technical Report is now available. See: [GLM-OCR Technical Report](https://arxiv.org/abs/2603.10910)
  23. - **[2026.2.12]** Fine-tuning tutorial based on LLaMA-Factory is now available. See: [GLM-OCR Fine-tuning Guide](examples/finetune/README.md)
  24. ### Download Model
  25. | Model | Download Links | Precision |
  26. | ------- | --------------------------------------------------------------------------------------------------------------------------- | --------- |
  27. | GLM-OCR | [🤗 Hugging Face](https://huggingface.co/zai-org/GLM-OCR)<br> [🤖 ModelScope](https://modelscope.cn/models/ZhipuAI/GLM-OCR) | BF16 |
  28. ## GLM-OCR SDK
  29. We provide an SDK for using GLM-OCR more efficiently and conveniently.
  30. ### Install SDK
  31. Choose the lightest installation that matches your scenario:
  32. ```bash
  33. # Cloud / MaaS + local images / PDFs (fastest install)
  34. pip install glmocr
  35. # Self-hosted pipeline (layout detection)
  36. pip install "glmocr[selfhosted]"
  37. # Flask service support
  38. pip install "glmocr[server]"
  39. ```
  40. Install from source for development:
  41. ```bash
  42. # Install from source
  43. git clone https://github.com/zai-org/glm-ocr.git
  44. cd glm-ocr
  45. uv venv --python 3.12 --seed && source .venv/bin/activate
  46. uv pip install -e .
  47. ```
  48. ### Model Deployment
  49. Two ways to use GLM-OCR:
  50. #### Option 1: Zhipu MaaS API (Recommended for Quick Start)
  51. 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.
  52. 1. Get an API key from https://open.bigmodel.cn
  53. 2. Configure `config.yaml`:
  54. ```yaml
  55. pipeline:
  56. maas:
  57. enabled: true # Enable MaaS mode
  58. api_key: your-api-key # Required
  59. ```
  60. That's it! When `maas.enabled=true`, the SDK acts as a thin wrapper that:
  61. - Forwards your documents to the Zhipu cloud API
  62. - Returns the results directly (Markdown + JSON layout details)
  63. - No local processing, no GPU required
  64. Input note (MaaS): the upstream API accepts `file` as a URL or a `data:<mime>;base64,...` data URI.
  65. If you have raw base64 without the `data:` prefix, wrap it as a data URI (recommended). The SDK will
  66. auto-wrap local file paths / bytes / raw base64 into a data URI when calling MaaS.
  67. API documentation: https://docs.bigmodel.cn/cn/guide/models/vlm/glm-ocr
  68. #### Option 2: Self-host with vLLM / SGLang
  69. Deploy the GLM-OCR model locally for full control. The SDK provides the complete pipeline: layout detection, parallel region OCR, and result formatting.
  70. Install the self-hosted extra first:
  71. ```bash
  72. pip install "glmocr[selfhosted]"
  73. ```
  74. ##### Using vLLM
  75. Install vLLM:
  76. ```bash
  77. docker pull vllm/vllm-openai:v0.19.0-ubuntu2404
  78. ```
  79. Or using with pip:
  80. ```bash
  81. pip install -U "vllm>=0.19.0"
  82. ```
  83. Launch the service:
  84. ```bash
  85. pip install "transformers>=5.3.0"
  86. vllm serve zai-org/GLM-OCR --port 8080 --speculative-config '{"method": "mtp", "num_speculative_tokens": 3}' --served-model-name glm-ocr
  87. ```
  88. >Note
  89. Add `--max-model-len` and `--gpu-memory-utilization` according to Your own machine to handle large image/pdf
  90. ##### Using SGLang
  91. Install SGLang:
  92. ```bash
  93. docker pull lmsysorg/sglang:v0.5.10
  94. ```
  95. Or using with pip:
  96. ```bash
  97. pip install "sglang>=0.5.10"
  98. ```
  99. Launch the service:
  100. ```bash
  101. 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
  102. ```
  103. >Note
  104. Add `--context-len` and `--mem-fraction-static` according to Your own machine to handle large image/pdf
  105. #### Option 3: Ollama/MLX
  106. For specialized deployment scenarios, see the detailed guides:
  107. - **[Apple Silicon with mlx-vlm](examples/mlx-deploy/README.md)** - Optimized for Apple Silicon Macs
  108. - **[Ollama Deployment](examples/ollama-deploy/README.md)** - Simple local deployment with Ollama
  109. #### Option 4: SDK Server + Client (GPU-less Client)
  110. 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.
  111. ```yaml
  112. # Client config.yaml
  113. pipeline:
  114. maas:
  115. enabled: true
  116. api_url: http://<SERVER_IP>:5002/glmocr/parse
  117. api_key: any-string # self-hosted server does not validate keys
  118. verify_ssl: false
  119. ```
  120. See the full guide: **[Self-hosted SDK Server + Client](examples/self-host/README.md)**
  121. #### Update Configuration
  122. After launching the service, configure `config.yaml`:
  123. ```yaml
  124. pipeline:
  125. maas:
  126. enabled: false # Disable MaaS mode (default)
  127. ocr_api:
  128. api_host: localhost # or your vLLM/SGLang server address
  129. api_port: 8080
  130. ```
  131. ### SDK Usage Guide
  132. #### CLI
  133. ```bash
  134. # Parse a single image
  135. glmocr parse examples/source/code.png
  136. # Parse a directory
  137. glmocr parse examples/source/
  138. # Set output directory
  139. glmocr parse examples/source/code.png --output ./results/
  140. # Use a custom config
  141. glmocr parse examples/source/code.png --config my_config.yaml
  142. # Enable debug logging with profiling
  143. glmocr parse examples/source/code.png --log-level DEBUG
  144. # Run layout detection on CPU (keep GPU free for OCR model)
  145. glmocr parse examples/source/code.png --layout-device cpu
  146. # Run layout detection on a specific GPU
  147. glmocr parse examples/source/code.png --layout-device cuda:1
  148. # Override any config value via --set (dotted path, repeatable)
  149. glmocr parse examples/source/code.png --set pipeline.ocr_api.api_port 8080
  150. glmocr parse examples/source/ --set pipeline.layout.use_polygon true --set logging.level DEBUG
  151. ```
  152. #### Python API
  153. ```python
  154. from glmocr import GlmOcr, parse
  155. # Simple function
  156. result = parse("image.png")
  157. result = parse(["img1.png", "img2.jpg"])
  158. result = parse("https://example.com/image.png")
  159. result.save(output_dir="./results")
  160. # Note: a list is treated as pages of a single document.
  161. # Class-based API
  162. with GlmOcr() as parser:
  163. result = parser.parse("image.png")
  164. print(result.json_result)
  165. result.save()
  166. # Place layout model on CPU (useful when GPU is reserved for OCR)
  167. with GlmOcr(layout_device="cpu") as parser:
  168. result = parser.parse("image.png")
  169. # Place layout model on a specific GPU
  170. with GlmOcr(layout_device="cuda:1") as parser:
  171. result = parser.parse("image.png")
  172. ```
  173. #### Flask Service
  174. Install the optional server dependency first:
  175. ```bash
  176. pip install "glmocr[server]"
  177. ```
  178. ```bash
  179. # Start service
  180. python -m glmocr.server
  181. # With debug logging
  182. python -m glmocr.server --log-level DEBUG
  183. # Call API
  184. curl -X POST http://localhost:5002/glmocr/parse \
  185. -H "Content-Type: application/json" \
  186. -d '{"images": ["./example/source/code.png"]}'
  187. ```
  188. Semantics:
  189. - `images` can be a string or a list.
  190. - A list is treated as pages of a single document.
  191. - For multiple independent documents, call the endpoint multiple times (one document per request).
  192. ### Modular Architecture
  193. GLM-OCR uses composable modules for easy customization:
  194. | Component | Description |
  195. | --------------------- | -------------------------------------- |
  196. | `PageLoader` | Preprocessing and image encoding |
  197. | `OCRClient` | Calls the GLM-OCR model service |
  198. | `PPDocLayoutDetector` | PP-DocLayout layout detection |
  199. | `ResultFormatter` | Post-processing, outputs JSON/Markdown |
  200. You can extend the behavior by creating custom pipelines:
  201. ```python
  202. from glmocr.dataloader import PageLoader
  203. from glmocr.ocr_client import OCRClient
  204. from glmocr.postprocess import ResultFormatter
  205. class MyPipeline:
  206. def __init__(self, config):
  207. self.page_loader = PageLoader(config)
  208. self.ocr_client = OCRClient(config)
  209. self.formatter = ResultFormatter(config)
  210. def process(self, request_data):
  211. # Implement your own processing logic
  212. pass
  213. ```
  214. ## Star History
  215. <a href="https://www.star-history.com/?repos=zai-org%2FGLM-OCR&type=date&legend=top-left">
  216. <picture>
  217. <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/image?repos=zai-org/GLM-OCR&type=date&theme=dark&legend=top-left" />
  218. <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/image?repos=zai-org/GLM-OCR&type=date&legend=top-left" />
  219. <img alt="Star History Chart" src="https://api.star-history.com/image?repos=zai-org/GLM-OCR&type=date&legend=top-left" />
  220. </picture>
  221. </a>
  222. ## Acknowledgement
  223. This project is inspired by the excellent work of the following projects and communities:
  224. - [PP-DocLayout-V3](https://huggingface.co/PaddlePaddle/PP-DocLayoutV3)
  225. - [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR)
  226. - [MinerU](https://github.com/opendatalab/MinerU)
  227. ## License
  228. The Code of this repo is under Apache License 2.0.
  229. The GLM-OCR model is released under the MIT License.
  230. The complete OCR pipeline integrates [PP-DocLayoutV3](https://huggingface.co/PaddlePaddle/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.
  231. ## Citation
  232. If you find GLM-OCR useful in your research, please cite our technical report:
  233. ```bibtex
  234. @misc{duan2026glmocrtechnicalreport,
  235. title={GLM-OCR Technical Report},
  236. 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},
  237. year={2026},
  238. eprint={2603.10910},
  239. archivePrefix={arXiv},
  240. primaryClass={cs.CL},
  241. url={https://arxiv.org/abs/2603.10910},
  242. }
  243. ```

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.