【部署】ubuntu部署olmOCR

项目地址:
https://github.com/allenai/olmocr

一、安装依赖


sudo apt-get update
sudo apt-get install poppler-utils ttf-mscorefonts-installer msttcorefonts fonts-crosextra-caladea fonts-crosextra-carlito gsfonts lcdf-typetools

二、安装conda新环境和sglang


conda create -n olmocr python=3.11
conda activate olmocr

git clone https://github.com/allenai/olmocr.git
cd olmocr
# If running on CPU, run this:
pip install -e .
# 如果没有权限,可以安装到用户目录下
pip install --user -e .

# If running on GPU, run this instead:
pip install -e .[gpu] --find-links https://flashinfer.ai/whl/cu124/torch2.4/flashinfer/

GPU下使用还需要安装sglang

pip install --upgrade pip
pip install uv
uv pip install "sglang[all]>=0.4.4" --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer-python

如果网络问题装不上也可以手动安装wheel,下载好wheel文件之后,sftp传到服务器上,然后直接下载

# 在这里下载
https://github.com/flashinfer-ai/flashinfer/releases/download/v0.2.3/flashinfer_python-0.2.3+cu124torch2.5-cp38-abi3-linux_x86_64.whl

特别慢这边
在这里插入图片描述
安装好之后再安装sglang

uv pip install "sglang[all]>=0.4.4"

在这里插入图片描述
启动运行命令之后会安装模型权重文件,十几个G,还是很大的。

在这里插入图片描述

三、PDF解析

1. 运行

python -m olmocr.pipeline ./localworkspace --pdfs tests/gnarly_pdfs/horribleocr.pdf

测试了两个pdf文件
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
输出的是.jsonl,所以看起来并没有换行,看的不清楚
在这里插入图片描述

转换多个PDF的命令

python -m olmocr.pipeline ./localworkspace --pdfs tests/gnarly_pdfs/*.pdf

2. 原始 PDF 并排查看结果

python -m olmocr.viewer.dolmaviewer localworkspace/results/output_*.jsonl

在这里插入图片描述

在这里插入图片描述

3. 更换模型

命令中可以增加模型的更换

  --model MODEL         List of paths where you can find the model to convert this pdf. You can specify several different paths here, and the script will try to use the
                        one which is fastest to access

四、可能出现的问题


1.note: This error originates from a subprocess, and is likely not a problem with pip.

从报错信息来看,问题出在 pip install -e . 时无法创建 olmocr.egg-info 目录,原因是 权限不足(Permission denied)。以下是解决方法:

  1. 检查当前用户权限
    确保你对项目目录(/data/huyuqiang/llf/ocr/olmocr)有写权限。可以通过以下命令检查:
ls -ld /data/huyuqiang/llf/ocr/olmocr

如果权限不足,可以尝试修改目录权限:

sudo chown -R $USER:$USER /data/huyuqiang/llf/ocr/olmocr
sudo chmod -R u+rw /data/huyuqiang/llf/ocr/olmocr
  1. 使用虚拟环境
    如果你没有使用虚拟环境,建议创建一个虚拟环境并激活它,这样可以避免权限问题:
python -m venv venv  # 创建虚拟环境
source venv/bin/activate  # 激活虚拟环境
pip install -e .  # 在虚拟环境中安装
  1. 指定 --user 选项
    如果你没有管理员权限,可以尝试使用 --user 选项安装到用户目录:
pip install --user -e .

2.转换单个PDF命令运行时

File “/data/huyuqiang/llf/ocr/olmocr/olmocr/pipeline.py”, line 26, in
import torch
File “/data/huyuqiang/anaconda3/envs/olmocr/lib/python3.11/site-packages/torch/init.py”, line 367, in
from torch._C import * # noqa: F403
^^^^^^^^^^^^^^^^^^^^^^
ImportError: libcupti.so.12: cannot open shared object file: No such file or directory

在这里插入图片描述
这个错误表示系统找不到 CUDA Profiling Tools Interface (CUPTI) 库文件 libcupti.so.12。这是 CUDA 工具包的一部分,通常在安装 CUDA toolkit 时应该包含这个库。

sudo apt-get install cuda-toolkit-12-0
# 编辑 ~/.bashrc 文件
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
sudo ln -s /usr/local/cuda/extras/CUPTI/lib64/libcupti.so.12 /usr/local/lib/libcupti.so.12

3.ImportError: libnccl.so.2: cannot open shared object file: No such file or directory

这个错误表明在运行代码时,PyTorch 无法找到 libnccl.so.2 这个共享库文件。libnccl.so.2 是 NVIDIA 的 NCCL(NVIDIA Collective Communications Library)库的一部分,通常用于多 GPU 通信。以下是解决这个问题的步骤:

  1. 检查是否安装了 NCCL
    NCCL 是 NVIDIA 的库,通常与 CUDA 一起安装。你可以通过以下命令检查是否安装了 NCCL:
ls /usr/lib/x86_64-linux-gnu/libnccl*

  1. 安装 NCCL
    如果 NCCL 未安装,可以通过以下步骤安装:

方法 1:通过 NVIDIA 官方安装
访问 NCCL 下载页面。

根据你的系统(Ubuntu/CentOS 等)和 CUDA 版本下载对应的 NCCL 包。

安装下载的包。例如,对于 Ubuntu:

在这里插入图片描述

conda install -c nvidia nccl

4.已经执行了正常命令,但是需要下载sglang

在这里插入图片描述
https://docs.sglang.ai/start/install.html

pip install --upgrade pip
pip install uv
uv pip install "sglang[all]>=0.4.4" --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer-python
03-08
### OLMOCR概述 OLMOCR是由Allen Institute for Artificial Intelligence (AI2)的AllenNLP团队开发的一个强大的开源工具[^3]。此工具专注于文档处理领域,能够将PDF文件及其他类型的文档高效地转化为纯文本形式的同时保持自然阅读顺序。其卓越之处在于不仅限于简单的文字转换,还具备处理复杂元素的能力,比如表格、公式甚至是手写内容。 ### 功能特性 #### 超低成本与高精度结构化文本提取 OLMOCR凭借其独特的算法和技术实现了成本效益极高的解决方案,同时提供精确度非常高的结构化文本抽取服务。这种组合使得该软件成为市场上极具竞争力的产品之一[^2]。 #### 混合模态解析技术 通过引入创新性的混合模式分析方法,OLMOCR可以更好地理解和解释不同种类的信息源——无论是印刷体还是手稿;不论是清晰打印件还是模糊扫描图像中的字符识别都能得到显著改善。这一进步对于提高整体性能至关重要。 #### 支持多种输入格式并优化输出质量 除了常见的PDF外,也兼容其他流行的电子文档标准作为输入材料。更重要的是,在转化过程中特别注意维护原始布局和样式特征,确保最终获得易于编辑且美观大方的结果。 ### 应用场景拓展 借助`train/train.py`文件所提供的Qwen2-VL和Molmo-O这两种语言模型微调功能,用户可以根据特定应用场景调整预训练好的视觉-语言模型参数,进而创建更加贴合实际业务需求的新版本OCR引擎。这无疑大大增强了系统的灵活性及适应范围[^1]。 ```python from transformers import Trainer, TrainingArguments import datasets # 加载自定义数据集 dataset = datasets.load_dataset('path_to_custom_data') # 定义训练参数 training_args = TrainingArguments( output_dir='./results', num_train_epochs=3, per_device_train_batch_size=8, ) # 初始化Trainer对象 trainer = Trainer( model=model_name_or_path='qwen2-vl', # 或者 'molmo-o' args=training_args, train_dataset=dataset['train'], ) # 开始训练过程 trainer.train() ```
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海绵波波107

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值