【部署】ubuntu部署olmOCR

目录

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

一、安装依赖


bash 复制代码
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


bash 复制代码
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

bash 复制代码
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传到服务器上,然后直接下载

bash 复制代码
# 在这里下载
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

bash 复制代码
uv pip install "sglang[all]>=0.4.4"

启动运行命令之后会安装模型权重文件,十几个G,还是很大的。

三、PDF解析

1. 运行

bash 复制代码
python -m olmocr.pipeline ./localworkspace --pdfs tests/gnarly_pdfs/horribleocr.pdf

测试了两个pdf文件

输出的是.jsonl,所以看起来并没有换行,看的不清楚

转换多个PDF的命令

bash 复制代码
python -m olmocr.pipeline ./localworkspace --pdfs tests/gnarly_pdfs/*.pdf

2. 原始 PDF 并排查看结果

bash 复制代码
python -m olmocr.viewer.dolmaviewer localworkspace/results/output_*.jsonl

3. 更换模型

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

bash 复制代码
  --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)有写权限。可以通过以下命令检查:
bash 复制代码
ls -ld /data/huyuqiang/llf/ocr/olmocr

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

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

bash 复制代码
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:
bash 复制代码
ls /usr/lib/x86_64-linux-gnu/libnccl*
  1. 安装 NCCL
    如果 NCCL 未安装,可以通过以下步骤安装:

方法 1:通过 NVIDIA 官方安装

访问 NCCL 下载页面。

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

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

bash 复制代码
conda install -c nvidia nccl

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


https://docs.sglang.ai/start/install.html

bash 复制代码
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
相关推荐
dessler30 分钟前
代理服务器-LVS的DR模式
linux·运维·云计算
梦星辰.1 小时前
VSCode CUDA C++进行Linux远程开发
linux·c++·vscode
远方16092 小时前
0x-2-Oracle Linux 9上安装JDK配置环境变量
java·linux·oracle
cui_win2 小时前
每日一令:Linux 极简通关指南 - 汇总
linux·运维·服务器
知星小度S2 小时前
Linux权限探秘:驾驭权限模型,筑牢系统安全
linux·运维·服务器
黄交大彭于晏2 小时前
发送文件脚本源码版本
java·linux·windows
搞Linux的杰仔3 小时前
Ubuntu20.04基础配置安装——系统安装(一)
linux·嵌入式开发
Kaede65 小时前
如何应对Linux云服务器磁盘空间不足的情况
linux·运维·服务器
草上爬7 小时前
OpenWrt:使用ALSA实现边录边播
ubuntu·openwrt·record·alsa·play
Kookoos8 小时前
Dynamics 365 Finance + Power Automate 自动化凭证审核
运维·自动化·dynamics 365·power automate