Instructions to use deepseek-ai/DeepSeek-OCR-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use deepseek-ai/DeepSeek-OCR-2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="deepseek-ai/DeepSeek-OCR-2", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("deepseek-ai/DeepSeek-OCR-2", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use deepseek-ai/DeepSeek-OCR-2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "deepseek-ai/DeepSeek-OCR-2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deepseek-ai/DeepSeek-OCR-2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/deepseek-ai/DeepSeek-OCR-2
- SGLang
How to use deepseek-ai/DeepSeek-OCR-2 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 "deepseek-ai/DeepSeek-OCR-2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deepseek-ai/DeepSeek-OCR-2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "deepseek-ai/DeepSeek-OCR-2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "deepseek-ai/DeepSeek-OCR-2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use deepseek-ai/DeepSeek-OCR-2 with Docker Model Runner:
docker model run hf.co/deepseek-ai/DeepSeek-OCR-2
Analysis on Prompt + Document Type Compatibility
Hello friends, a common issue we encounter when running this model is that it can go into an infinite loop of repetition and fail to give a good output.
This happens when the model's vision component and langauge component de-sync. Meaning the language model is no longer following the vision input but going on an adventure of its own.
As a specialist model, DeepSeek-OCR-2 is very senstive to prompting and giving the model a suitable prompt for the document/task is the key way to gain performance.
I've done some analysis on which prompt works best on which type of document.
Some findings:
- Document
<image>\n<|grounding|>Convert the document to markdown.is the best generalist prompt over<image>\nFree OCR. - General
<image>\nDescribe this image in detail.is the most reliable prompt, though it doesn't usually give you word for word output. - Rec
<image>\nLocate <|ref|>{OBJECT}<|/ref|> in the image.is effective with photos, but not documents.
You can view the full dataset, including exact model outputs, in an interactive web app here: https://deepseek-ocr-v2-demo.vercel.app
Curious to hear any creative uses of this model + performance tips.
确实是,markdown提示词确实有很大的提升,但是对于能给出精细坐标的\n<|grounding|>OCR this image.这个提示词,2相比于1似乎有相当大的劣势,尽管2在小部分图片上表现出了更高的坐标准确性和文字识别准确性,但是,2似乎经常陷入复读,漏字以及奇怪的部分区域漏识别,非常不稳定
老弟,你说的太好了。1在有些图章覆盖或者其他复杂环境下确实不如2,但是2在一些简单场景反而不如1。这就是大模型怪象,2不一定比1好
