Instructions to use zai-org/GLM-OCR with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zai-org/GLM-OCR with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="zai-org/GLM-OCR") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoTokenizer, AutoModelForImageTextToText tokenizer = AutoTokenizer.from_pretrained("zai-org/GLM-OCR") model = AutoModelForImageTextToText.from_pretrained("zai-org/GLM-OCR") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use zai-org/GLM-OCR with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "zai-org/GLM-OCR" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/GLM-OCR", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/zai-org/GLM-OCR
- SGLang
How to use zai-org/GLM-OCR with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "zai-org/GLM-OCR" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/GLM-OCR", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "zai-org/GLM-OCR" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zai-org/GLM-OCR", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use zai-org/GLM-OCR with Docker Model Runner:
docker model run hf.co/zai-org/GLM-OCR
Add OlmOCRBench evaluation results
#43
by staghado - opened
.eval_results/olmocrbench.yaml
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
- dataset:
|
| 2 |
+
id: allenai/olmOCR-bench
|
| 3 |
+
task_id: overall
|
| 4 |
+
value: 75.2
|
| 5 |
+
notes: "Excluding Headers & Footers category. Using ZAI API."
|
| 6 |
+
source:
|
| 7 |
+
url: https://huggingface.co/zai-org/GLM-OCR
|
| 8 |
+
name: GLM-OCR API evaluation
|
| 9 |
+
user: staghado
|
| 10 |
+
- dataset:
|
| 11 |
+
id: allenai/olmOCR-bench
|
| 12 |
+
task_id: arxiv_math
|
| 13 |
+
value: 80.7
|
| 14 |
+
source:
|
| 15 |
+
url: https://huggingface.co/zai-org/GLM-OCR
|
| 16 |
+
name: GLM-OCR API evaluation
|
| 17 |
+
user: staghado
|
| 18 |
+
- dataset:
|
| 19 |
+
id: allenai/olmOCR-bench
|
| 20 |
+
task_id: old_scans_math
|
| 21 |
+
value: 68.3
|
| 22 |
+
source:
|
| 23 |
+
url: https://huggingface.co/zai-org/GLM-OCR
|
| 24 |
+
name: GLM-OCR API evaluation
|
| 25 |
+
user: staghado
|
| 26 |
+
- dataset:
|
| 27 |
+
id: allenai/olmOCR-bench
|
| 28 |
+
task_id: table_tests
|
| 29 |
+
value: 77.6
|
| 30 |
+
source:
|
| 31 |
+
url: https://huggingface.co/zai-org/GLM-OCR
|
| 32 |
+
name: GLM-OCR API evaluation
|
| 33 |
+
user: staghado
|
| 34 |
+
- dataset:
|
| 35 |
+
id: allenai/olmOCR-bench
|
| 36 |
+
task_id: old_scans
|
| 37 |
+
value: 37.6
|
| 38 |
+
source:
|
| 39 |
+
url: https://huggingface.co/zai-org/GLM-OCR
|
| 40 |
+
name: GLM-OCR API evaluation
|
| 41 |
+
user: staghado
|
| 42 |
+
- dataset:
|
| 43 |
+
id: allenai/olmOCR-bench
|
| 44 |
+
task_id: multi_column
|
| 45 |
+
value: 76.7
|
| 46 |
+
source:
|
| 47 |
+
url: https://huggingface.co/zai-org/GLM-OCR
|
| 48 |
+
name: GLM-OCR API evaluation
|
| 49 |
+
user: staghado
|
| 50 |
+
- dataset:
|
| 51 |
+
id: allenai/olmOCR-bench
|
| 52 |
+
task_id: long_tiny_text
|
| 53 |
+
value: 86.9
|
| 54 |
+
source:
|
| 55 |
+
url: https://huggingface.co/zai-org/GLM-OCR
|
| 56 |
+
name: GLM-OCR API evaluation
|
| 57 |
+
user: staghado
|
| 58 |
+
- dataset:
|
| 59 |
+
id: allenai/olmOCR-bench
|
| 60 |
+
task_id: headers_footers
|
| 61 |
+
value: 95.8
|
| 62 |
+
source:
|
| 63 |
+
url: https://huggingface.co/zai-org/GLM-OCR
|
| 64 |
+
name: GLM-OCR API evaluation
|
| 65 |
+
user: staghado
|
| 66 |
+
- dataset:
|
| 67 |
+
id: allenai/olmOCR-bench
|
| 68 |
+
task_id: baseline
|
| 69 |
+
value: 98.8
|
| 70 |
+
source:
|
| 71 |
+
url: https://huggingface.co/zai-org/GLM-OCR
|
| 72 |
+
name: GLM-OCR API evaluation
|
| 73 |
+
user: staghado
|