mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-08 12:48:28 +00:00
fix: Enable GPU for RapidOCR when available (#2659)
* add setting for using gpu Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * add docs Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> --------- Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
This commit is contained in:
@@ -110,6 +110,9 @@ class RapidOcrModel(BaseOcrModel):
|
|||||||
use_cuda = str(AcceleratorDevice.CUDA.value).lower() in device
|
use_cuda = str(AcceleratorDevice.CUDA.value).lower() in device
|
||||||
use_dml = accelerator_options.device == AcceleratorDevice.AUTO
|
use_dml = accelerator_options.device == AcceleratorDevice.AUTO
|
||||||
intra_op_num_threads = accelerator_options.num_threads
|
intra_op_num_threads = accelerator_options.num_threads
|
||||||
|
gpu_id = 0
|
||||||
|
if use_cuda and ":" in device:
|
||||||
|
gpu_id = int(device.split(":")[1])
|
||||||
_ALIASES = {
|
_ALIASES = {
|
||||||
"onnxruntime": EngineType.ONNXRUNTIME,
|
"onnxruntime": EngineType.ONNXRUNTIME,
|
||||||
"openvino": EngineType.OPENVINO,
|
"openvino": EngineType.OPENVINO,
|
||||||
@@ -184,6 +187,10 @@ class RapidOcrModel(BaseOcrModel):
|
|||||||
"Det.engine_type": backend_enum,
|
"Det.engine_type": backend_enum,
|
||||||
"Cls.engine_type": backend_enum,
|
"Cls.engine_type": backend_enum,
|
||||||
"Rec.engine_type": backend_enum,
|
"Rec.engine_type": backend_enum,
|
||||||
|
"EngineConfig.paddle.use_cuda": use_cuda,
|
||||||
|
"EngineConfig.paddle.gpu_id": gpu_id,
|
||||||
|
"EngineConfig.torch.use_cuda": use_cuda,
|
||||||
|
"EngineConfig.torch.gpu_id": gpu_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.options.rec_font_path is not None:
|
if self.options.rec_font_path is not None:
|
||||||
|
|||||||
15
docs/usage/gpu.md
vendored
15
docs/usage/gpu.md
vendored
@@ -43,6 +43,21 @@ Setting a higher `page_batch_size` will run the Docling models (in particular th
|
|||||||
|
|
||||||
For a complete example see [gpu_standard_pipeline.py](../examples/gpu_standard_pipeline.py).
|
For a complete example see [gpu_standard_pipeline.py](../examples/gpu_standard_pipeline.py).
|
||||||
|
|
||||||
|
#### OCR engines
|
||||||
|
|
||||||
|
The current Docling OCR engines rely on third-party libraries, hence GPU support depends on the availability in the respective engines.
|
||||||
|
|
||||||
|
The only setup which is known to work at the moment is RapidOCR with the torch backend, which can be enabled via
|
||||||
|
|
||||||
|
```py
|
||||||
|
pipeline_options = PdfPipelineOptions()
|
||||||
|
pipeline_options.ocr_options = RapidOcrOptions(
|
||||||
|
backend="torch",
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
More details in the GitHub discussion [#2451](https://github.com/docling-project/docling/discussions/2451).
|
||||||
|
|
||||||
|
|
||||||
### VLM Pipeline
|
### VLM Pipeline
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user