Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

feat: add backend dependency checks for hybrid clients and update documentation

myhloli016169ce2efb
diff --git a/docs/en/usage/quick_usage.md b/docs/en/usage/quick_usage.md
index 40095507..ac8ba996 100644
--- a/docs/en/usage/quick_usage.md
+++ b/docs/en/usage/quick_usage.md
@@ -104,6 +104,8 @@ If you need to adjust parsing options through custom parameters, you can also ch
> ```bash
> mineru -p <input_path> -o <output_path> -b hybrid-http-client -u http://127.0.0.1:30000
> ```
+ >`vlm-http-client` is the lightweight remote client option and does not require local `torch`.
+ >`hybrid-http-client` requires local pipeline dependencies such as `mineru[pipeline]` and `torch`.
> [!NOTE]
> All officially supported `vllm/lmdeploy` parameters can be passed to MinerU through command line arguments, including the following commands: `mineru`, `mineru-openai-server`, `mineru-gradio`, `mineru-api`, `mineru-router`.
diff --git a/docs/zh/usage/quick_usage.md b/docs/zh/usage/quick_usage.md
index 81fbf13b..caf5a5b6 100644
--- a/docs/zh/usage/quick_usage.md
+++ b/docs/zh/usage/quick_usage.md
@@ -104,6 +104,8 @@ mineru -p <input_path> -o <output_path>
> ```bash
> mineru -p <input_path> -o <output_path> -b hybrid-http-client -u http://127.0.0.1:30000
> ```
+ >`vlm-http-client` 是轻量远程 client,用法上不要求本地安装 `torch`。
+ >`hybrid-http-client` 需要本地具备 `mineru[pipeline]` 及 `torch` 等 pipeline 依赖。
> [!NOTE]
> 所有`vllm/lmdeploy`官方支持的参数都可用通过命令行参数传递给 MinerU,包括以下命令:`mineru`、`mineru-openai-server`、`mineru-gradio`、`mineru-api`、`mineru-router`,
diff --git a/mineru/cli/client.py b/mineru/cli/client.py
index 0127c998..1c015686 100644
--- a/mineru/cli/client.py
+++ b/mineru/cli/client.py
@@ -30,6 +30,8 @@ from mineru.utils.pdfium_guard import (
from mineru.version import __version__
from mineru.cli.common import (
+ HybridDependencyError,
+ ensure_backend_dependencies,
image_suffixes,
office_suffixes,
pdf_suffixes,
@@ -847,6 +849,11 @@ async def run_orchestrated_cli(
raise click.ClickException("--start must be greater than or equal to 0")
if end_page_id is not None and end_page_id < 0:
raise click.ClickException("--end must be greater than or equal to 0")
+ if api_url is None:
+ try:
+ ensure_backend_dependencies(backend)
+ except HybridDependencyError as exc:
+ raise click.ClickException(str(exc)) from exc
output_dir.mkdir(parents=True, exist_ok=True)
documents = collect_input_documents(
@@ -1004,7 +1011,7 @@ async def run_orchestrated_cli(
vlm-auto-engine: High accuracy via local computing power.
vlm-http-client: High accuracy via remote computing power(client suitable for openai-compatible servers).
hybrid-auto-engine: Next-generation high accuracy solution via local computing power.
- hybrid-http-client: High accuracy but requires a little local computing power(client suitable for openai-compatible servers).
+ hybrid-http-client: High accuracy via remote computing power but requires local pipeline dependencies (`mineru[pipeline]`, including `torch`).
Without method specified, hybrid-auto-engine will be used by default.""",
)
@click.option(
diff --git a/mineru/cli/common.py b/mineru/cli/common.py
index 64b7c5ac..9f98b808 100644
--- a/mineru/cli/common.py
+++ b/mineru/cli/common.py
@@ -1,4 +1,6 @@
# Copyright (c) Opendatalab. All rights reserved.
+import importlib
+import importlib.util
import json
import os
from concurrent.futures import ThreadPoolExecutor
@@ -40,6 +42,37 @@ os.environ["TOKENIZERS_PARALLELISM"] = "false"
MAX_TASK_STEM_BYTES = 200
+class HybridDependencyError(RuntimeError):
+ pass
+
+
+def build_hybrid_dependency_error_message(backend: str) -> str:
+ return (
+ f"`{backend}` requires local pipeline dependencies (`mineru[pipeline]`, "
+ "including `torch`). Install `mineru[pipeline]` or `mineru[core]`. "
+ "If you need a lightweight remote client without local `torch`, "
+ "use `vlm-http-client` instead."
+ )
+
+
+def ensure_backend_dependencies(backend: str) -> None:
+ if not backend.startswith("hybrid-"):
+ return
+ if importlib.util.find_spec("torch") is None:
+ raise HybridDependencyError(build_hybrid_dependency_error_message(backend))
+
+
+def _load_hybrid_analyze_entrypoint(entrypoint_name: str, backend: str):
+ ensure_backend_dependencies(backend)
+ try:
+ hybrid_analyze = importlib.import_module("mineru.backend.hybrid.hybrid_analyze")
+ except (ImportError, ModuleNotFoundError) as exc:
+ raise HybridDependencyError(
+ build_hybrid_dependency_error_message(backend)
+ ) from exc
+ return getattr(hybrid_analyze, entrypoint_name)
+
+
def utf8_byte_length(value: str) -> int:
return len(value.encode("utf-8"))
@@ -438,7 +471,10 @@ def _process_hybrid(
server_url=None,
**kwargs,
):
- from mineru.backend.hybrid.hybrid_analyze import doc_analyze as hybrid_doc_analyze
+ hybrid_doc_analyze = _load_hybrid_analyze_entrypoint(
+ "doc_analyze",
+ f"hybrid-{backend}",
+ )
"""同步处理hybrid后端逻辑"""
if not backend.endswith("client"):
server_url = None
@@ -491,7 +527,10 @@ async def _async_process_hybrid(
server_url=None,
**kwargs,
):
- from mineru.backend.hybrid.hybrid_analyze import aio_doc_analyze as aio_hybrid_doc_analyze
+ aio_hybrid_doc_analyze = _load_hybrid_analyze_entrypoint(
+ "aio_doc_analyze",
+ f"hybrid-{backend}",
+ )
"""异步处理hybrid后端逻辑"""
if not backend.endswith("client"):
server_url = None
@@ -642,6 +681,7 @@ def do_parse(
server_url, **kwargs,
)
elif backend.startswith("hybrid-"):
+ ensure_backend_dependencies(backend)
backend = backend[7:]
if backend == "vllm-async-engine":
@@ -734,6 +774,7 @@ async def aio_do_parse(
server_url, **kwargs,
)
elif backend.startswith("hybrid-"):
+ ensure_backend_dependencies(backend)
backend = backend[7:]
if backend == "vllm-engine":
diff --git a/mineru/cli/fast_api.py b/mineru/cli/fast_api.py
index f94edfb4..6a3b1e41 100644
--- a/mineru/cli/fast_api.py
+++ b/mineru/cli/fast_api.py
@@ -709,7 +709,7 @@ async def parse_request_form(
- vlm-auto-engine: High accuracy via local computing power, supports Chinese and English documents only.
- vlm-http-client: High accuracy via remote computing power(client suitable for openai-compatible servers), supports Chinese and English documents only.
- hybrid-auto-engine: Next-generation high accuracy solution via local computing power, supports multiple languages.
-- hybrid-http-client: High accuracy via remote computing power but requires a little local computing power(client suitable for openai-compatible servers), supports multiple languages.""",
+- hybrid-http-client: High accuracy via remote computing power but requires local pipeline dependencies (`mineru[pipeline]`, including `torch`), supports multiple languages.""",
),
parse_method: str = Form(
"auto",