GLM-OCR README

The project's README from github.com/zai-org/GLM-OCR. As one markdown file: README.md.

GLM-OCR

中文阅读

👋 Join our WeChat and Discord community
📖 Check out the GLM-OCR technical report
📍 Use GLM-OCR's API

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

News & Updates

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:

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.

  1. Get an API key from https://open.bigmodel.cn
  2. 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:

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-len and --gpu-memory-utilization according 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-len and --mem-fraction-static according to Your own machine to handle large image/pdf

Option 3: Ollama/MLX

For specialized deployment scenarios, see the detailed guides:

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:

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

Star History Chart

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},
}

GLM-OCR (zai-org/GLM-OCR)

Searching Database…

7.5K ·GitHub
这是什么?GLM-OCR 是一个多模态 OCR 模型,用于理解复杂文档,基于 GLM-V 编码器-解码器架构构建,并配有轻量级 SDK 和推理工具链。
这只是一个模型,还是一整套工具?两者都是:它包括一个 0.9B 参数的 OCR 模型,以及一个 Python SDK,提供 CLI、Python API 和 Flask 服务三种调用入口,并带有用于版面检测和结果格式化的模块化组件。
我该如何让它跑起来?先用 pip install glmocr 安装 SDK,然后可以选择用 API 密钥调用智谱托管的 MaaS 云端 API 快速上手,或者用 vLLM 或 SGLang 自行部署模型,以获得完整的本地控制。
处理大图片或 PDF 时需要调整什么参数吗?需要。自行部署时,应根据你的机器配置设置 vLLM 的 --max-model-len 和 --gpu-memory-utilization,或 SGLang 的 --context-len 和 --mem-fraction-static,以便处理大尺寸图片或 PDF 输入。
没有独立显卡的 Mac 能运行它吗?可以。我们提供了使用 mlx-vlm 在 Apple Silicon 上部署的专门指南,也可以通过 Ollama 进行简单的本地部署。
GLM-OCR 与其他 OCR 模型相比准确率如何?它在 OmniDocBench V1.5 上得分 94.62,综合排名第一,并在公式识别、表格识别和信息提取方面达到了业界领先水平。
明明要运行完整的文档处理流程,为什么还说它很快?GLM-OCR 只有 0.9B 参数,推理延迟和计算成本都很低,适合高并发服务和边缘部署。
GLM-OCR 能作为智能体技能使用吗?可以。SDK 支持对智能体友好的 Skill 模式:只需 pip install glmocr 加上一个 API 密钥,就能立即通过 CLI 或 Python 调用,无需 GPU,也不需要 YAML 配置。
这个 OCR 流程的内部结构是怎样的?它是模块化的:PageLoader 负责预处理,PPDocLayoutDetector 负责版面检测,OCRClient 调用 GLM-OCR 模型,ResultFormatter 输出 JSON 或 Markdown。每个部分都可以替换,以构建自定义流程。
Creator
zai-org
Size
98.2 MB
Stars
7.5K
Age
8mo
Commits · 90 Days