ComfyUI Node

GLM-OCR Run

Point it at a scan, get markdown and LaTeX back — this is the whole point of the pack

By Dangocan·Created 6 months ago·Updated 6 months ago· 3
GLM-OCR Run
  • glm_ocr_model
  • image
  • text
task_prompt
max_new_tokens2048
custom_prompt

GLM-OCR Run is where the comfyui_glm_ocr pack earns its keep. Feed it the model from GLM-OCR Model Loader, an image, and one of four task presets, and it hands you a STRING of actual text. A scanned page becomes plain text, a table becomes markdown, a formula becomes LaTeX. No API, no key, no Ollama - the 0.9B model from Z.ai (the Tsinghua spin-off that ships the GLM line under permissive licenses) runs entirely on your machine.

If your ComfyUI OCR experience so far is EasyOCR or PaddleOCR nodes, this is a different animal. Those detect and recognize text and give you bounding boxes - great for finding text, useless for understanding a document's structure. GLM-OCR is a vision-language model: it reads the whole image and returns structured output, which is exactly the shape you want before you pipe a scan into an LLM. The one thing it won't give you is coordinates. It's a reader, not a detector.

The settings that matter

Three inputs do 95% of the work:

  • task_prompt - the preset enum. Text Recognition: for everything on the page, Formula Recognition: for math as LaTeX, Table Recognition: for markdown tables, Describe the image. for a plain caption.
  • custom_prompt - leave empty to use the preset above, or type anything for an arbitrary question about the image. Watch for the subtle trap: even whitespace counts as "filled," and a custom prompt silently overrides the preset.
  • max_new_tokens - output length, default 2048, range 64–8192. Long tables or dense multi-column pages can hit the cap and get cut off mid-row; bump it before you blame the model.

It takes the loaded model, an IMAGE, and outputs text as a STRING - wire it into ShowText or any text node. It's also an output node, so the result shows in the UI even without ShowText. One real limitation buried in the source: it only processes the first image in a batch (image[0]). Feed it one image at a time.

Installing and the one dependency that bites

Clone into custom_nodes (or ComfyUI Manager → Install via Git URL), put the model in a checkpoint folder ComfyUI knows:

cd ComfyUI/custom_nodes
git clone https://github.com/Dangocan/comfyui_glm_ocr
huggingface-cli download zai-org/GLM-OCR --local-dir ComfyUI/models/checkpoints/GLM-OCR

Then the one that actually bites: GLM-OCR needs a very recent transformers. The glm_ocr architecture only exists in transformers>=5.3.0. If you get "does not recognize this architecture" or the model fails to load, install from source:

pip install git+https://github.com/huggingface/transformers.git

The loader node even prints that exact fix when it detects the failure, so you're not left guessing. The catch is that transformers is shared across every custom node you own - this is the classic ComfyUI dependency-hell situation, so upgrading it can quietly break another node that pins an older version. Check what else is riding on your transformers install before you upgrade, and keep a mental note of what you changed when something regresses.

The workflow, end to end

Load your scan or screenshot → GLM-OCR Model Loader (pick the model) → GLM-OCR Run (model, image, task prompt) → ShowText. That's the entire graph. Five minutes of setup, and suddenly your ComfyUI instance reads invoices, research papers, and whiteboard photos.

CategoryGLM-OCR

Inputs (5)

NameTypeDefaultDescription
glm_ocr_modelGLM_OCR_MODEL
imageIMAGE
task_promptCOMBO4 options: Text Recognition:, Formula Recognition:, Table Recognition:, Describe the image.
max_new_tokensINT204864–8192
custom_promptoptSTRING

Outputs (1)

NameTypeDescription
textSTRING