ARTICLE · INTELLIGENCE

战地情报 · 详情页

来自尧图项目组的一线实战观察与深度解析

Docling 怎么安装 Nemotron OCR 引擎(feat-ocr-nemotron 与 CUDA 13 配置)?

Docling 怎么安装 Nemotron OCR 引擎(feat-ocr-nemotron 与 CUDA 13 配置)? Docling 怎么安装 Nemotron OCR 引擎feat-ocr-nemotron 与 CUDA 13 配置【免费下载链接】doclingGet your documents ready for gen AI项目地址: https://gitcode.com/GitHub_Trending/do/doclingDocling 支持多个可插拔的 OCR 引擎其中 NVIDIA Nemotron OCR 只走一条安装路径feat-ocr-nemotronextra。它和普通的pip install docling不同必须额外指定 CUDA 13 的 PyTorch wheel 索引否则 pip 会解析到非 CUDA 的 torch 包引擎无法运行。本文给出在满足条件的机器上安装 Nemotron OCR、验证运行时环境、并把它接入 PDF 转换的最小路径。安装前提先确认环境是否满足安装文档 和引擎实现都明确限定了 Nemotron OCR 的适用范围三项缺一不可Linux x86_64Python 3.12CUDA 13.xDocling 运行时强制要求 13.x见 OCR 引擎说明Nemotron works only on Linux and requires CUDA (Docling enforces 13.x)。这个限制同样写进了依赖声明里。pyproject.toml 中feat-ocr-nemotronextra 的实际依赖带有环境标记feat-ocr-nemotron [ nemotron-ocr2.0.0 ; python_version 3.12 and sys_platform linux and platform_machine x86_64, ]也就是说在 macOS、ARM 架构或 Python 3.11/3.13 的机器上安装该 extra 时nemotron-ocr包本身不会被装上后续运行时校验会直接失败。如果环境不满足应改用文档中列出的其他 OCR 引擎EasyOCR、Tesseract、RapidOCR 等。安装命令feat-ocr-nemotron 加 CUDA 13 索引安装文档 给出的完整安装命令是pip install docling[feat-ocr-nemotron] \ --extra-index-url https://download.pytorch.org/whl/cu130 \ --index-strategy unsafe-best-match三个部分各自的作用文档均有说明docling[feat-ocr-nemotron]安装 NVIDIA Nemotron OCR 的可选依赖--extra-index-url https://download.pytorch.org/whl/cu130Nemotron OCR requires the CUDA 13 PyTorch wheels即从 PyTorch 官方的 CUDA 13 wheel 索引拉取torch--index-strategy unsafe-best-match让pip在多个索引间按最佳匹配解析正确选中 CUDA-enabled 的torch包。命令中的cu130索引地址与unsafe-best-match参数必须原样保留它们是安装文档中针对 CUDA 13 配置明确给出的内容删掉任一参数都可能导致解析到 CPU 版 torch使 CUDA 13.x 运行时校验不通过。验证安装与运行时Docling 对 Nemotron OCR 的运行时校验集中在NemotronOcrModel.validate_runtime见 引擎实现。它按顺序检查平台、架构、Python 版本、加速器与 CUDA 版本任一不满足都会抛出带明确原因的RuntimeError。仓库的端到端测试 tests/test_e2e_nemotron_ocr_conversion.py 中复用了同一个校验入口可以照抄这段代码做安装后的自检from docling.datamodel.accelerator_options import ( AcceleratorDevice, AcceleratorOptions, ) from docling.models.stages.ocr.nemotron_ocr_model import NemotronOcrModel # 1. 可选依赖是否装上 import nemotron_ocr.inference.pipeline_v2 # 未安装会抛 ImportError # 2. 运行时环境是否满足Linux x86_64 / Python 3.12 / CUDA 13.x NemotronOcrModel.validate_runtime( AcceleratorOptions(deviceAcceleratorDevice.AUTO) )validate_runtime的实际判断逻辑与 引擎实现 一致sys.platform ! linux→Nemotron OCR is only supported on Linux.platform.machine() ! x86_64→Nemotron OCR is only supported on x86_64 machines.Python 不是 3.12 →Nemotron OCR requires Python 3.12.加速器不是 CUDA →Nemotron OCR requires a CUDA accelerator. Set pipeline_options.accelerator_options.device to CUDA or AUTO on a CUDA-enabled machine.torch.cuda.is_available()为 false →Nemotron OCR requires CUDA at initialization time, but torch.cuda.is_available() is false.torch.version.cuda不是 13.x 开头 →Nemotron OCR requires CUDA 13.x, but the current PyTorch runtime reports CUDA ...如果第 1 步导入时报ImportError引擎初始化时也会给出同一条安装提示Install the optional dependency via pip install docling[feat-ocr-nemotron] on Linux x86_64 with Python 3.12 and CUDA 13.x.按上面「安装命令」一节重新执行即可。两段检查都通过无异常抛出即说明环境符合 Nemotron OCR 的运行条件。首次使用把 Nemotron OCR 接入 PDF 转换安装完成后通过ocr_options选择引擎。示例脚本 中展示了各引擎的切换方式Nemotron 对应from docling.datamodel.base_models import InputFormat from docling.datamodel.pipeline_options import ( NemotronOcrOptions, OcrMode, PdfPipelineOptions, ) from docling.document_converter import DocumentConverter, PdfFormatOption pipeline_options PdfPipelineOptions() pipeline_options.do_ocr True pipeline_options.ocr_options NemotronOcrOptions(modeOcrMode.FULL_PAGE) doc_converter DocumentConverter( format_options{InputFormat.PDF: PdfFormatOption(pipeline_optionspipeline_options)} )Nemotron OCR 必须有 CUDA 加速器端到端测试 中额外显式设置了设备可以一并加上from docling.datamodel.accelerator_options import AcceleratorDevice pipeline_options.accelerator_options.device AcceleratorDevice.CUDA然后对任意 PDF 执行doc_converter.convert(你的 PDF 路径)得到ConversionResult。NemotronOcrOptions还支持batch_size参数测试中使用了NemotronOcrOptions(batch_size3)用于控制一次送入 OCR 的页面/区域批量。不走 Python API 的话CLI 也支持该引擎CLI 参考 中--ocr-engine的可选值包含nemotron-ocr语言仍通过--ocr-lang传入。模型文件可预先下载Nemotron OCR 的模型nvidia/nemotron-ocr-v2不需要手动放置权重。如需提前下载CLI 提供了对应条目docling-tools models download的模型列表中包括nemotron_ocr_v2见 CLI 参考docling-tools models download nemotron_ocr_v2默认下载到$HOME/.cache/docling/models可用-o/--output-dir改目录。此外NemotronOcrOptions的说明中提到可以通过 pipeline 级artifacts_path指向预先下载好的 checkpoint。语言支持与限制OCR 语言文档 和 Nemotron 专节 给出的语言规则引擎原生代码只有两个english别名en和multilingual别名multilang留空时默认走英语模型multilingual覆盖英语、简体中文、繁体中文、日语、韩语、俄语iso:zh、iso:zh-Hant、iso:ja、iso:ko、iso:ru都会映射到多语言模型一次转换只运行一个语言lang中有多个条目时取第一个并警告其余条目无法覆盖的语言直接抛OcrLanguageNotSupportedError不会静默回退到其他模型。其他值得留意的边界开发环境默认排除该 extra安装文档 的 development setup 使用uv sync --all-extras --no-extra feat-ocr-nemotron原因是该 extra 只在 Linux x86_64 Python 3.12 CUDA 13.x 下可用避免在无 CUDA 的开发机上引入装不上的依赖语言映射的完整行为可参考 测试文件 中的test_nemotron_language_mappingen/eng/EN/en-US等均归一到englishzh-CN/zh-Hant/ja/ko/ru归一到multilingual。环境满足且校验通过后安装即完成后续所有 PDF 转换只要把ocr_options设为NemotronOcrOptions或 CLI 传--ocr-engine nemotron-ocrOCR 阶段就会走 Nemotron 引擎无需再额外配置。【免费下载链接】doclingGet your documents ready for gen AI项目地址: https://gitcode.com/GitHub_Trending/do/docling创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
RELATED READING

延伸阅读

更多一线实战笔记与深度复盘,助您持续精进