StableLearn Logo

Search Content

AI Tools 8 min read

HunyuanOCR Tutorial: 1B Param Model Outperforms DeepSeek/PaddleOCR/Qwen | Deployment Guide

HunyuanOCR: Tencent 1B OCR model beats DeepSeek-OCR (92% vs 10% on cards). Supports 100+ languages, vLLM OpenAI API deployment. Full code examples included.

Cover image for HunyuanOCR Tutorial: 1B Param Model Outperforms DeepSeek/PaddleOCR/Qwen | Deployment Guide

Published 297 days ago. Content may be outdated.

What is HunyuanOCR?

HunyuanOCR is an end-to-end OCR expert Vision Language Model (VLM) developed by Tencent’s Hunyuan team. Built on Hunyuan’s native multimodal architecture, it achieves SOTA (state-of-the-art) performance across multiple industry benchmarks with only 1B parameters.

The most impressive aspect of this model is its “end-to-end” philosophy—completing complex tasks with a single instruction and single inference, far more efficient than solutions requiring multiple cascaded models.

💡 In simple terms, HunyuanOCR is a small but powerful OCR model capable of handling various complex document recognition tasks while supporting over 100 languages.

Core Features

💪 Efficient Lightweight Architecture

  • 1B Parameter Design: Based on Hunyuan’s native multimodal architecture and training strategy, achieving SOTA performance with minimal parameters
  • Low Deployment Cost: Significantly lower deployment threshold compared to models with tens or hundreds of billions of parameters
  • End-to-End Inference: Complete tasks in a single inference without complex cascading pipelines

📑 Comprehensive OCR Capabilities

One model covering multiple classic OCR tasks:

  • Text Detection & Recognition: Precisely locate and recognize text in images
  • Complex Document Parsing: Handle complex documents containing formulas, tables, and charts
  • Open-field Information Extraction: Extract structured information from cards, receipts, etc.
  • Video Subtitle Extraction: Automatically extract subtitles from video frames
  • Image Translation: End-to-end image text translation
  • Document QA: Answer questions based on document content

🌏 Extensive Language Support

  • Supports 100+ languages
  • Excels in both single-language and mixed-language scenarios
  • Specially optimized for 14 commonly used minor languages (German, Spanish, Turkish, Italian, Russian, French, Portuguese, Arabic, Thai, Vietnamese, Indonesian, Malay, Japanese, Korean) translation to Chinese/English

System Requirements

🖥️ Hardware Requirements

Running this model has certain hardware requirements:

  • Operating System: Linux
  • Python: 3.12+ (recommended)
  • CUDA: 12.8
  • PyTorch: 2.7.1
  • GPU: NVIDIA GPU with CUDA support
  • GPU Memory: 80GB
  • Disk Space: 6GB

⚠️ Note: The 80GB GPU memory requirement means you’ll need professional GPUs like A100 or H100. Consumer-grade GPUs may not be able to run the full model.

Quick Start

vLLM is the officially recommended inference method with better performance.

Installation

Using pip:

   pip install vllm --pre --extra-index-url https://wheels.vllm.ai/nightly

Using uv:

   uv pip install vllm --extra-index-url https://wheels.vllm.ai/nightly

Model Inference

   from vllm import LLM, SamplingParams
from PIL import Image
from transformers import AutoProcessor

def clean_repeated_substrings(text):
    """Clean repeated substrings in text"""
    n = len(text)
    if n < 8000:
        return text
    for length in range(2, n // 10 + 1):
        candidate = text[-length:] 
        count = 0
        i = n - length
        
        while i >= 0 and text[i:i + length] == candidate:
            count += 1
            i -= length

        if count >= 10:
            return text[:n - length * (count - 1)]  

    return text

# Load model
model_path = "tencent/HunyuanOCR"
llm = LLM(model=model_path, trust_remote_code=True)
processor = AutoProcessor.from_pretrained(model_path)
sampling_params = SamplingParams(temperature=0, max_tokens=16384)

# Prepare input
img_path = "/path/to/image.jpg"
img = Image.open(img_path)
messages = [
    {"role": "user", "content": [
        {"type": "image", "image": img_path},
        {"type": "text", "text": "Detect and recognize text in the image, output text coordinates in formatted manner."}
    ]}
]

# Inference
prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = {"prompt": prompt, "multi_modal_data": {"image": [img]}}
output = llm.generate([inputs], sampling_params)[0]
print(clean_repeated_substrings(output.outputs[0].text))

Deploy OpenAI Compatible API Service

vLLM also supports deploying an OpenAI-compatible API server for easy integration into existing systems:

Start the service:

   vllm serve tencent/HunyuanOCR \
    --no-enable-prefix-caching \
    --mm-processor-cache-gb 0

Call using OpenAI client:

   from openai import OpenAI

# Create client
client = OpenAI(
    api_key="EMPTY",
    base_url="http://localhost:8000/v1",
    timeout=3600
)

# Build request
messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image_url",
                "image_url": {
                    "url": "https://example.com/your-image.png"
                }
            },
            {
                "type": "text",
                "text": (
                    "Extract all information from the main body of the document image "
                    "and represent it in markdown format, ignoring headers and footers. "
                    "Tables should be expressed in HTML format, formulas in the document "
                    "should be represented using LaTeX format, and the parsing should be "
                    "organized according to the reading order."
                )
            }
        ]
    }
]

# Send request
response = client.chat.completions.create(
    model="tencent/HunyuanOCR",
    messages=messages,
    temperature=0.0,
)

print(f"Result: {response.choices[0].message.content}")

Configuration Tips:

  • Use greedy sampling (temperature=0.0) or low temperature sampling for optimal OCR performance
  • OCR tasks typically don’t need prefix caching or image reuse; disable these features to avoid unnecessary hashing and caching overhead
  • Adjust max_num_batched_tokens parameter based on hardware capability for better throughput

🔧 Using Transformers

If you’re more familiar with the Transformers framework, you can use this approach:

Installation

   pip install git+https://github.com/huggingface/transformers@82a06db03535c49aa987719ed0746a76093b1ec4

Note: Currently, Transformers has some performance degradation compared to the vLLM framework. The team is working on fixes.

Model Inference

   from transformers import AutoProcessor
from transformers import HunYuanVLForConditionalGeneration
from PIL import Image
import torch

# Load model and processor
model_name_or_path = "tencent/HunyuanOCR"
processor = AutoProcessor.from_pretrained(model_name_or_path, use_fast=False)

# Prepare input
img_path = "path/to/your/image.jpg"
image_inputs = Image.open(img_path)
messages1 = [
    {
        "role": "user",
        "content": [
            {"type": "image", "image": img_path},
            {"type": "text", "text": "Detect and recognize text in the image, output text coordinates in formatted manner."},
        ],
    }
]
messages = [messages1]

# Process input
texts = [
    processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True)
    for msg in messages
]
inputs = processor(
    text=texts,
    images=image_inputs,
    padding=True,
    return_tensors="pt",
)

# Load model and inference
model = HunYuanVLForConditionalGeneration.from_pretrained(
    model_name_or_path,
    attn_implementation="eager",
    dtype=torch.bfloat16,
    device_map="auto"
)

with torch.no_grad():
    device = next(model.parameters()).device
    inputs = inputs.to(device)
    generated_ids = model.generate(**inputs, max_new_tokens=16384, do_sample=False)

# Decode output
if "input_ids" in inputs:
    input_ids = inputs.input_ids
else:
    input_ids = inputs.inputs

generated_ids_trimmed = [
    out_ids[len(in_ids):] for in_ids, out_ids in zip(input_ids, generated_ids)
]
output_texts = processor.batch_decode(
    generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_texts)

Application Scenarios and Prompts

HunyuanOCR supports various tasks. Here are commonly used prompts:

📝 Text Spotting

   Detect and recognize text in the image, and output the text coordinates in a formatted manner.

📄 Document Parsing

TaskPrompt
Formula RecognitionIdentify the formula in the image and represent it using LaTeX format.
Table ParsingParse the table in the image into HTML.
Chart ParsingParse the chart in the image; use Mermaid format for flowcharts and Markdown for other charts.
Full DocumentExtract all information from the main body of the document image and represent it in markdown format, ignoring headers and footers. Tables should be expressed in HTML format, formulas in the document should be represented using LaTeX format, and the parsing should be organized according to the reading order.

📋 General Parsing

   Extract the text in the image.

🔍 Information Extraction

TaskPrompt
Single FieldOutput the value of Key.
Multiple FieldsExtract the content of the fields: [‘key1’,‘key2’, …] from the image and return it in JSON format.
Subtitle ExtractionExtract the subtitles from the image.

🌐 Translation

   First extract the text, then translate the text content into English. If it is a document, ignore the header and footer. Formulas should be represented in LaTeX format, and tables should be represented in HTML format.

Performance Evaluation

📊 Text Spotting Performance

In internal benchmark tests, HunyuanOCR’s overall performance:

Model TypeMethodOverall Score
TraditionalPaddleOCR53.38
TraditionalBaiduOCR61.9
General VLMQwen3VL-2B-Instruct29.68
General VLMQwen3VL-235B-Instruct53.62
General VLMSeed-1.6-Vision59.23
OCR-Specific VLMHunyuanOCR70.92

Summary: HunyuanOCR achieves the best overall performance (70.92%) across various scenarios, significantly outperforming both traditional OCR methods and general VLMs.

📑 Document Parsing Performance

On OmniDocBench and multilingual internal benchmarks:

Model TypeMethodParametersOmniDocBench Overall
General VLMGemni-2.5-pro-88.03
General VLMQwen3-VL-235B235B89.15
Specialized VLM (Modular)MinerU2.51.2B90.67
Specialized VLM (Modular)PaddleOCR-VL0.9B92.86
Specialized VLM (End2End)Deepseek-OCR3B87.01
Specialized VLM (End2End)dots.ocr3B88.41
Specialized VLM (End2End)HunyuanOCR1B94.10

Summary: HunyuanOCR demonstrates superior performance in multilingual document parsing, achieving the lowest edit distances across most categories.

📋 Information Extraction & VQA Performance

ModelCardsReceiptsVideo SubtitlesOCRBench
DeepSeek-OCR10.0440.545.41430
Qwen3-VL-2B-Instruct67.6264.623.75858
Gemini-2.5-Pro80.5980.6653.65872
Qwen3-VL-235B-A22B-Instruct75.5978.450.74920
HunyuanOCR92.2992.5392.87860

Summary: HunyuanOCR significantly outperforms larger models in card/receipt processing and video subtitle extraction, while maintaining competitive performance on OCRBench.

🌐 Image Translation Performance

MethodParametersOther2EnOther2ZhDoTA (en2zh)
Gemini-2.5-Flash-79.2680.0685.60
Qwen3-VL-235B-Instruct235B73.6777.2080.01
Qwen3-VL-2B-Instruct2B66.3066.7773.49
HunyuanOCR1B73.3873.6283.48

Summary: HunyuanOCR, with only 1B parameters, achieves comparable results to Qwen3-VL-235B in image translation tasks.

Application Scenarios

🔤 Text Detection & Recognition

The model can output text content and corresponding coordinate information at the line level for all text in an image, performing excellently in scenarios including documents, artistic fonts, street views, handwriting, advertisements, invoices, screenshots, games, and videos.

📚 Complex Document Processing

Capable of digitizing scanned or photographed multilingual document images, specifically:

  • Organizing text content according to reading order
  • Using LaTeX format for formulas
  • Expressing complex tables in HTML format

📋 Open-field Information Extraction

For common cards and receipts, parse fields of interest (such as name/address/company) using standard JSON format.

Example Prompt:

   Extract the content of the fields: ['unit_price', 'pickup_time', 'invoice_number', 'province_prefix', 'total_amount', 'invoice_code', 'dropoff_time', 'mileage'] from the image and return it in JSON format.

Example Output:

   {
    "unit_price": "3.00",
    "pickup_time": "09:01",
    "invoice_number": "42609332",
    "province_prefix": "",
    "total_amount": "¥77.10",
    "invoice_code": "161002018100",
    "dropoff_time": "09:51",
    "mileage": "26.1km"
}

🎬 Video Subtitle Extraction

The model can automatically extract subtitles from videos, including bilingual subtitles.

🌍 Image Text Translation

The model can translate photographed images in minor languages into Chinese or English text format end-to-end. It won the small model track championship in the ICDAR2025 document end-to-end translation competition.

Comparison with Other OCR Solutions

FeatureHunyuanOCRPaddleOCRDeepSeek-OCRGeneral VLM
Parameters1B-3B2B-235B
End-to-End
Multilingual100+LimitedLimitedExtensive
Document ParsingExcellentGoodGoodAverage
Info ExtractionExcellentAverageAverageGood
Video SubtitlesExcellentAveragePoorAverage
Image TranslationExcellentAverage-Good

Conclusion

HunyuanOCR represents a significant breakthrough by Tencent’s Hunyuan team in the OCR field. With only 1B parameters, it outperforms much larger models on multiple tasks, fully embodying the “small but powerful” design philosophy.

Key Advantages:

  • 🎯 Parameter Efficient: 1B parameters achieving SOTA performance, low deployment cost
  • 🚀 End-to-End: Complete tasks in single inference, high efficiency
  • 🌏 Multilingual: Supports 100+ languages, extensive coverage
  • 📑 Comprehensive: Text recognition, document parsing, information extraction, translation all in one
  • ⚡ Strong Performance: Leading in multiple benchmark tests

Points to Note:

  • 💾 High GPU Memory Requirement: Requires 80GB GPU memory, difficult to run on consumer-grade GPUs
  • 🐧 Linux Only: Currently only supports Linux systems

If you have suitable hardware, HunyuanOCR is definitely one of the most worthwhile open-source OCR models to try.

References

Share Article

More Articles