Skip to main content

ONNX Runtime implementations for Docling AI models

Project description

Docling ONNX Models

ONNX Runtime implementations for Docling AI models, providing improved performance and cross-platform compatibility.

Overview

docling-onnx-models is a drop-in replacement for the docling-ibm-models package, offering the same APIs but powered by ONNX Runtime. This provides several advantages:

  • Improved Performance: ONNX Runtime optimizations for better inference speed
  • Cross-Platform: Consistent behavior across different operating systems
  • Hardware Acceleration: Support for CPU, CUDA, and other execution providers
  • Reduced Dependencies: Lighter weight than full PyTorch models

Installation

pip install docling-onnx-models

For GPU support:

pip install docling-onnx-models[gpu]

Supported Models

Layout Model

  • Input: Document page images
  • Output: Layout element detection (text, tables, figures, etc.)
  • Compatible with: docling.models.layout_model.LayoutModel

Document Figure Classifier

  • Input: Figure/image regions
  • Output: Classification into 16 figure types (charts, logos, maps, etc.)
  • Compatible with: docling.models.document_picture_classifier.DocumentPictureClassifier

Table Structure Predictor

  • Input: Table region images and token data
  • Output: Table structure with rows, columns, and cell relationships
  • Compatible with: docling.models.table_structure_model.TableStructureModel

Usage

Basic Usage

The ONNX models are designed as drop-in replacements for the original models:

# Instead of:
# from docling_ibm_models.layoutmodel.layout_predictor import LayoutPredictor

# Use:
from docling_onnx_models.layoutmodel.layout_predictor import LayoutPredictor

# Same API
predictor = LayoutPredictor(
    artifact_path="/path/to/onnx/model/directory",
    device="cpu",
    num_threads=4
)

predictions = predictor.predict_batch(images)

With Docling

To use ONNX models with Docling, ensure your model directories contain ONNX files:

model_directory/
├── model.onnx              # ONNX model file
├── config.json             # Model configuration
├── preprocessor_config.json # Preprocessing config
└── ...                     # Other model files

The models will be automatically detected and used by Docling when available.

Custom Execution Providers

from docling_onnx_models.layoutmodel.layout_predictor import LayoutPredictor

# Use specific execution providers
predictor = LayoutPredictor(
    artifact_path="/path/to/model",
    device="cuda",
    providers=["CUDAExecutionProvider", "CPUExecutionProvider"]
)

Model Conversion

If you have PyTorch models that need to be converted to ONNX:

# Example for converting a layout model
import torch
from transformers import AutoModelForObjectDetection

model = AutoModelForObjectDetection.from_pretrained("path/to/pytorch/model")
model.eval()

# Dummy input (adjust dimensions as needed)
dummy_input = torch.randn(1, 3, 640, 640)

# Export to ONNX
torch.onnx.export(
    model,
    dummy_input,
    "model.onnx",
    export_params=True,
    opset_version=11,
    do_constant_folding=True,
    input_names=["input"],
    output_names=["output"],
    dynamic_axes={
        "input": {0: "batch_size"},
        "output": {0: "batch_size"}
    }
)

Performance Tips

  1. Use appropriate execution providers based on your hardware
  2. Set optimal thread counts for CPU inference
  3. Batch processing when possible for better throughput
  4. Model quantization for reduced memory usage (if supported)

API Compatibility

This package maintains full API compatibility with docling-ibm-models:

  • All method signatures are identical
  • Input/output formats are preserved
  • Configuration files use the same structure
  • Error handling behavior is consistent

Requirements

  • Python 3.10+
  • ONNX Runtime 1.15.0+
  • NumPy 1.21.0+
  • Pillow 8.3.0+
  • OpenCV 4.5.0+

Contributing

Please see the main Docling repository for contribution guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docling_onnx_models-0.1.1.dev0.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docling_onnx_models-0.1.1.dev0-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file docling_onnx_models-0.1.1.dev0.tar.gz.

File metadata

  • Download URL: docling_onnx_models-0.1.1.dev0.tar.gz
  • Upload date:
  • Size: 32.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for docling_onnx_models-0.1.1.dev0.tar.gz
Algorithm Hash digest
SHA256 2909256746982bf238bf5c0506aed7062bd8aa8b2c43d1be7bfb94c12a701ab3
MD5 77d3e77da36a977eadc811f53df20bd1
BLAKE2b-256 c4afbca1d6152f7e3e5fe7edda022dcde6f572ddb52ca3e5920c83938eedc2f1

See more details on using hashes here.

File details

Details for the file docling_onnx_models-0.1.1.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for docling_onnx_models-0.1.1.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 495919ce5cfbdf3f8108994c97acf07aa7bd218ebf62ac0c48dc835260695d20
MD5 f7e3eed7ca8feae5b250eb1c0e8c3055
BLAKE2b-256 e9cafa75f08f7816e45fc00ba9d172d30b335263f7b0b18a0b549dbf77f35701

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page