Instructions to use tiny-random/glm-ocr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/glm-ocr with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tiny-random/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("tiny-random/glm-ocr") model = AutoModelForImageTextToText.from_pretrained("tiny-random/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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use tiny-random/glm-ocr with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/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": "tiny-random/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/tiny-random/glm-ocr
- SGLang
How to use tiny-random/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 "tiny-random/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": "tiny-random/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 "tiny-random/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": "tiny-random/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 tiny-random/glm-ocr with Docker Model Runner:
docker model run hf.co/tiny-random/glm-ocr
| { | |
| "architectures": [ | |
| "GlmOcrForConditionalGeneration" | |
| ], | |
| "dtype": "bfloat16", | |
| "image_end_token_id": 59257, | |
| "image_start_token_id": 59256, | |
| "image_token_id": 59280, | |
| "model_type": "glm_ocr", | |
| "text_config": { | |
| "attention_bias": false, | |
| "attention_dropout": 0.0, | |
| "dtype": "bfloat16", | |
| "eos_token_id": [ | |
| 59246, | |
| 59253 | |
| ], | |
| "head_dim": 32, | |
| "hidden_act": "silu", | |
| "hidden_size": 8, | |
| "initializer_range": 0.02, | |
| "intermediate_size": 64, | |
| "max_position_embeddings": 131072, | |
| "model_type": "glm_ocr_text", | |
| "num_attention_heads": 8, | |
| "num_hidden_layers": 2, | |
| "num_key_value_heads": 4, | |
| "num_nextn_predict_layers": 1, | |
| "pad_token_id": 59246, | |
| "rms_norm_eps": 1e-05, | |
| "rope_parameters": { | |
| "mrope_section": [ | |
| 4, | |
| 4, | |
| 8 | |
| ], | |
| "partial_rotary_factor": 1.0, | |
| "rope_theta": 10000, | |
| "rope_type": "default" | |
| }, | |
| "tie_word_embeddings": false, | |
| "use_cache": true, | |
| "vocab_size": 59392 | |
| }, | |
| "tie_word_embeddings": false, | |
| "transformers_version": "5.2.0.dev0", | |
| "video_end_token_id": 59259, | |
| "video_start_token_id": 59258, | |
| "video_token_id": 59281, | |
| "vision_config": { | |
| "attention_bias": true, | |
| "attention_dropout": 0.0, | |
| "depth": 2, | |
| "hidden_act": "silu", | |
| "hidden_dropout_prob": 0.0, | |
| "hidden_size": 32, | |
| "image_size": 336, | |
| "in_channels": 3, | |
| "initializer_range": 0.02, | |
| "intermediate_size": 64, | |
| "model_type": "glm_ocr_vision", | |
| "num_heads": 1, | |
| "out_hidden_size": 8, | |
| "patch_size": 14, | |
| "rms_norm_eps": 1e-05, | |
| "spatial_merge_size": 2, | |
| "temporal_patch_size": 2 | |
| } | |
| } | |