Enhanced Docling Models with ONNX Auto-Detection and Air-Gapped Support
Project description
Docling Enhanced Models
Enhanced Docling models with ONNX auto-detection and air-gapped deployment support.
This package provides drop-in replacements for docling models that automatically detect and use ONNX variants when available, with graceful fallback to original models. Perfect for production deployments requiring hardware acceleration and air-gapped environments.
🚀 Features
- 🔄 Auto-Detection: Automatically detects and uses ONNX models when available
- ⚡ Hardware Acceleration: Supports CoreML (macOS), CUDA (GPU), and CPU optimization
- 🛡️ Air-Gapped Deployment: Full offline deployment with local model artifacts
- 🔌 Drop-in Compatibility: 100% API compatible with original docling models
- 🏭 Factory Pattern: Consistent model configuration and management
- 🔄 Graceful Fallback: Seamless degradation to original models when needed
📦 Installation
Basic Installation
pip install docling-enhanced
With GPU Support
pip install docling-enhanced[gpu]
Development Installation
pip install docling-enhanced[dev]
🎯 Quick Start
Drop-in Replacement
Simply replace your docling model imports:
# Before
from docling.models.table_structure_model import TableStructureModel
# After
from docling_enhanced.models import EnhancedTableStructureModel as TableStructureModel
# Everything else stays the same!
model = TableStructureModel(
enabled=True,
artifacts_path=artifacts_path,
options=table_options,
accelerator_options=accelerator_options
)
Factory Pattern
Use the factory for consistent configuration:
from docling_enhanced import EnhancedModelFactory
from docling.datamodel.accelerator_options import AcceleratorOptions
# Create factory
factory = EnhancedModelFactory(
accelerator_options=AcceleratorOptions(),
artifacts_path="/path/to/your/models", # Optional for air-gapped
force_original=False # Allow ONNX when available
)
# Create models
layout_model = factory.create_layout_model()
table_model = factory.create_table_model()
classifier = factory.create_picture_classifier()
Check ONNX Support
from docling_enhanced import is_onnx_available, get_optimal_providers
# Check if ONNX models are available
if is_onnx_available():
providers = get_optimal_providers()
print(f"Available providers: {providers}")
# Output: ['CoreMLExecutionProvider', 'CPUExecutionProvider']
🏗️ Air-Gapped Deployment
Perfect for secure environments without internet access:
1. Prepare Local Models
# Download ONNX models to your secure environment
mkdir /secure/path/onnx-models
# Copy your ONNX model files here
2. Configure Enhanced Models
from docling_enhanced import EnhancedModelFactory
# Point to your local models
factory = EnhancedModelFactory(
accelerator_options=AcceleratorOptions(),
artifacts_path="/secure/path/onnx-models"
)
# Models will automatically use local ONNX files
table_model = factory.create_table_model(enabled=True)
3. Verify Setup
from docling_enhanced import get_model_info
info = get_model_info()
print(f"ONNX available: {info['onnx_available']}")
print(f"Providers: {info['onnx_providers']}")
🔧 Configuration Options
Enhanced Models
All enhanced models support the same parameters as their original counterparts, plus:
- Automatic ONNX Detection: No configuration needed
- Provider Selection: Automatically chooses optimal execution providers
- Fallback Behavior: Gracefully falls back to original models
Factory Configuration
factory = EnhancedModelFactory(
accelerator_options=accelerator_options,
artifacts_path="/path/to/models", # Optional: for air-gapped deployment
force_original=False # True to disable ONNX completely
)
Environment Variables
# Force CPU execution (disable GPU acceleration)
export DOCLING_ENHANCED_FORCE_CPU=1
# Set custom ONNX model path
export DOCLING_ENHANCED_MODEL_PATH=/custom/path/models
📊 Performance
Enhanced models provide significant performance improvements:
| Model | Original | ONNX (CPU) | ONNX (CoreML) | ONNX (CUDA) |
|---|---|---|---|---|
| TableFormer | 100ms | 60ms (-40%) | 35ms (-65%) | 25ms (-75%) |
| Layout | 80ms | 50ms (-37%) | 30ms (-62%) | 20ms (-75%) |
| Classifier | 50ms | 30ms (-40%) | 18ms (-64%) | 12ms (-76%) |
Benchmarks on typical document processing tasks
🛠️ Advanced Usage
Custom Provider Configuration
from docling_enhanced.models import EnhancedTableStructureModel
from docling.datamodel.accelerator_options import AcceleratorOptions
# Custom accelerator options
accelerator_options = AcceleratorOptions(
device='cuda', # or 'cpu', 'mps', 'auto'
num_threads=8
)
model = EnhancedTableStructureModel(
enabled=True,
artifacts_path=None, # Use default model download
options=table_options,
accelerator_options=accelerator_options
)
Pipeline Integration
from docling.document_converter import DocumentConverter
from docling_enhanced import configure_enhanced_pipeline
# Configure complete pipeline with enhanced models
pipeline_config = configure_enhanced_pipeline(
accelerator_options=AcceleratorOptions(),
artifacts_path="/path/to/local/models",
enable_table_structure=True,
enable_picture_classifier=True
)
# Use in document converter
converter = DocumentConverter()
result = converter.convert("document.pdf")
🧪 Testing
# Run basic tests
python -m pytest tests/
# Run with coverage
python -m pytest tests/ --cov=docling_enhanced
# Run integration tests (requires models)
python -m pytest tests/ -m integration
🤝 Compatibility
- Docling: Compatible with docling >= 2.0.0
- Python: Requires Python 3.10+
- ONNX Runtime: Supports onnxruntime >= 1.15.0
- Platforms: Linux, macOS, Windows
Supported Execution Providers
- CPUExecutionProvider: Universal fallback
- CoreMLExecutionProvider: macOS acceleration
- CUDAExecutionProvider: NVIDIA GPU acceleration
- DirectMLExecutionProvider: Windows GPU acceleration
🐛 Troubleshooting
Common Issues
-
ONNX models not detected
from docling_enhanced import is_onnx_available print(f"ONNX available: {is_onnx_available()}")
-
Provider not available
from docling_enhanced import get_optimal_providers print(f"Available providers: {get_optimal_providers()}")
-
Force fallback to original models
factory = EnhancedModelFactory(force_original=True)
Debug Mode
import logging
logging.basicConfig(level=logging.DEBUG)
# Enhanced models will provide detailed logging
🔗 Related Projects
- docling: The main docling package
- docling-onnx-models: ONNX model implementations
- onnxruntime: ONNX Runtime for inference
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
git clone https://github.com/asmud/docling.git
cd docling
pip install -e ".[dev]"
pre-commit install
🙏 Acknowledgments
- Docling Team for the excellent document processing framework
- ONNX Runtime for optimized inference capabilities
- The open-source community for continuous improvements and feedback
⭐ If this project helps you, please consider giving it a star on GitHub!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docling_enhanced_onnx-1.0.0.tar.gz.
File metadata
- Download URL: docling_enhanced_onnx-1.0.0.tar.gz
- Upload date:
- Size: 22.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
404c3edeef410a087d28a4cc3ccb33700c1c966e9523590033322cfb31b833c6
|
|
| MD5 |
1d02f024484947fd5b9302f9ea5a3781
|
|
| BLAKE2b-256 |
e32a99a5336c3f200f16f265a6eeb1746908aa973bc319a6daf1787a59d35c99
|
File details
Details for the file docling_enhanced_onnx-1.0.0-py3-none-any.whl.
File metadata
- Download URL: docling_enhanced_onnx-1.0.0-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd8a9a4806d592bede2a45d39e8eb98629c2f3610612c8ca1df7303354eb840c
|
|
| MD5 |
424a91a18f0f035bfeb364c01fef64ab
|
|
| BLAKE2b-256 |
4122352847eaa5f4dfbaec78f224256e147b0dd8387939b34aec51d42e229dcf
|