davanstrien/deepseek-ocr
0
DeepSeek-OCR with vLLM
High-performance document OCR using DeepSeek-OCR with vLLM for efficient batch processing.
๐ Quick Start with HuggingFace Jobs
Process any image dataset without needing your own GPU:
# Basic usage (Gundam mode - adaptive resolution)
hf jobs run --flavor l4x1 \
--secrets HF_TOKEN \
hf.co/spaces/davanstrien/deepseek-ocr \
python process_dataset.py \
input-dataset \
output-dataset
# Quick test with 10 samples
hf jobs run --flavor l4x1 \
--secrets HF_TOKEN \
hf.co/spaces/davanstrien/deepseek-ocr \
python process_dataset.py \
your-input-dataset \
your-output-dataset \
--max-samples 10That's it! The script will:
- โ Process images from your dataset
- โ
Add OCR results as a new
markdowncolumn - โ Push results to a new dataset with automatic documentation
- ๐ View results at:
https://huggingface.co/datasets/[your-output-dataset]
๐ Features
Model Capabilities
- ๐ LaTeX equations - Mathematical formulas preserved in LaTeX format
- ๐ Tables - Extracted and formatted as HTML/markdown
- ๐ Document structure - Headers, lists, and formatting maintained
- ๐ผ๏ธ Image grounding - Spatial layout and bounding box information
- ๐ Complex layouts - Multi-column and hierarchical structures
- ๐ Multilingual - Supports multiple languages
Performance
- โก vLLM AsyncEngine - Optimized for throughput (~2500 tokens/s on A100)
- ๐ฏ Multiple resolution modes - Choose speed vs quality
- ๐ฅ Large context - Up to 8K tokens
- ๐ช Batch optimized - Efficient async processing
๐๏ธ Resolution Modes
๐ป Usage Examples
Basic Processing
# Default (Gundam mode)
hf jobs run --flavor l4x1 --secrets HF_TOKEN \
hf.co/spaces/davanstrien/deepseek-ocr \
python process_dataset.py \
my-images-dataset \
ocr-resultsFast Processing for Testing
hf jobs run --flavor l4x1 --secrets HF_TOKEN \
hf.co/spaces/davanstrien/deepseek-ocr \
python process_dataset.py \
large-dataset \
test-output \
--max-samples 100Random Sampling
hf jobs run --flavor l4x1 --secrets HF_TOKEN \
hf.co/spaces/davanstrien/deepseek-ocr \
python process_dataset.py \
ordered-dataset \
random-sample \
--max-samples 50 \
--shuffle \
--seed 42Custom Image Column
hf jobs run --flavor a10g-large --secrets HF_TOKEN \
hf.co/spaces/davanstrien/deepseek-ocr \
python process_dataset.py \
davanstrien/ufo-ColPali \
ufo-ocr \
--image-column imagePrivate Output Dataset
hf jobs run --flavor l4x1 --secrets HF_TOKEN \
hf.co/spaces/davanstrien/deepseek-ocr \
python process_dataset.py \
private-input \
private-output \
--private๐ Command-Line Options
Required Arguments
Optional Arguments
๐ Output Format
The script adds two new columns to your dataset:
- `markdown` - The OCR text in markdown format
- `inference_info` - JSON metadata about the processing
Inference Info Structure
[
{
"column_name": "markdown",
"model_id": "deepseek-ai/DeepSeek-OCR",
"processing_date": "2025-10-21T12:00:00",
"resolution_mode": "gundam",
"base_size": 1024,
"image_size": 640,
"crop_mode": true,
"prompt": "<image>\n<|grounding|>Convert the document to markdown.",
"max_tokens": 8192,
"gpu_memory_utilization": 0.75,
"max_model_len": 8192,
"script": "main.py",
"script_version": "1.0.0",
"space_url": "https://huggingface.co/spaces/davanstrien/deepseek-ocr",
"implementation": "vllm-async (optimized)"
}
]๐ง Technical Details
Architecture
- Model: DeepSeek-OCR (3B parameters, based on Qwen2.5-VL)
- Inference Engine: vLLM 0.8.5 with AsyncEngine
- Image Preprocessing: Custom dynamic tiling based on aspect ratio
- Vision Encoders: Custom CLIP + SAM encoders
- Context Length: Up to 8K tokens
- Optimization: Flash Attention 2.7.3, async batch processing
Hardware Requirements
- Minimum: L4 GPU (24GB VRAM) -
--flavor l4x1 - Recommended: L40S/A10G (48GB VRAM) -
--flavor l40sx1or--flavor a10g-large - Maximum Performance: A100 (40GB+ VRAM) -
--flavor a100-large
Speed Benchmarks
๐ Example Workflows
1. Process Historical Documents
hf jobs run --flavor l40sx1 --secrets HF_TOKEN \
hf.co/spaces/davanstrien/deepseek-ocr \
python main.py \
historical-scans \
historical-text \
--resolution-mode large \
--shuffle2. Extract Tables from Reports
hf jobs run --flavor a10g-large --secrets HF_TOKEN \
hf.co/spaces/davanstrien/deepseek-ocr \
python main.py \
financial-reports \
extracted-tables \
--resolution-mode gundam \
--prompt "<image>\n<|grounding|>Convert the document to markdown."3. Multi-language Documents
hf jobs run --flavor l4x1 --secrets HF_TOKEN \
hf.co/spaces/davanstrien/deepseek-ocr \
python main.py \
multilingual-docs \
ocr-output \
--resolution-mode base๐ Related Resources
- Model: deepseek-ai/DeepSeek-OCR
- vLLM: vllm-project/vllm
- HF Jobs: Documentation
๐ License
MIT License - See model card for details
๐ Acknowledgments
- DeepSeek AI for the OCR model
- vLLM team for the inference engine
- Hugging Face for Jobs infrastructure
Built with โค๏ธ using vLLM and DeepSeek-OCR
