Instructions to use ctogaurav/GLM_OCR-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use ctogaurav/GLM_OCR-GGUF with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf ctogaurav/GLM_OCR-GGUF:Q8_0 # Run inference directly in the terminal: llama cli -hf ctogaurav/GLM_OCR-GGUF:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf ctogaurav/GLM_OCR-GGUF:Q8_0 # Run inference directly in the terminal: llama cli -hf ctogaurav/GLM_OCR-GGUF:Q8_0
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf ctogaurav/GLM_OCR-GGUF:Q8_0 # Run inference directly in the terminal: ./llama-cli -hf ctogaurav/GLM_OCR-GGUF:Q8_0
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf ctogaurav/GLM_OCR-GGUF:Q8_0 # Run inference directly in the terminal: ./build/bin/llama-cli -hf ctogaurav/GLM_OCR-GGUF:Q8_0
Use Docker
docker model run hf.co/ctogaurav/GLM_OCR-GGUF:Q8_0
- LM Studio
- Jan
- Ollama
How to use ctogaurav/GLM_OCR-GGUF with Ollama:
ollama run hf.co/ctogaurav/GLM_OCR-GGUF:Q8_0
- Unsloth Studio
How to use ctogaurav/GLM_OCR-GGUF with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ctogaurav/GLM_OCR-GGUF to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ctogaurav/GLM_OCR-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for ctogaurav/GLM_OCR-GGUF to start chatting
- Pi
How to use ctogaurav/GLM_OCR-GGUF with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf ctogaurav/GLM_OCR-GGUF:Q8_0
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "ctogaurav/GLM_OCR-GGUF:Q8_0" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use ctogaurav/GLM_OCR-GGUF with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf ctogaurav/GLM_OCR-GGUF:Q8_0
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default ctogaurav/GLM_OCR-GGUF:Q8_0
Run Hermes
hermes
- Atomic Chat new
- OpenClaw new
How to use ctogaurav/GLM_OCR-GGUF with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf ctogaurav/GLM_OCR-GGUF:Q8_0
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "ctogaurav/GLM_OCR-GGUF:Q8_0" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
- Docker Model Runner
How to use ctogaurav/GLM_OCR-GGUF with Docker Model Runner:
docker model run hf.co/ctogaurav/GLM_OCR-GGUF:Q8_0
- Lemonade
How to use ctogaurav/GLM_OCR-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull ctogaurav/GLM_OCR-GGUF:Q8_0
Run and chat with the model
lemonade run user.GLM_OCR-GGUF-Q8_0
List all available models
lemonade list
GLM-OCR v4.1 β GGUF (for LM Studio / Ollama / llama.cpp)
GGUF conversion of ctogaurav/GLM_OCR v4.1 β the LoRA adapter merged into zai-org/GLM-OCR and converted for local, single-file inference. Verified working β tested end-to-end on GPU, output checked against the model's own validated ground truth (see below), not just "conversion succeeded."
Files
Both versions are available. Each needs two files β the language model and its vision
projector (mmproj). Download both files of whichever version you want, into the same folder.
| Version | Files | Size |
|---|---|---|
| v4.1 | v4.1/GLM-OCR-v4.1-Q8_0.gguf + v4.1/mmproj-GLM-OCR-v4.1-Q8_0.gguf |
~683 MB + ~485 MB |
| v3.1 | v3.1/GLM-OCR-v3.1-Q8_0.gguf + v3.1/mmproj-GLM-OCR-v3.1-Q8_0.gguf |
~683 MB + ~485 MB |
Which to pick: v4.1 has lower character error rate and better content metrics; v3.1 compiles to a valid PDF more often (88.9% vs 82.4%). See the main model card for the full comparison.
LM Studio detects the mmproj file automatically when it's named mmproj-* alongside the main
model. With llama.cpp directly:
llama-mtmd-cli -m GLM-OCR-v4.1-Q8_0.gguf --mmproj mmproj-GLM-OCR-v4.1-Q8_0.gguf --image page.png \
-p "OCR this handwritten math page. Convert ONLY the handwritten mathematical content into a
complete, compilable LaTeX document. Ignore printed text, student info, page numbers,
cancelled work and rough work. Output only LaTeX." \
-n 2048 --temp 0 --repeat-penalty 1.0 -c 8192
β οΈ Required settings β read this if output repeats forever
The most common failure is the model looping the same line endlessly instead of finishing. This is almost always a configuration mismatch, not a broken model. Required settings:
| Setting | Value | Why |
|---|---|---|
| Context length | β₯ 8192 | The image alone consumes ~1536 tokens. At 2048 context the image fails to decode outright; too-small contexts are a prime cause of degenerate output. This is the #1 thing to check. |
| Temperature | 0 |
The model was fine-tuned and benchmarked with greedy decoding. |
| Repeat penalty | 1.0 (off) |
Matches training/benchmark conditions. |
| Max output tokens | 2048 |
Matches the benchmark cap. |
| System prompt | empty | The fine-tune never saw a system prompt. LM Studio injects "You are a helpful assistant" by default β clear it. |
| Prompt | use the exact prompt above, verbatim | The model was fine-tuned on this specific instruction; paraphrasing degrades it. |
β οΈ Resize your images first (the #1 cause of runaway repetition)
These adapters were fine-tuned at 1536 image tokens β 1.2 megapixels. A full-resolution scan or phone photo is typically 8β14 MP β around 10Γ more image tokens than the model ever saw in training. That is far enough off-distribution that the model degenerates into repeating the same line until it hits the token cap.
llama-mtmd-cli downscales to the budget automatically. LM Studio does not. A 14 MP photo
there produces ~17,800 prompt tokens, versus ~1,650 when sized correctly.
Resize to roughly 1.2 MP (about 920Γ1300 for a portrait page) before uploading. A helper script is in the code repo:
python tools/resize_for_ocr.py page.jpg # -> page_ocr.png
python tools/resize_for_ocr.py scans/ -o ready/ # whole folder
Verified: the same page that loops at full resolution transcribes completely and terminates
correctly with \end{document} once resized to 1.2 MP.
Using Ollama? There's a second option: tools/ocr_proxy.py
resizes images automatically, transparently, for every request β no manual step per image.
pip install flask requests pillow
python tools/ocr_proxy.py # listens on :11500
$env:OLLAMA_HOST = "http://localhost:11500" # PowerShell
ollama run glm-ocr-v4.1 "...prompt... unresized_page.jpg" # works, gets resized in transit
Verified end-to-end: an 8.7 MP image that fails outright on context size, sent through the proxy, comes back as clean, correctly-terminated LaTeX with zero manual resizing.
This only covers Ollama (its CLI, or any app you can point at a custom OLLAMA_HOST/API
URL) or LM Studio's separate "Local Server" mode, if you use that instead of its chat window.
It cannot help LM Studio's built-in chat window β that talks directly to LM Studio's
internal engine with no configurable network endpoint, so nothing external can intercept it.
For that interface, resize manually with resize_for_ocr.py first β there's no way around it.
Honest caveat: even correctly configured, the model does not succeed on every page β its measured PDF compile rate is 82.4% (v4.1) / 88.9% (v3.1) on held-out data. Long, repetitive pages (e.g. multi-step matrix row reductions where consecutive steps look nearly identical) are the hardest case. That ~11β18% failure rate is a property of the model, documented in the project's own benchmark β not a defect introduced by this GGUF conversion.
A real bug we hit and fixed (useful if you're converting this architecture yourself)
Naively running convert_hf_to_gguf.py on this checkpoint fails to load with
missing tensor 'blk.16.attn_norm.weight'. Root cause: GlmOcrForConditionalGeneration's
conversion code sets block_count = num_hidden_layers + num_nextn_predict_layers (16 + 1 = 17),
reserving a 17th block for a NextN/multi-token-prediction head β but the publicly released
zai-org/GLM-OCR checkpoint (loaded via AutoModelForImageTextToText) doesn't actually ship
those NextN weights. The official ggml-org/GLM-OCR-GGUF quant does include them (as unused
tensors β llama.cpp's own loader logs unused tensor blk.16... ignoring for them), presumably
converted from a checkpoint variant that has them.
Fix: patch conversion/glm.py's GlmOCRModel.__init__ to drop the + num_nextn_predict_layers
term, so block_count matches what's actually in the checkpoint (16). Since NextN is confirmed
unused at inference time regardless, this has no effect on output quality β verified by direct
comparison against ground truth (below).
Verification, not just "it ran"
Tested against ctogaurav/GLM_OCR's own samples/ (2 pages with known, pdflatex-validated
ground truth). Output matched the validated transcription almost verbatim β this confirms the
merge + conversion + quantization pipeline preserves the fine-tuned model's actual behavior,
not just that the file loads.
Additionally stress-tested on a multi-step matrix row-reduction page (the hardest known case for
this model β consecutive near-identical matrices are what typically triggers runaway repetition).
With the settings above, v4.1 transcribed it fully and terminated correctly with
\end{document}. Both versions were verified this way before upload.
License
MIT, same as the base model and the source adapter β free to use, redistribute, and modify, including commercially.
Links
- Source adapter (PEFT, not merged): ctogaurav/GLM_OCR
- Code / full pipeline: github.com/realgauravvyas/ocr2tex
- Base model: zai-org/GLM-OCR
- Downloads last month
- 89
8-bit
Model tree for ctogaurav/GLM_OCR-GGUF
Base model
zai-org/GLM-OCR