GLM-OCR Local Deployment: Ollama vs vLLM vs SGLang
Compare different local deployment options for GLM-OCR including Ollama, vLLM, and SGLang. Learn which option is best for your use case.
Introduction
GLM-OCR supports multiple local deployment options, each with different trade-offs between ease of use, performance, and flexibility. This guide compares Ollama, vLLM, and SGLang to help you choose the right option.
Deployment Options Overview
| Feature | Ollama | vLLM | SGLang |
|---|---|---|---|
| Ease of Setup | Very Easy | Moderate | Moderate |
| Performance | Good | Excellent | Excellent |
| GPU Memory | Efficient | High | High |
| Batching | Basic | Advanced | Advanced |
| Production Ready | Yes | Yes | Yes |
| Best For | Development | Production | Production |
Option 1: Ollama
Ollama is the simplest way to run GLM-OCR locally.
Installation
# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh
# Pull GLM-OCR model
ollama pull glm-ocrAvailable Models
| Model | Size | Use Case |
|---|---|---|
| glm-ocr:latest | 2.2GB | Default, balanced |
| glm-ocr:q8_0 | 1.6GB | Memory constrained |
| glm-ocr:bf16 | 2.2GB | Best quality |
Usage
# Interactive mode
ollama run glm-ocr
# Direct recognition
ollama run glm-ocr Text Recognition: ./document.png
ollama run glm-ocr Table Recognition: ./table.pngAPI Server
# Start Ollama server (runs by default)
ollama serve
# API call
curl http://localhost:11434/api/generate -d '{
"model": "glm-ocr",
"prompt": "Text Recognition:",
"images": ["base64_encoded_image"]
}'Pros and Cons
Pros:
- One-line installation
- Simple CLI interface
- Automatic model management
- Low memory footprint with quantized models
Cons:
- Limited batching capabilities
- Less control over inference parameters
- Not optimized for high-throughput scenarios
Option 2: vLLM
vLLM provides high-performance inference with advanced batching.
Installation
# Install vLLM
pip install -U vllm --extra-index-url https://wheels.vllm.ai/nightly
# Install Transformers (required for GLM-OCR)
pip install git+https://github.com/huggingface/transformers.gitStart Server
vllm serve zai-org/GLM-OCR \
--allowed-local-media-path / \
--port 8080 \
--tensor-parallel-size 1 \
--max-model-len 8192Configuration Options
| Option | Description | Default |
|---|---|---|
--tensor-parallel-size | Number of GPUs | 1 |
--max-model-len | Max context length | 8192 |
--gpu-memory-utilization | GPU memory usage | 0.9 |
--max-num-batched-tokens | Batch size | 8192 |
API Usage
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8080/v1",
api_key="not-needed"
)
response = client.chat.completions.create(
model="zai-org/GLM-OCR",
messages=[{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "file:///path/to/image.png"}},
{"type": "text", "text": "Text Recognition:"}
]
}],
max_tokens=4096
)Pros and Cons
Pros:
- Excellent throughput with continuous batching
- OpenAI-compatible API
- Advanced memory management
- Production-ready
Cons:
- Higher GPU memory requirements
- More complex setup
- Requires CUDA
Option 3: SGLang
SGLang offers efficient serving with advanced scheduling.
Installation
pip install sglang
pip install git+https://github.com/huggingface/transformers.gitStart Server
python -m sglang.launch_server \
--model zai-org/GLM-OCR \
--port 8080 \
--tp 1Configuration Options
| Option | Description | Default |
|---|---|---|
--tp | Tensor parallelism | 1 |
--dp | Data parallelism | 1 |
--mem-fraction-static | Static memory | 0.8 |
API Usage
import sglang as sgl
@sgl.function
def ocr_recognition(s, image_path, task="Text Recognition:"):
s += sgl.user(sgl.image(image_path) + task)
s += sgl.assistant(sgl.gen("response", max_tokens=4096))
# Run
state = ocr_recognition.run(image_path="document.png")
print(state["response"])Pros and Cons
Pros:
- Efficient RadixAttention for caching
- Advanced scheduling algorithms
- Good for complex workflows
- Supports structured generation
Cons:
- Newer, less mature ecosystem
- Steeper learning curve
- Requires CUDA
Performance Comparison
Throughput Test
Test conditions: 100 A4 document images, single GPU (RTX 4090)
| Deployment | Throughput | Latency (p50) | Latency (p99) |
|---|---|---|---|
| Ollama | 0.5 img/s | 1.8s | 3.2s |
| vLLM | 1.8 img/s | 0.5s | 1.2s |
| SGLang | 1.7 img/s | 0.6s | 1.3s |
Memory Usage
| Deployment | GPU Memory | System RAM |
|---|---|---|
| Ollama (q8_0) | 4GB | 2GB |
| Ollama (bf16) | 6GB | 2GB |
| vLLM | 8GB | 4GB |
| SGLang | 8GB | 4GB |
Choosing the Right Option
Use Ollama When:
- Quick prototyping and development
- Limited GPU memory (< 8GB)
- Simple CLI-based workflows
- Single-user scenarios
Use vLLM When:
- Production deployment
- High-throughput requirements
- OpenAI API compatibility needed
- Multiple concurrent users
Use SGLang When:
- Complex multi-step workflows
- Need for structured generation
- Advanced caching requirements
- Research and experimentation
Docker Deployment
Ollama Docker
FROM ollama/ollama
RUN ollama pull glm-ocr
EXPOSE 11434
CMD ["ollama", "serve"]vLLM Docker
FROM vllm/vllm-openai:latest
ENV MODEL_NAME=zai-org/GLM-OCR
CMD ["--model", "${MODEL_NAME}", "--port", "8080"]Docker Compose
version: '3.8'
services:
glm-ocr:
image: vllm/vllm-openai:latest
ports:
- "8080:8080"
volumes:
- ./models:/root/.cache/huggingface
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
command: ["--model", "zai-org/GLM-OCR", "--port", "8080"]Monitoring and Scaling
Health Checks
import requests
def check_health(endpoint):
try:
response = requests.get(f"{endpoint}/health")
return response.status_code == 200
except:
return FalseLoad Balancing
upstream glm_ocr {
server localhost:8080;
server localhost:8081;
server localhost:8082;
}
server {
listen 80;
location / {
proxy_pass http://glm_ocr;
}
}Conclusion
Each deployment option has its strengths:
- Ollama: Best for development and simple use cases
- vLLM: Best for production with high throughput needs
- SGLang: Best for complex workflows and research
Choose based on your specific requirements for performance, ease of use, and deployment environment.
Related Articles
Author
Categories
More Posts
Mathematical Formula Recognition: GLM-OCR LaTeX Output Guide
Learn how to use GLM-OCR for high-accuracy mathematical formula recognition with LaTeX output, perfect for academic documents and scientific papers.
Complex Table Recognition: How GLM-OCR Handles Merged Cells
Learn how GLM-OCR excels at recognizing complex tables with merged cells, multi-level headers, and diverse layouts commonly found in business documents.
GLM-OCR Quick Start: Complete Document Parsing Guide
Learn how to get started with GLM-OCR for document parsing. This guide covers API integration, Ollama local deployment, vLLM, and SGLang deployment options.