【部署】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
相关推荐
你不知道我是谁?1 小时前
负载均衡--四层、七层负载均衡的区别
运维·服务器·负载均衡
蓝易云1 小时前
Qt框架中connect()方法的ConnectionType参数使用说明 点击改变文章字体大小
linux·前端·后端
dyj0951 小时前
【Rancher Server + Kubernets】- Nginx-ingress日志持久化至宿主机
运维·nginx·rancher
花落已飘1 小时前
多线程 vs 异步
linux·网络·系统架构
PanZonghui2 小时前
Centos项目部署之Nginx部署项目
linux·nginx
码出钞能力2 小时前
linux内核模块的查看
linux·运维·服务器
星辰云-3 小时前
# Linux Centos系统硬盘分区扩容
linux·运维·centos·磁盘扩容
Hellc0073 小时前
Nginx 高级 CC 与 DDoS 防御策略指南
运维·nginx·ddos
聽雨2373 小时前
02每日简报20250704
linux·科技·金融·生活·社交电子·娱乐·媒体
feilieren3 小时前
Docker 安装 Elasticsearch 9
运维·elasticsearch·docker·es