VenusOCR / README.md
flow3rdown's picture
Upload folder using huggingface_hub
bbbb04c verified
|
Raw History Blame Contribute Delete
5.03 kB
---
library_name: transformers
pipeline_tag: image-text-to-text
language:
- en
- zh
tags:
- ocr
- document-parsing
- vision-language-model
- formula-recognition
- table-recognition
- speculative-decoding
- ptp2
- vllm
---
<div align="center">
# VenusOCR 2.0
### Towards Efficient and Effective Document Parsing
[![GitHub](https://img.shields.io/badge/GitHub-VenusOCR-181717?logo=github)](https://github.com/flow3rdown/VenusOCR)
[![Paper](https://img.shields.io/badge/Paper-arXiv-b31b1b?logo=arxiv)](https://arxiv.org/pdf/2611.32617)
</div>
**VenusOCR 2.0** is a 1B vision-language OCR model built for high-accuracy document recognition. It supports both standard autoregressive inference and optional **PTPv2** parallel speculative decoding for faster lossless generation.
This repository hosts the **region-level recognition weights**. For full-page PDF/image parsing (layout detection, reading-order recovery, and Markdown export), please use the companion [**VenusOCR SDK**](https://github.com/flow3rdown/VenusOCR).
<div align="center">
<img src="assets/overview.png" alt="VenusOCR 2.0 Overview" width="100%">
</div>
## Highlights
- **Unified Region Recognition:** Recognizes multi-column text, LaTeX mathematical formulas, and complex tables.
- **Compact & Fast:** Lightweight 1B-class recognizer designed for efficient single-GPU deployment.
- **Optional PTPv2 Acceleration:** Bundled parallel draft module (`ptp2/`) enables lossless speedup in vLLM serving.
## Architecture
<div align="center">
<img src="assets/architecture.png" alt="VenusOCR 2.0 Architecture" width="100%">
</div>
## Usage
### 1. Transformers Inference
Install dependencies (pinned `transformers==5.5.4` is recommended):
```bash
pip install transformers==5.5.4
```
Run quick inference on a cropped document region image:
```bash
python scripts/infer_transformers.py --image /path/to/region.png --task text
```
Or load directly in Python:
```python
import torch
from PIL import Image
from transformers import AutoModelForCausalLM, AutoProcessor
model_path = "./VenusOCR2-1B"
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_path,
dtype=torch.bfloat16,
attn_implementation="sdpa",
trust_remote_code=True,
).to("cuda:0").eval()
image = Image.open("/path/to/region.png").convert("RGB")
messages = [
{
"role": "user",
"content": [
{"type": "image"},
{"type": "text", "text": "Text Recognition:"},
],
}
]
prompt = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
inputs = processor(images=image, text=prompt, return_tensors="pt").to(model.device)
with torch.inference_mode():
output_ids = model.generate(**inputs, max_new_tokens=2048, do_sample=False)
generated_ids = output_ids[:, inputs["input_ids"].shape[1]:]
print(processor.batch_decode(generated_ids, skip_special_tokens=True)[0])
```
#### Task Prompts
| Task | Prompt | Output Format |
| --- | --- | --- |
| Text | `Text Recognition:` | Plain text / Markdown |
| Formula | `Formula Recognition:` | LaTeX |
| Table | `Table Recognition:` | OTSL structure |
### 2. vLLM
#### Standard Mode (AR)
If you have the [VenusOCR SDK](https://github.com/flow3rdown/VenusOCR) installed, launch the OpenAI-compatible server directly:
```bash
venusocr serve ./VenusOCR2-1B --host 127.0.0.1 --port 8000
```
Or launch standalone without the SDK (using `vllm==0.20.0` and `transformers==5.5.4`):
```bash
pip install "vllm==0.20.0" "transformers==5.5.4"
bash scripts/patch_vllm_v0_20_ptp2.sh
USE_PTP2=0 HOST=127.0.0.1 PORT=8000 bash scripts/vllm_serve_ptp2.sh
```
#### Accelerated Mode (Optional PTPv2)
With the vLLM patch applied (`bash scripts/patch_vllm_v0_20_ptp2.sh --reverse` to undo):
```bash
HOST=127.0.0.1 PORT=8000 bash scripts/vllm_serve_ptp2.sh
```
Common environment overrides: `CUDA_VISIBLE_DEVICES`, `HOST`, `PORT`, `USE_PTP2` (`1` by default, `0` for AR), `GPU_MEMORY_UTILIZATION`, `MAX_MODEL_LEN`, `MAX_NUM_SEQS`.
### 4. End-to-End Document Parsing
For full-page PDF and image parsing (layout detection, reading order, and Markdown export), use the [VenusOCR SDK](https://github.com/flow3rdown/VenusOCR):
```bash
git clone https://github.com/flow3rdown/VenusOCR.git
cd VenusOCR
pip install -e '.[transformers,serve]'
venusocr parse document.pdf -o ./output --server-url http://127.0.0.1:8000/v1
```
## Citation
If you find VenusOCR 2.0 useful in your research or applications, please consider citing:
```bibtex
@misc{venusocr2026,
title={VenusOCR2.0: Towards Efficient and Effective Document Parsing},
author={Lei Li and Zheng Wei and Yi Yuan and Qingbin Liu and Jiang Bian and Zang Li},
year={2026},
eprint={2611.32617},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2611.32617}
}
```
## Acknowledgements
We thank the SigLIP2, Qwen3, PaddleOCR / PP-DocLayoutV3, vLLM, and OmniDocBench communities.