Instructions to use dots-studio/dots.ocr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use dots-studio/dots.ocr with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="dots-studio/dots.ocr", trust_remote_code=True) 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 AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("dots-studio/dots.ocr", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use dots-studio/dots.ocr with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "dots-studio/dots.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": "dots-studio/dots.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/dots-studio/dots.ocr
- SGLang
How to use dots-studio/dots.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 "dots-studio/dots.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": "dots-studio/dots.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 "dots-studio/dots.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": "dots-studio/dots.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 dots-studio/dots.ocr with Docker Model Runner:
docker model run hf.co/dots-studio/dots.ocr
Guard `cache_position` against `None` in `prepare_inputs_for_generation`
Guard cache_position against None in prepare_inputs_for_generation
prepare_inputs_for_generation subscripts cache_position unconditionally:
if cache_position[0] == 0:
model_inputs["pixel_values"] = pixel_values
Recent transformers releases pass cache_position=None on some generation paths, which crashes with TypeError: 'NoneType' object is not subscriptable at this line. The failure is content-dependent and version-dependent, which makes it confusing to hit in practice:
- transformers 5.14: fails on a subset of inputs — in our document-OCR benchmarking, 4 of 25 OmniDocBench pages crashed while the rest processed normally.
- transformers 5.12: fails immediately on the first generation call.
Full traceback (5.12, but the failing frame is identical on 5.14):
File ".../transformers/generation/utils.py", line 3824, in _prefill
model_inputs = self.prepare_inputs_for_generation(
File ".../modeling_dots_ocr.py", line 128, in prepare_inputs_for_generation
if cache_position[0] == 0:
TypeError: 'NoneType' object is not subscriptable
This PR adds the standard guard used by in-tree transformers models:
if cache_position is not None and cache_position[0] == 0:
Semantics are preserved: when cache_position is None, pixel_values is simply not re-attached for that step, matching the behavior of the equivalent guard in upstream transformers VLM implementations. Verified on the previously-crashing pages — they now generate and parse normally.