乐于分享
好东西不私藏

一种PDF快速量化为MD格式的方法

一种PDF快速量化为MD格式的方法
Marker PDF 离线安装包 - Intel GPU 版 @echo offchcp 65001 >nulecho ============================================echo  Marker PDF 离线安装脚本 (Intel GPU 版)echo ============================================echo.:: 检查 Pythonpython --version >nul 2>&1if errorlevel 1 (    echo [错误] 未找到 Python,请先安装 Python 3.11+    echo 下载地址: https://www.python.org/downloads/    pause    exit /b 1)echo [1/4] 安装 PyTorch XPU 及依赖...pip install --no-index --find-links=wheels torch torchvision torchaudioif errorlevel 1 (    echo [错误] PyTorch 安装失败    pause    exit /b 1)echo.echo [2/4] 安装 marker-pdf 及相关包...pip install --no-index --find-links=wheels marker-pdf surya-ocr transformersif errorlevel 1 (    echo [错误] marker-pdf 安装失败    pause    exit /b 1)echo.echo [3/4] 复制模型文件到用户目录...set MODEL_DEST=%LOCALAPPDATA%\datalab\datalab\Cache\modelsif exist "models" (    if not exist "%MODEL_DEST%" mkdir "%MODEL_DEST%"    xcopy /E /I /Y "models\*" "%MODEL_DEST%\"    echo 模型文件已复制到: %MODEL_DEST%) else (    echo [警告] 未找到 models 目录,首次运行时会自动下载模型)echo.echo [4/4] 验证安装...python -c "import torch; print(f'PyTorch: {torch.__version__}'); print(f'XPU available: {torch.xpu.is_available()}')"if errorlevel 1 (    echo [警告] PyTorch XPU 验证失败,可能需要安装 Intel oneAPI)python -c "import marker; print(f'marker-pdf: OK')"python -c "import transformers; print(f'transformers: {transformers.__version__}')"echo.echo ============================================echo  安装完成!echo ============================================echo.echo 使用方法:echo   set TORCH_DEVICE=xpuecho   marker_single your_file.pdf --output_dir ./outputecho.echo 模型位置: %LOCALAPPDATA%\datalab\datalab\Cache\modelsecho.pause[09:54:24] 开始转换任务,共 1 个文件[09:54:24] ▶ 开始转换 [1/1]: 【3】+养虾新手安全指南.pdf[09:54:24] 启动命令: marker_single C:/Users/1001/Desktop/LIUSIJIA/【3】+养虾新手安全指南.pdf --output_dir C:/Users/1001/Desktop/LIUSIJIA[09:54:35] [STDERR][09:54:35] [STDERR] Recognizing Layout:   0%|          | 0/12 [00:00<?, ?it/s][09:54:41] [STDERR][09:54:41] [STDERR] Recognizing Layout:   8%|��         | 1/12 [00:06<01:10,  6.36s/it][09:54:41] [STDERR][09:54:41] [STDERR] Recognizing Layout:  17%|����        | 2/12 [00:06<00:26,  2.68s/it][09:54:44] [STDERR][09:54:44] [STDERR] Recognizing Layout:  33%|��������      | 4/12 [00:08<00:14,  1.76s/it][09:54:45] [STDERR][09:54:45] [STDERR] Recognizing Layout:  50%|����������     | 6/12 [00:10<00:07,  1.32s/it][09:54:46] [STDERR][09:54:46] [STDERR] Recognizing Layout:  67%|��������������   | 8/12 [00:11<00:03,  1.01it/s][09:54:46] [STDERR][09:54:46] [STDERR] Recognizing Layout:  83%|������������������ | 10/12 [00:11<00:01,  1.50it/s][09:54:47] [STDERR][09:54:47] [STDERR] Recognizing Layout: 100%|��������������������| 12/12 [00:12<00:00,  2.03it/s][09:54:47] [STDERR] Recognizing Layout: 100%|��������������������| 12/12 [00:12<00:00,  1.01s/it][09:54:47] [STDERR][09:54:47] [STDERR] Running OCR Error Detection:   0%|          | 0/3 [00:00<?, ?it/s][09:54:47] [STDERR][09:54:47] [STDERR] Running OCR Error Detection:  33%|��������      | 1/3 [00:00<00:00,  3.82it/s][09:54:47] [STDERR][09:54:47] [STDERR] Running OCR Error Detection: 100%|��������������������| 3/3 [00:00<00:00,  9.77it/s][09:54:47] [STDERR][09:54:47] [STDERR] Detecting bboxes: 0it [00:00, ?it/s][09:54:47] [STDERR] Detecting bboxes: 0it [00:00, ?it/s][09:54:49] [STDERR][09:54:49] [STDERR] Recognizing tables:   0%|          | 0/1 [00:00<?, ?it/s][09:54:50] [STDERR][09:54:50] [STDERR] Recognizing tables: 100%|��������������������| 1/1 [00:01<00:00,  1.39s/it][09:54:50] [STDERR] Recognizing tables: 100%|��������������������| 1/1 [00:01<00:00,  1.39s/it][09:54:51] [STDERR][09:54:51] [STDERR] Detecting bboxes: 0it [00:00, ?it/s][09:54:51] [STDERR] Detecting bboxes: 0it [00:00, ?it/s][09:54:51] [STDERR] 2026-04-22 09:54:51,208 [INFO] marker: Saved markdown to C:/Users/1001/Desktop/LIUSIJIA\��3��+��Ϻ���ְ�ȫָ��[09:54:51] [STDERR] 2026-04-22 09:54:51,208 [INFO] marker: Total time: 17.002374172210693[09:54:52] 成功: 【3】+养虾新手安全指南.pdf -> C:/Users/1001/Desktop/LIUSIJIA[09:54:52] 所有文件转换完成

Marker PDF 离线安装包 - Intel GPU 版

系统要求

  • 操作系统: Windows 10/11 64位

  • Python: 3.11(推荐)或 3.10/3.12

  • GPU: Intel Arc 系列显卡(或 Intel 集成显卡)

  • 驱动: Intel GPU 驱动最新版

安装步骤

1. 安装 Python 3.11

如果还没有安装 Python:

  1. 下载 https://www.python.org/ftp/python/3.11.9/python-3.11.9-amd64.exe

  2. 安装时勾选 "Add Python to PATH"

2. 安装 Intel oneAPI Base Toolkit(可选但推荐)

如果目标电脑有 Intel GPU,建议安装 Intel oneAPI 运行时:

  • 下载地址: https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html

  • 选择 "Online Installer" 或 "Offline Installer"

  • 安装时至少选择 "Intel oneAPI DPC++/C++ Compiler" 和 "Intel oneAPI Math Kernel Library"

注意: PyTorch XPU 版已包含大部分运行时,oneAPI Toolkit 主要提供 GPU 驱动层的完整支持。

3. 运行安装脚本

双击 install_marker.bat 或在命令行中执行:

install_marker.bat

脚本会自动安装所有 wheel 包并复制模型文件。

4. 验证安装

python-c"import torch; print(f'XPU: {torch.xpu.is_available()}')"

如果输出 XPU: True,说明 GPU 加速已启用。

模型文件

重要: marker 首次运行会自动下载约 3.2 GB 的模型文件。本离线包已包含这些模型,安装时会自动复制到正确位置。

模型大小用途
text_detection73 MB文本检测
text_recognition1.4 GB文字识别 (OCR)
layout1.4 GB布局分析
table_recognition201 MB表格识别
ocr_error_detection262 MBOCR 纠错

模型存储位置%LOCALAPPDATA%\datalab\datalab\Cache\models

手动复制模型

如果安装脚本未自动复制,手动操作:

# 创建目标目录
mkdir"$env:LOCALAPPDATA\datalab\datalab\Cache\models"

# 复制模型文件
xcopy/E/I/Y"C:\AI2026_Marker\models\*""$env:LOCALAPPDATA\datalab\datalab\Cache\models\"

使用方法

设置环境变量(必须)

marker 默认不会自动使用 GPU,需要设置 TORCH_DEVICE

# PowerShell
$env:TORCH_DEVICE="xpu"

# CMD
setTORCH_DEVICE=xpu

转换 PDF

# 单个文件
marker_singleyour_file.pdf--output_dir./output

# 批量转换(PowerShell)
Get-ChildItem*.pdf|ForEach-Object{marker_single$_.Name--output_dir./output}

持久化设置

在 PowerShell profile 中添加:

# 打开 profile
notepad$PROFILE

# 添加这一行
$env:TORCH_DEVICE="xpu"

包含的软件包

包名版本说明
torch2.11.0+xpuPyTorch Intel GPU 版
torchvision0.26.0+xpu图像处理
torchaudio2.11.0+xpu音频处理
triton-xpu3.7.0Intel GPU 编译器
marker-pdf1.10.2PDF 转 Markdown
surya-ocr0.17.1OCR 引擎
transformers4.56.2HuggingFace 模型库

以及约 100 个依赖包。

故障排除

XPU 不可用

  1. 检查 GPU 驱动是否最新

  2. 安装 Intel oneAPI Base Toolkit

  3. 确认 GPU 型号支持 oneAPI(Intel Arc / 11代+ 集成显卡)

ImportError: cannot import name 'PreTrainedModel'

transformers 版本不对,确保安装的是 4.56.2:

pipinstalltransformers==4.56.2--no-index--find-links=wheels

运行速度慢

确认 TORCH_DEVICE=xpu 已设置,否则会回退到 CPU。

首次运行还在下载模型

检查模型文件是否已正确复制:

dir"$env:LOCALAPPDATA\datalab\datalab\Cache\models"

应该看到 5 个子目录:layout、ocr_error_detection、table_recognition、text_detection、text_recognition。

文件结构

C:\AI2026_Marker\
├── install_marker.bat    # 安装脚本
├── README.md             # 本说明文件
├── wheels\               # Python wheel 包 (1.6 GB)
│   ├── torch-2.11.0+xpu-...
│   ├── marker_pdf-1.10.2-...
│   └── ... (约 100 个包)
└── models\               # 模型文件 (3.2 GB)
    ├── layout\
    ├── text_detection\
    ├── text_recognition\
    ├── table_recognition\
    └── ocr_error_detection\

总大小: 约 4.8 GB