mirror of
https://github.com/opendatalab/MinerU.git
synced 2026-03-27 19:18:34 +07:00
Compare commits
35 Commits
mineru-2.7
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61248e2ec9 | ||
|
|
c717a1c83a | ||
|
|
daf970af0e | ||
|
|
077b3101b3 | ||
|
|
a12610fb3e | ||
|
|
53aad4c900 | ||
|
|
345c46a457 | ||
|
|
e460f33c95 | ||
|
|
e9091876b6 | ||
|
|
c68dc3682a | ||
|
|
40796b9a7e | ||
|
|
31122e655b | ||
|
|
3eef5157f8 | ||
|
|
5cc95f3760 | ||
|
|
e31c0ec34d | ||
|
|
3e51cb4e81 | ||
|
|
bc63b17ae4 | ||
|
|
7f986fc1e3 | ||
|
|
5fb8d50b70 | ||
|
|
3ce9500894 | ||
|
|
142dc30a03 | ||
|
|
5e3db4a472 | ||
|
|
90b77a2809 | ||
|
|
948161c527 | ||
|
|
5397c74a34 | ||
|
|
97450688d6 | ||
|
|
6e7c6b082d | ||
|
|
6f281be4ff | ||
|
|
880cdd02b2 | ||
|
|
73b31d1118 | ||
|
|
74ec4894e0 | ||
|
|
c1022fc3e2 | ||
|
|
6270b05d3a | ||
|
|
bbd214dbc3 | ||
|
|
5fa66202a7 |
52
README.md
52
README.md
@@ -45,17 +45,23 @@
|
||||
|
||||
# Changelog
|
||||
|
||||
- 2026/01/30 2.7.4 Release
|
||||
- Added support for domestic computing platforms IluvatarCorex and Cambricon. Currently, the officially supported domestic computing platforms include:
|
||||
- [Ascend](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Ascend/)
|
||||
- [T-Head](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/THead/)
|
||||
- [METAX](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/METAX/)
|
||||
- 2026/02/06 2.7.6 Release
|
||||
- Added support for the domestic computing platforms Kunlunxin and Tecorigin; currently, the domestic computing platforms that have been adapted and supported by the official team and vendors include:
|
||||
- [Ascend](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Ascend)
|
||||
- [T-Head](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/THead)
|
||||
- [METAX](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/METAX)
|
||||
- [Hygon](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Hygon/)
|
||||
- [Enflame](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Enflame/)
|
||||
- [MooreThreads](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/MooreThreads/)
|
||||
- [IluvatarCorex](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/IluvatarCorex/)
|
||||
- [Cambricon](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Cambricon/)
|
||||
- MinerU continues to ensure compatibility with domestic hardware platforms, supporting mainstream chip architectures. With secure and reliable technology, we empower researchers, government, and enterprises to reach new heights in document digitization!
|
||||
- [Kunlunxin](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Kunlunxin/)
|
||||
- [Tecorigin](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Tecorigin/)
|
||||
- [Biren](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Biren/)
|
||||
- MinerU continues to support domestic hardware platforms and mainstream chip architectures. With secure and reliable technology, it helps research, government, and enterprise users reach new heights in document digitization!
|
||||
|
||||
- 2026/01/30 2.7.4 Release
|
||||
- Added support for domestic computing platforms IluvatarCorex and Cambricon.
|
||||
|
||||
- 2026/01/23 2.7.2 Release
|
||||
- Added support for domestic computing platforms Hygon, Enflame, and Moore Threads.
|
||||
@@ -313,24 +319,25 @@ Currently, some models in this project are trained based on YOLO. However, since
|
||||
# Citation
|
||||
|
||||
```bibtex
|
||||
@misc{niu2025mineru25decoupledvisionlanguagemodel,
|
||||
title={MinerU2.5: A Decoupled Vision-Language Model for Efficient High-Resolution Document Parsing},
|
||||
author={Junbo Niu and Zheng Liu and Zhuangcheng Gu and Bin Wang and Linke Ouyang and Zhiyuan Zhao and Tao Chu and Tianyao He and Fan Wu and Qintong Zhang and Zhenjiang Jin and Guang Liang and Rui Zhang and Wenzheng Zhang and Yuan Qu and Zhifei Ren and Yuefeng Sun and Yuanhong Zheng and Dongsheng Ma and Zirui Tang and Boyu Niu and Ziyang Miao and Hejun Dong and Siyi Qian and Junyuan Zhang and Jingzhou Chen and Fangdong Wang and Xiaomeng Zhao and Liqun Wei and Wei Li and Shasha Wang and Ruiliang Xu and Yuanyuan Cao and Lu Chen and Qianqian Wu and Huaiyu Gu and Lindong Lu and Keming Wang and Dechen Lin and Guanlin Shen and Xuanhe Zhou and Linfeng Zhang and Yuhang Zang and Xiaoyi Dong and Jiaqi Wang and Bo Zhang and Lei Bai and Pei Chu and Weijia Li and Jiang Wu and Lijun Wu and Zhenxiang Li and Guangyu Wang and Zhongying Tu and Chao Xu and Kai Chen and Yu Qiao and Bowen Zhou and Dahua Lin and Wentao Zhang and Conghui He},
|
||||
year={2025},
|
||||
eprint={2509.22186},
|
||||
archivePrefix={arXiv},
|
||||
primaryClass={cs.CV},
|
||||
url={https://arxiv.org/abs/2509.22186},
|
||||
@article{dong2026minerudiffusion,
|
||||
title={MinerU-Diffusion: Rethinking Document OCR as Inverse Rendering via Diffusion Decoding},
|
||||
author={Dong, Hejun and Niu, Junbo and Wang, Bin and Zeng, Weijun and Zhang, Wentao and He, Conghui},
|
||||
journal={arXiv preprint arXiv:2603.22458},
|
||||
year={2026}
|
||||
}
|
||||
|
||||
@misc{wang2024mineruopensourcesolutionprecise,
|
||||
title={MinerU: An Open-Source Solution for Precise Document Content Extraction},
|
||||
author={Bin Wang and Chao Xu and Xiaomeng Zhao and Linke Ouyang and Fan Wu and Zhiyuan Zhao and Rui Xu and Kaiwen Liu and Yuan Qu and Fukai Shang and Bo Zhang and Liqun Wei and Zhihao Sui and Wei Li and Botian Shi and Yu Qiao and Dahua Lin and Conghui He},
|
||||
year={2024},
|
||||
eprint={2409.18839},
|
||||
archivePrefix={arXiv},
|
||||
primaryClass={cs.CV},
|
||||
url={https://arxiv.org/abs/2409.18839},
|
||||
@article{niu2025mineru2,
|
||||
title={Mineru2. 5: A decoupled vision-language model for efficient high-resolution document parsing},
|
||||
author={Niu, Junbo and Liu, Zheng and Gu, Zhuangcheng and Wang, Bin and Ouyang, Linke and Zhao, Zhiyuan and Chu, Tao and He, Tianyao and Wu, Fan and Zhang, Qintong and others},
|
||||
journal={arXiv preprint arXiv:2509.22186},
|
||||
year={2025}
|
||||
}
|
||||
|
||||
@article{wang2024mineru,
|
||||
title={Mineru: An open-source solution for precise document content extraction},
|
||||
author={Wang, Bin and Xu, Chao and Zhao, Xiaomeng and Ouyang, Linke and Wu, Fan and Zhao, Zhiyuan and Xu, Rui and Liu, Kaiwen and Qu, Yuan and Shang, Fukai and others},
|
||||
journal={arXiv preprint arXiv:2409.18839},
|
||||
year={2024}
|
||||
}
|
||||
|
||||
@article{he2024opendatalab,
|
||||
@@ -353,6 +360,7 @@ Currently, some models in this project are trained based on YOLO. However, since
|
||||
|
||||
|
||||
# Links
|
||||
- [MinerU-Diffusion: Rethinking Document OCR as Inverse Rendering via Diffusion Decoding](https://github.com/opendatalab/MinerU-Diffusion)
|
||||
- [Easy Data Preparation with latest LLMs-based Operators and Pipelines](https://github.com/OpenDCAI/DataFlow)
|
||||
- [Vis3 (OSS browser based on s3)](https://github.com/opendatalab/Vis3)
|
||||
- [LabelU (A Lightweight Multi-modal Data Annotation Tool)](https://github.com/opendatalab/labelU)
|
||||
|
||||
@@ -45,8 +45,8 @@
|
||||
|
||||
# 更新记录
|
||||
|
||||
- 2026/01/30 2.7.4 发布
|
||||
- 新增国产算力平台天数智芯、寒武纪的适配支持,目前已由官方适配并支持的国产算力平台包括:
|
||||
- 2026/02/06 2.7.6 发布
|
||||
- 新增国产算力平台昆仑芯、太初元碁的适配支持,目前已由官方和厂商适配并支持的国产算力平台包括:
|
||||
- [昇腾 Ascend](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Ascend)
|
||||
- [平头哥 T-Head](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/THead)
|
||||
- [沐曦 METAX](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/METAX)
|
||||
@@ -55,8 +55,14 @@
|
||||
- [摩尔线程 MooreThreads](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/MooreThreads/)
|
||||
- [天数智芯 IluvatarCorex](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/IluvatarCorex/)
|
||||
- [寒武纪 Cambricon](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Cambricon/)
|
||||
- [昆仑芯 Kunlunxin](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Kunlunxin/)
|
||||
- [太初元碁 Tecorigin](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Tecorigin/)
|
||||
- [壁仞 Biren](https://opendatalab.github.io/MinerU/zh/usage/acceleration_cards/Biren/)
|
||||
- MinerU 持续兼容国产硬件平台,支持主流芯片架构。以安全可靠的技术,助力科研、政企用户迈向文档数字化新高度!
|
||||
|
||||
- 2026/01/30 2.7.4 发布
|
||||
- 新增国产算力平台天数智芯、寒武纪的适配支持。
|
||||
|
||||
- 2026/01/23 2.7.2 发布
|
||||
- 新增国产算力平台海光、燧原、摩尔线程的适配支持
|
||||
- 跨页表合并优化,提升合并成功率与合并效果
|
||||
@@ -320,24 +326,18 @@ mineru -p <input_path> -o <output_path> -b pipeline
|
||||
# Citation
|
||||
|
||||
```bibtex
|
||||
@misc{niu2025mineru25decoupledvisionlanguagemodel,
|
||||
title={MinerU2.5: A Decoupled Vision-Language Model for Efficient High-Resolution Document Parsing},
|
||||
author={Junbo Niu and Zheng Liu and Zhuangcheng Gu and Bin Wang and Linke Ouyang and Zhiyuan Zhao and Tao Chu and Tianyao He and Fan Wu and Qintong Zhang and Zhenjiang Jin and Guang Liang and Rui Zhang and Wenzheng Zhang and Yuan Qu and Zhifei Ren and Yuefeng Sun and Yuanhong Zheng and Dongsheng Ma and Zirui Tang and Boyu Niu and Ziyang Miao and Hejun Dong and Siyi Qian and Junyuan Zhang and Jingzhou Chen and Fangdong Wang and Xiaomeng Zhao and Liqun Wei and Wei Li and Shasha Wang and Ruiliang Xu and Yuanyuan Cao and Lu Chen and Qianqian Wu and Huaiyu Gu and Lindong Lu and Keming Wang and Dechen Lin and Guanlin Shen and Xuanhe Zhou and Linfeng Zhang and Yuhang Zang and Xiaoyi Dong and Jiaqi Wang and Bo Zhang and Lei Bai and Pei Chu and Weijia Li and Jiang Wu and Lijun Wu and Zhenxiang Li and Guangyu Wang and Zhongying Tu and Chao Xu and Kai Chen and Yu Qiao and Bowen Zhou and Dahua Lin and Wentao Zhang and Conghui He},
|
||||
year={2025},
|
||||
eprint={2509.22186},
|
||||
archivePrefix={arXiv},
|
||||
primaryClass={cs.CV},
|
||||
url={https://arxiv.org/abs/2509.22186},
|
||||
@article{niu2025mineru2,
|
||||
title={Mineru2. 5: A decoupled vision-language model for efficient high-resolution document parsing},
|
||||
author={Niu, Junbo and Liu, Zheng and Gu, Zhuangcheng and Wang, Bin and Ouyang, Linke and Zhao, Zhiyuan and Chu, Tao and He, Tianyao and Wu, Fan and Zhang, Qintong and others},
|
||||
journal={arXiv preprint arXiv:2509.22186},
|
||||
year={2025}
|
||||
}
|
||||
|
||||
@misc{wang2024mineruopensourcesolutionprecise,
|
||||
title={MinerU: An Open-Source Solution for Precise Document Content Extraction},
|
||||
author={Bin Wang and Chao Xu and Xiaomeng Zhao and Linke Ouyang and Fan Wu and Zhiyuan Zhao and Rui Xu and Kaiwen Liu and Yuan Qu and Fukai Shang and Bo Zhang and Liqun Wei and Zhihao Sui and Wei Li and Botian Shi and Yu Qiao and Dahua Lin and Conghui He},
|
||||
year={2024},
|
||||
eprint={2409.18839},
|
||||
archivePrefix={arXiv},
|
||||
primaryClass={cs.CV},
|
||||
url={https://arxiv.org/abs/2409.18839},
|
||||
@article{wang2024mineru,
|
||||
title={Mineru: An open-source solution for precise document content extraction},
|
||||
author={Wang, Bin and Xu, Chao and Zhao, Xiaomeng and Ouyang, Linke and Wu, Fan and Zhao, Zhiyuan and Xu, Rui and Liu, Kaiwen and Qu, Yuan and Shang, Fukai and others},
|
||||
journal={arXiv preprint arXiv:2409.18839},
|
||||
year={2024}
|
||||
}
|
||||
|
||||
@article{he2024opendatalab,
|
||||
|
||||
33
docker/china/kxpu.Dockerfile
Normal file
33
docker/china/kxpu.Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
||||
# Base image containing the vLLM inference environment, requiring amd64(x86-64) CPU + Kunlun XPU.
|
||||
FROM docker.1ms.run/wjie520/vllm_kunlun:v0.10.1.1rc1
|
||||
|
||||
|
||||
# Install Noto fonts for Chinese characters
|
||||
RUN apt-get update && \
|
||||
apt-get install -y \
|
||||
fonts-noto-core \
|
||||
fonts-noto-cjk \
|
||||
fontconfig && \
|
||||
fc-cache -fv && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install mineru latest
|
||||
RUN python3 -m pip install -U pip -i https://mirrors.aliyun.com/pypi/simple && \
|
||||
python3 -m pip install "mineru[api,gradio]>=2.7.6" \
|
||||
"matplotlib>=3.10,<4" \
|
||||
"ultralytics>=8.3.48,<9" \
|
||||
"doclayout_yolo==0.0.4" \
|
||||
"ftfy>=6.3.1,<7" \
|
||||
"shapely>=2.0.7,<3" \
|
||||
"pyclipper>=1.3.0,<2" \
|
||||
"omegaconf>=2.3.0,<3" \
|
||||
-i https://mirrors.aliyun.com/pypi/simple && \
|
||||
sed -i '1,200{s/self\.act = act_layer()/self.act = nn.GELU()/;t;b};' /root/miniconda/envs/vllm_kunlun_0.10.1.1/lib/python3.10/site-packages/vllm_kunlun/models/qwen2_vl.py && \
|
||||
python3 -m pip cache purge
|
||||
|
||||
# Download models and update the configuration file
|
||||
RUN /bin/bash -c "mineru-models-download -s modelscope -m all"
|
||||
|
||||
# Set the entry point to activate the virtual environment and run the command line tool
|
||||
ENTRYPOINT ["/bin/bash", "-c", "export MINERU_MODEL_SOURCE=local && exec \"$@\"", "--"]
|
||||
@@ -1,6 +1,6 @@
|
||||
# 基础镜像配置 vLLM 或 LMDeploy ,请根据实际需要选择其中一个,要求 amd64(x86-64) CPU + Cambricon MLU.
|
||||
# Base image containing the LMDEPLOY inference environment, requiring amd64(x86-64) CPU + Cambricon MLU.
|
||||
FROM crpi-4crprmm5baj1v8iv.cn-hangzhou.personal.cr.aliyuncs.com/lmdeploy_dlinfer/camb:qwen2.5_vl
|
||||
FROM crpi-4crprmm5baj1v8iv.cn-hangzhou.personal.cr.aliyuncs.com/lmdeploy_dlinfer/camb:mineru25
|
||||
ARG BACKEND=lmdeploy
|
||||
# Base image containing the vLLM inference environment, requiring amd64(x86-64) CPU + Cambricon MLU.
|
||||
# FROM crpi-vofi3w62lkohhxsp.cn-shanghai.personal.cr.aliyuncs.com/opendatalab-mineru/mlu:vllm0.8.3-torch2.6.0-torchmlu1.26.1-ubuntu22.04-py310
|
||||
@@ -39,4 +39,4 @@ RUN /bin/bash -c '\
|
||||
WORKDIR /workspace
|
||||
|
||||
# Set the entry point to activate the virtual environment and run the command line tool
|
||||
ENTRYPOINT ["/bin/bash", "-c", "export MINERU_MODEL_SOURCE=local && exec \"$@\"", "--"]
|
||||
ENTRYPOINT ["/bin/bash", "-c", "export MINERU_MODEL_SOURCE=local && exec \"$@\"", "--"]
|
||||
|
||||
112
docs/zh/usage/acceleration_cards/Biren.md
Normal file
112
docs/zh/usage/acceleration_cards/Biren.md
Normal file
@@ -0,0 +1,112 @@
|
||||
## 1. 测试平台
|
||||
以下为本指南测试使用的平台信息,供参考:
|
||||
```
|
||||
os: Ubuntu 22.04.4 LTS
|
||||
cpu: Intel x86-64
|
||||
gpu: Biren 106C
|
||||
driver: 1.10.0
|
||||
docker: 28.0.4
|
||||
```
|
||||
|
||||
## 2. 环境准备
|
||||
|
||||
### 2.1 下载并加载镜像 (vllm)
|
||||
|
||||
```bash
|
||||
wget http://birentech.com/xxx/MinerU/mineru-vllm.tar 链接获取请联系壁仞内部人员(邮箱:MonaLiu@birentech.com)
|
||||
docker load -i mineru-vllm.tar
|
||||
```
|
||||
|
||||
## 3. 启动 Docker 容器
|
||||
|
||||
```bash
|
||||
docker run -it --name mineru_docker \
|
||||
--privileged \
|
||||
--network=host \
|
||||
--shm-size=100G \
|
||||
-e MINERU_MODEL_SOURCE=local \
|
||||
-e MINERU_DEVICE_MODEL=supa \
|
||||
-e SHAPE_TRANSFORM_GRANK=true \
|
||||
mineru:biren-vllm-latest \
|
||||
/bin/bash
|
||||
```
|
||||
|
||||
|
||||
执行该命令后,您将进入到Docker容器的交互式终端,您可以直接在容器内运行MinerU相关命令来使用MinerU的功能。
|
||||
您也可以直接通过替换`/bin/bash`为服务启动命令来启动MinerU服务,详细说明请参考[通过命令启动服务](https://opendatalab.github.io/MinerU/zh/usage/quick_usage/#apiwebuihttp-clientserver)。
|
||||
|
||||
|
||||
## 4. 注意事项
|
||||
|
||||
不同环境下,MinerU对Biren加速卡的支持情况如下表所示:
|
||||
|
||||
<table border="1">
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowspan="2" colspan="2">使用场景</th>
|
||||
<th colspan="2">容器环境</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>vllm</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">命令行工具(mineru)</td>
|
||||
<td>pipeline</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-auto-engine</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-http-client</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">fastapi服务(mineru-api)</td>
|
||||
<td>pipeline</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-auto-engine</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-http-client</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">gradio界面(mineru-gradio)</td>
|
||||
<td>pipeline</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-auto-engine</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-http-client</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">openai-server服务(mineru-openai-server)</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">数据并行 (--data-parallel-size)</td>
|
||||
<td>🔴</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
注:
|
||||
🟢: 支持,运行较稳定,精度与Nvidia GPU基本一致
|
||||
🟡: 支持但较不稳定,在某些场景下可能出现异常,或精度存在一定差异
|
||||
🔴: 不支持,无法运行,或精度存在较大差异
|
||||
|
||||
>[!TIP]
|
||||
> - Biren加速卡指定可用加速卡的方式与NVIDIA GPU类似,请参考[使用指定GPU设备](https://opendatalab.github.io/MinerU/zh/usage/advanced_cli_parameters/#cuda_visible_devices)章节说明,
|
||||
>将环境变量`CUDA_VISIBLE_DEVICES`替换为`SUPA_VISIBLE_DEVICES`即可。
|
||||
> - 在壁仞平台可以通过`brsmi`命令查看加速卡的使用情况,并根据需要指定空闲的加速卡ID以避免资源冲突。
|
||||
@@ -36,7 +36,7 @@ docker run --name mineru_docker \
|
||||
--security-opt apparmor=unconfined \
|
||||
-e VLLM_ENFORCE_CUDA_GRAPH=1 \
|
||||
-e MINERU_MODEL_SOURCE=local \
|
||||
-e MINERU_LMDEPLOY_DEVICE=corex \
|
||||
-e MINERU_VLLM_DEVICE=corex \
|
||||
-it mineru:corex-vllm-latest \
|
||||
/bin/bash
|
||||
```
|
||||
|
||||
124
docs/zh/usage/acceleration_cards/Kunlunxin.md
Normal file
124
docs/zh/usage/acceleration_cards/Kunlunxin.md
Normal file
@@ -0,0 +1,124 @@
|
||||
## 1. 测试平台
|
||||
以下为本指南测试使用的平台信息,供参考:
|
||||
```
|
||||
os: Ubuntu 22.04.5 LTS
|
||||
cpu: Intel x86-64
|
||||
xpu: P800
|
||||
driver: 515.58
|
||||
docker: 20.10.5
|
||||
```
|
||||
|
||||
## 2. 环境准备
|
||||
|
||||
### 2.1 使用 Dockerfile 构建镜像 (vllm)
|
||||
|
||||
```bash
|
||||
wget https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/docker/china/kxpu.Dockerfile
|
||||
docker build --network=host -t mineru:kxpu-vllm-latest -f kxpu.Dockerfile .
|
||||
```
|
||||
|
||||
## 3. 启动 Docker 容器
|
||||
|
||||
```bash
|
||||
docker run -u root --name mineru_docker \
|
||||
--device=/dev/xpu0:/dev/xpu0 \
|
||||
--device=/dev/xpu1:/dev/xpu1 \
|
||||
--device=/dev/xpu2:/dev/xpu2 \
|
||||
--device=/dev/xpu3:/dev/xpu3 \
|
||||
--device=/dev/xpu4:/dev/xpu4 \
|
||||
--device=/dev/xpu5:/dev/xpu5 \
|
||||
--device=/dev/xpu6:/dev/xpu6 \
|
||||
--device=/dev/xpu7:/dev/xpu7 \
|
||||
--device=/dev/xpuctrl:/dev/xpuctrl \
|
||||
--net=host \
|
||||
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
|
||||
--tmpfs /dev/shm:rw,nosuid,nodev,exec,size=32g \
|
||||
--cap-add=SYS_PTRACE \
|
||||
-v /home/users/vllm-kunlun:/home/vllm-kunlun \
|
||||
-v /usr/local/bin/xpu-smi:/usr/local/bin/xpu-smi \
|
||||
-w /workspace \
|
||||
-e MINERU_MODEL_SOURCE=local \
|
||||
-e MINERU_FORMULA_CH_SUPPORT=true \
|
||||
-e MINERU_VLLM_DEVICE=kxpu \
|
||||
-it mineru:kxpu-vllm-latest \
|
||||
/bin/bash
|
||||
```
|
||||
|
||||
执行该命令后,您将进入到Docker容器的交互式终端,您可以直接在容器内运行MinerU相关命令来使用MinerU的功能。
|
||||
您也可以直接通过替换`/bin/bash`为服务启动命令来启动MinerU服务,详细说明请参考[通过命令启动服务](https://opendatalab.github.io/MinerU/zh/usage/quick_usage/#apiwebuihttp-clientserver)。
|
||||
|
||||
|
||||
## 4. 注意事项
|
||||
|
||||
不同环境下,MinerU对Kunlunxin加速卡的支持情况如下表所示:
|
||||
|
||||
<table border="1">
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowspan="2" colspan="2">使用场景</th>
|
||||
<th colspan="2">容器环境</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>vllm</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">命令行工具(mineru)</td>
|
||||
<td>pipeline</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-auto-engine</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-http-client</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">fastapi服务(mineru-api)</td>
|
||||
<td>pipeline</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-auto-engine</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-http-client</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">gradio界面(mineru-gradio)</td>
|
||||
<td>pipeline</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-auto-engine</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-http-client</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">openai-server服务(mineru-openai-server)</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">数据并行 (--data-parallel-size)</td>
|
||||
<td>🔴</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
注:
|
||||
🟢: 支持,运行较稳定,精度与Nvidia GPU基本一致
|
||||
🟡: 支持但较不稳定,在某些场景下可能出现异常,或精度存在一定差异
|
||||
🔴: 不支持,无法运行,或精度存在较大差异
|
||||
|
||||
>[!TIP]
|
||||
> - Kunlunxin加速卡指定可用加速卡的方式与NVIDIA GPU类似,请参考[使用指定GPU设备](https://opendatalab.github.io/MinerU/zh/usage/advanced_cli_parameters/#cuda_visible_devices)章节说明,
|
||||
>将环境变量`CUDA_VISIBLE_DEVICES`替换为`XPU_VISIBLE_DEVICES`即可。
|
||||
> - 在Kunlunxin平台可以通过`xpu-smi`命令查看加速卡的使用情况,并根据需要指定空闲的加速卡ID以避免资源冲突。
|
||||
@@ -27,6 +27,7 @@ docker run -u root --name mineru_docker \
|
||||
--shm-size=80g \
|
||||
--privileged \
|
||||
-e MTHREADS_VISIBLE_DEVICES=all \
|
||||
-e MINERU_VLLM_DEVICE=musa \
|
||||
-e MINERU_MODEL_SOURCE=local \
|
||||
-it mineru:musa-vllm-latest \
|
||||
/bin/bash
|
||||
|
||||
@@ -127,7 +127,7 @@ docker run --privileged=true \
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">数据并行 (--data-parallel-size/--dp)</td>
|
||||
<td>🟡</td>
|
||||
<td>🔴</td>
|
||||
<td>🔴</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -1,73 +1,120 @@
|
||||
# TECO适配
|
||||
## 1. 测试平台
|
||||
以下为本指南测试使用的平台信息,供参考:
|
||||
```
|
||||
os: Ubuntu 22.04.5 LTS
|
||||
cpu: AMD EPYC (amd64)
|
||||
gpu: T100
|
||||
driver: 3.0.0
|
||||
docker: 28.0.4
|
||||
```
|
||||
|
||||
## 快速开始
|
||||
使用本工具执行推理的主要流程如下:
|
||||
1. 基础环境安装:介绍推理前需要完成的基础环境检查和安装。
|
||||
3. 构建Docker环境:介绍如何使用Dockerfile创建模型推理时所需的Docker环境。
|
||||
4. 启动推理:介绍如何启动推理。
|
||||
## 2. 环境准备
|
||||
|
||||
### 1 基础环境安装
|
||||
请参考[Teco用户手册的安装准备章节](http://docs.tecorigin.com/release/torch_2.4/v2.2.0/#fc980a30f1125aa88bad4246ff0cedcc),完成训练前的基础环境检查和安装。
|
||||
### 2.1 下载并加载镜像 (vllm)
|
||||
|
||||
### 2 构建docker
|
||||
#### 2.1 执行以下命令,下载Docker镜像至本地(Docker镜像包:pytorch-3.0.0-torch_sdaa3.0.0.tar)
|
||||
```bash
|
||||
wget http://wb.tecorigin.com:8082/repository/teco-customer-repo/Course/MinerU/mineru-vllm.tar
|
||||
|
||||
wget 镜像下载链接(链接获取请联系太初内部人员)
|
||||
docker load -i mineru-vllm.tar
|
||||
```
|
||||
|
||||
#### 2.2 校验Docker镜像包,执行以下命令,生成MD5码是否与官方MD5码b2a7f60508c0d199a99b8b6b35da3954一致:
|
||||
## 3. 启动 Docker 容器
|
||||
|
||||
md5sum pytorch-3.0.0-torch_sdaa3.0.0.tar
|
||||
```bash
|
||||
docker run -dit --name mineru_docker \
|
||||
--privileged \
|
||||
--cap-add SYS_PTRACE \
|
||||
--cap-add SYS_ADMIN \
|
||||
--network=host \
|
||||
--shm-size=500G \
|
||||
mineru:sdaa-vllm-latest \
|
||||
/bin/bash
|
||||
```
|
||||
|
||||
#### 2.3 执行以下命令,导入Docker镜像
|
||||
>[!TIP]
|
||||
> 如需使用`vllm`环境,请执行以下操作:
|
||||
> - 进入容器后,通过以下命令切换到conda环境:
|
||||
> ```bash
|
||||
> conda activate vllm_env_py310
|
||||
> ```
|
||||
>
|
||||
> - 切换成功后,您可以在命令行前看到`(vllm_env_py310)`的标识,这表示您已成功进入`vllm`的虚拟环境。
|
||||
|
||||
docker load < pytorch-3.0.0-torch_sdaa3.0.0.tar
|
||||
|
||||
#### 2.4 执行以下命令,构建名为MinerU的Docker容器
|
||||
|
||||
docker run -itd --name="MinerU" --net=host --device=/dev/tcaicard0 --device=/dev/tcaicard1 --device=/dev/tcaicard2 --device=/dev/tcaicard3 --cap-add SYS_PTRACE --cap-add SYS_ADMIN --shm-size 64g jfrog.tecorigin.net/tecotp-docker/release/ubuntu22.04/x86_64/pytorch:3.0.0-torch_sdaa3.0.0 /bin/bash
|
||||
|
||||
#### 2.5 执行以下命令,进入名称为tecopytorch_docker的Docker容器。
|
||||
|
||||
docker exec -it MinerU bash
|
||||
执行该命令后,您将进入到Docker容器的交互式终端,您可以直接在容器内运行MinerU相关命令来使用MinerU的功能。
|
||||
您也可以直接通过替换`/bin/bash`为服务启动命令来启动MinerU服务,详细说明请参考[通过命令启动服务](https://opendatalab.github.io/MinerU/zh/usage/quick_usage/#apiwebuihttp-clientserver)。
|
||||
|
||||
|
||||
### 3 执行以下命令安装MinerU
|
||||
- 安装前的准备
|
||||
```
|
||||
cd <MinerU>
|
||||
pip install --upgrade pip
|
||||
pip install uv
|
||||
```
|
||||
- 由于镜像中安装了torch,并且不需要安装nvidia-nccl-cu12、nvidia-cudnn-cu12等包,因此需要注释掉一部分安装依赖。
|
||||
- 请注释掉<MinerU>/pyproject.toml文件中所有的"doclayout_yolo==0.0.4"依赖,并且将torch开头的包也注释掉。
|
||||
- 执行以下命令安装MinerU
|
||||
```
|
||||
uv pip install -e .[core]
|
||||
```
|
||||
- 下载安装doclayout_yolo==0.0.4
|
||||
```
|
||||
pip install doclayout_yolo==0.0.4 --no-deps
|
||||
```
|
||||
- 下载安装其他包(doclayout_yolo==0.0.4的依赖)
|
||||
```
|
||||
pip install albumentations py-cpuinfo seaborn thop numpy==1.24.4
|
||||
```
|
||||
- 由于部分张量内部内存分布不连续,需要修改如下两个文件
|
||||
<ultralytics安装路径>/ultralytics/utils/tal.py(330行左右,将view --> reshape)
|
||||
<doclayout_yolo安装路径>/doclayout_yolo/utils/tal.py(375行左右,将view --> reshape)
|
||||
### 4 执行推理
|
||||
- 开启sdaa环境
|
||||
```
|
||||
export TORCH_SDAA_AUTOLOAD=cuda_migrate
|
||||
```
|
||||
- 首次运行推理命令前请添加以下环境下载模型权重
|
||||
```
|
||||
export HF_ENDPOINT=https://hf-mirror.com
|
||||
```
|
||||
- 运行以下命令执行推理
|
||||
```
|
||||
mineru -p 'input path' -o 'output_path' --lang 'model_name'
|
||||
```
|
||||
其中model_name可从'ch', 'ch_server', 'ch_lite', 'en', 'korean', 'japan', 'chinese_cht', 'ta', 'te', 'ka', 'latin', 'arabic', 'east_slavic', 'cyrillic', 'devanagari'选择
|
||||
### 5 适配用到的软件栈版本列表
|
||||
使用v3.0.0软件栈版本适配,获取方式联系太初内部人员
|
||||
## 4. 注意事项
|
||||
|
||||
不同环境下,MinerU对Tecorigin加速卡的支持情况如下表所示:
|
||||
|
||||
<table border="1">
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowspan="2" colspan="2">使用场景</th>
|
||||
<th colspan="2">容器环境</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>vllm</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">命令行工具(mineru)</td>
|
||||
<td>pipeline</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-auto-engine</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-http-client</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">fastapi服务(mineru-api)</td>
|
||||
<td>pipeline</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-auto-engine</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-http-client</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan="3">gradio界面(mineru-gradio)</td>
|
||||
<td>pipeline</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-auto-engine</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><vlm/hybrid>-http-client</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">openai-server服务(mineru-openai-server)</td>
|
||||
<td>🟢</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">数据并行 (--data-parallel-size)</td>
|
||||
<td>🔴</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
注:
|
||||
🟢: 支持,运行较稳定,精度与Nvidia GPU基本一致
|
||||
🟡: 支持但较不稳定,在某些场景下可能出现异常,或精度存在一定差异
|
||||
🔴: 不支持,无法运行,或精度存在较大差异
|
||||
|
||||
>[!TIP]
|
||||
> - Tecorigin加速卡指定可用加速卡的方式与NVIDIA GPU类似,请参考[使用指定GPU设备](https://opendatalab.github.io/MinerU/zh/usage/advanced_cli_parameters/#cuda_visible_devices)章节说明,
|
||||
>将环境变量`CUDA_VISIBLE_DEVICES`替换为`SDAA_VISIBLE_DEVICES`即可。
|
||||
> - 在太初平台可以通过`teco-smi -c`命令查看加速卡的使用情况,并根据需要指定空闲的加速卡ID以避免资源冲突。
|
||||
@@ -17,9 +17,11 @@
|
||||
* [摩尔线程 MooreThreads](acceleration_cards/MooreThreads.md) 🚀
|
||||
* [天数智芯 IluvatarCorex](acceleration_cards/IluvatarCorex.md) 🚀
|
||||
* [寒武纪 Cambricon](acceleration_cards/Cambricon.md) 🚀
|
||||
* [AMD](acceleration_cards/AMD.md) [#3662](https://github.com/opendatalab/MinerU/discussions/3662) ❤️
|
||||
* [太初元碁 Tecorigin](acceleration_cards/Tecorigin.md) [#3767](https://github.com/opendatalab/MinerU/pull/3767) ❤️
|
||||
* [瀚博 VastAI](acceleration_cards/VastAI.md) [#4237](https://github.com/opendatalab/MinerU/discussions/4237)❤️
|
||||
* [昆仑芯 Kunlunxin](acceleration_cards/Kunlunxin.md) 🚀
|
||||
* [太初元碁 Tecorigin](acceleration_cards/Tecorigin.md) ❤️
|
||||
* [壁仞 Biren](acceleration_cards/Biren.md) ❤️
|
||||
* [AMD #3662](https://github.com/opendatalab/MinerU/discussions/3662) ❤️
|
||||
* [瀚博 VastAI #4237](https://github.com/opendatalab/MinerU/discussions/4237) ❤️
|
||||
- 插件与生态
|
||||
* [Cherry Studio](plugin/Cherry_Studio.md)
|
||||
* [Sider](plugin/Sider.md)
|
||||
|
||||
@@ -24,6 +24,9 @@ def enable_custom_logits_processors() -> bool:
|
||||
compute_capability = "8.0"
|
||||
elif hasattr(torch, 'mlu') and torch.mlu.is_available():
|
||||
compute_capability = "8.0"
|
||||
elif hasattr(torch, 'sdaa') and torch.sdaa.is_available():
|
||||
compute_capability = "8.0"
|
||||
|
||||
else:
|
||||
logger.info("CUDA not available, disabling custom_logits_processors")
|
||||
return False
|
||||
@@ -102,4 +105,128 @@ def set_default_batch_size() -> int:
|
||||
except Exception as e:
|
||||
logger.warning(f'Error determining VRAM: {e}, using default batch_ratio: 1')
|
||||
batch_size = 1
|
||||
return batch_size
|
||||
return batch_size
|
||||
|
||||
|
||||
def _get_device_config(device_type: str) -> dict | None:
|
||||
"""获取不同设备类型的配置参数"""
|
||||
|
||||
# 各设备类型的配置定义
|
||||
DEVICE_CONFIGS = {
|
||||
# "musa": {
|
||||
# "compilation_config_dict": {
|
||||
# "cudagraph_capture_sizes": [1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 18, 20, 24, 28, 30],
|
||||
# "simple_cuda_graph": True
|
||||
# },
|
||||
# "block_size": 32,
|
||||
# },
|
||||
"corex": {
|
||||
"compilation_config_dict": {
|
||||
"cudagraph_mode": "FULL_DECODE_ONLY",
|
||||
"level": 0
|
||||
},
|
||||
},
|
||||
"kxpu": {
|
||||
"compilation_config_dict": {
|
||||
"splitting_ops": [
|
||||
"vllm.unified_attention", "vllm.unified_attention_with_output",
|
||||
"vllm.unified_attention_with_output_kunlun", "vllm.mamba_mixer2",
|
||||
"vllm.mamba_mixer", "vllm.short_conv", "vllm.linear_attention",
|
||||
"vllm.plamo2_mamba_mixer", "vllm.gdn_attention", "vllm.sparse_attn_indexer"
|
||||
]
|
||||
},
|
||||
"block_size": 128,
|
||||
"dtype": "float16",
|
||||
"distributed_executor_backend": "mp",
|
||||
"enable_chunked_prefill": False,
|
||||
"enable_prefix_caching": False,
|
||||
},
|
||||
}
|
||||
|
||||
return DEVICE_CONFIGS.get(device_type.lower())
|
||||
|
||||
|
||||
def _check_server_arg_exists(args: list, arg_name: str) -> bool:
|
||||
"""检查命令行参数列表中是否已存在指定参数"""
|
||||
return any(arg == f"--{arg_name}" or arg.startswith(f"--{arg_name}=") for arg in args)
|
||||
|
||||
|
||||
def _add_server_arg_if_missing(args: list, arg_name: str, value: str) -> None:
|
||||
"""如果参数不存在,则添加到命令行参数列表"""
|
||||
if not _check_server_arg_exists(args, arg_name):
|
||||
args.extend([f"--{arg_name}", value])
|
||||
|
||||
|
||||
def _add_server_flag_if_missing(args: list, flag_name: str) -> None:
|
||||
"""如果 flag 不存在,则添加到命令行参数列表"""
|
||||
if not _check_server_arg_exists(args, flag_name):
|
||||
args.append(f"--{flag_name}")
|
||||
|
||||
|
||||
def _add_engine_kwarg_if_missing(kwargs: dict, key: str, value) -> None:
|
||||
"""如果参数不存在,则添加到 kwargs 字典"""
|
||||
if key not in kwargs:
|
||||
kwargs[key] = value
|
||||
|
||||
|
||||
def mod_kwargs_by_device_type(kwargs_or_args: dict | list, vllm_mode: str) -> dict | list:
|
||||
"""根据设备类型修改 vllm 配置参数
|
||||
|
||||
Args:
|
||||
kwargs_or_args: 配置参数,server 模式为 list,engine 模式为 dict
|
||||
vllm_mode: vllm 运行模式 ("server", "sync_engine", "async_engine")
|
||||
|
||||
Returns:
|
||||
修改后的配置参数
|
||||
"""
|
||||
device_type = os.getenv("MINERU_VLLM_DEVICE", "")
|
||||
config = _get_device_config(device_type)
|
||||
|
||||
if config is None:
|
||||
return kwargs_or_args
|
||||
|
||||
if vllm_mode == "server":
|
||||
_apply_server_config(kwargs_or_args, config)
|
||||
else:
|
||||
_apply_engine_config(kwargs_or_args, config, vllm_mode)
|
||||
|
||||
return kwargs_or_args
|
||||
|
||||
|
||||
def _apply_server_config(args: list, config: dict) -> None:
|
||||
"""应用 server 模式的配置"""
|
||||
import json
|
||||
|
||||
for key, value in config.items():
|
||||
if key == "compilation_config_dict":
|
||||
_add_server_arg_if_missing(
|
||||
args, "compilation-config",
|
||||
json.dumps(value, separators=(',', ':'))
|
||||
)
|
||||
else:
|
||||
# 转换 key 格式: block_size -> block-size
|
||||
arg_name = key.replace("_", "-")
|
||||
if arg_name in {"enable-chunked-prefill", "enable-prefix-caching"} and value is False:
|
||||
_add_server_flag_if_missing(args, f"no-{arg_name}")
|
||||
continue
|
||||
_add_server_arg_if_missing(args, arg_name, str(value))
|
||||
|
||||
|
||||
def _apply_engine_config(kwargs: dict, config: dict, vllm_mode: str) -> None:
|
||||
"""应用 engine 模式的配置"""
|
||||
try:
|
||||
from vllm.config import CompilationConfig
|
||||
except ImportError:
|
||||
raise ImportError("Please install vllm to use the vllm-async-engine backend.")
|
||||
|
||||
for key, value in config.items():
|
||||
if key == "compilation_config_dict":
|
||||
if vllm_mode == "sync_engine":
|
||||
compilation_config = value
|
||||
elif vllm_mode == "async_engine":
|
||||
compilation_config = CompilationConfig(**value)
|
||||
else:
|
||||
continue
|
||||
_add_engine_kwarg_if_missing(kwargs, "compilation_config", compilation_config)
|
||||
else:
|
||||
_add_engine_kwarg_if_missing(kwargs, key, value)
|
||||
|
||||
@@ -6,7 +6,7 @@ import json
|
||||
from loguru import logger
|
||||
|
||||
from .utils import enable_custom_logits_processors, set_default_gpu_memory_utilization, set_default_batch_size, \
|
||||
set_lmdeploy_backend
|
||||
set_lmdeploy_backend, mod_kwargs_by_device_type
|
||||
from .model_output_to_middle_json import result_to_middle_json
|
||||
from ...data.data_reader_writer import DataWriter
|
||||
from mineru.utils.pdf_image_tools import load_images_from_pdf
|
||||
@@ -101,27 +101,7 @@ class ModelSingleton:
|
||||
except ImportError:
|
||||
raise ImportError("Please install vllm to use the vllm-engine backend.")
|
||||
|
||||
# musa vllm v1 引擎特殊配置
|
||||
# device = get_device()
|
||||
# if device_type.startswith("musa"):
|
||||
# import torch
|
||||
# if torch.musa.is_available():
|
||||
# compilation_config = {
|
||||
# "cudagraph_capture_sizes": [1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 18, 20, 24, 28, 30],
|
||||
# "simple_cuda_graph": True
|
||||
# }
|
||||
# block_size = 32
|
||||
# kwargs["compilation_config"] = compilation_config
|
||||
# kwargs["block_size"] = block_size
|
||||
|
||||
# corex vllm v1 引擎特殊配置
|
||||
device_type = os.getenv("MINERU_LMDEPLOY_DEVICE", "")
|
||||
if device_type.lower() == "corex":
|
||||
compilation_config = {
|
||||
"cudagraph_mode": "FULL_DECODE_ONLY",
|
||||
"level": 0
|
||||
}
|
||||
kwargs["compilation_config"] = compilation_config
|
||||
kwargs = mod_kwargs_by_device_type(kwargs, vllm_mode="sync_engine")
|
||||
|
||||
if "compilation_config" in kwargs:
|
||||
if isinstance(kwargs["compilation_config"], str):
|
||||
@@ -148,28 +128,7 @@ class ModelSingleton:
|
||||
except ImportError:
|
||||
raise ImportError("Please install vllm to use the vllm-async-engine backend.")
|
||||
|
||||
|
||||
# musa vllm v1 引擎特殊配置
|
||||
# device = get_device()
|
||||
# if device.startswith("musa"):
|
||||
# import torch
|
||||
# if torch.musa.is_available():
|
||||
# compilation_config = CompilationConfig(
|
||||
# cudagraph_capture_sizes=[1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 18, 20, 24, 28, 30],
|
||||
# simple_cuda_graph=True
|
||||
# )
|
||||
# block_size = 32
|
||||
# kwargs["compilation_config"] = compilation_config
|
||||
# kwargs["block_size"] = block_size
|
||||
|
||||
# corex vllm v1 引擎特殊配置
|
||||
device_type = os.getenv("MINERU_LMDEPLOY_DEVICE", "")
|
||||
if device_type.lower() == "corex":
|
||||
compilation_config = CompilationConfig(
|
||||
cudagraph_mode="FULL_DECODE_ONLY",
|
||||
level=0
|
||||
)
|
||||
kwargs["compilation_config"] = compilation_config
|
||||
kwargs = mod_kwargs_by_device_type(kwargs, vllm_mode="async_engine")
|
||||
|
||||
if "compilation_config" in kwargs:
|
||||
if isinstance(kwargs["compilation_config"], dict):
|
||||
|
||||
@@ -89,7 +89,11 @@ class FormulaRecognizer(BaseOCRV20):
|
||||
return rec_formula
|
||||
|
||||
def batch_predict(
|
||||
self, images_mfd_res: list, images: list, batch_size: int = 64
|
||||
self,
|
||||
images_mfd_res: list,
|
||||
images: list,
|
||||
batch_size: int = 64,
|
||||
interline_enable: bool = True,
|
||||
) -> list:
|
||||
images_formula_list = []
|
||||
mf_image_list = []
|
||||
@@ -105,6 +109,8 @@ class FormulaRecognizer(BaseOCRV20):
|
||||
for idx, (xyxy, conf, cla) in enumerate(
|
||||
zip(mfd_res.boxes.xyxy, mfd_res.boxes.conf, mfd_res.boxes.cls)
|
||||
):
|
||||
if not interline_enable and cla.item() == 1:
|
||||
continue # Skip interline regions if not enabled
|
||||
xmin, ymin, xmax, ymax = [int(p.item()) for p in xyxy]
|
||||
new_item = {
|
||||
"category_id": 13 + int(cla.item()),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from mineru.backend.vlm.utils import set_default_gpu_memory_utilization, enable_custom_logits_processors
|
||||
from mineru.utils.config_reader import get_device
|
||||
from mineru.backend.vlm.utils import set_default_gpu_memory_utilization, enable_custom_logits_processors, \
|
||||
mod_kwargs_by_device_type
|
||||
from mineru.utils.models_download_utils import auto_download_and_get_model_root_path
|
||||
|
||||
from vllm.entrypoints.cli.main import main as vllm_main
|
||||
@@ -14,8 +14,6 @@ def main():
|
||||
has_port_arg = False
|
||||
has_gpu_memory_utilization_arg = False
|
||||
has_logits_processors_arg = False
|
||||
has_block_size_arg = False
|
||||
has_compilation_config = False
|
||||
model_path = None
|
||||
model_arg_indices = []
|
||||
|
||||
@@ -27,10 +25,6 @@ def main():
|
||||
has_gpu_memory_utilization_arg = True
|
||||
if arg == "--logits-processors" or arg.startswith("--logits-processors="):
|
||||
has_logits_processors_arg = True
|
||||
if arg == "--block-size" or arg.startswith("--block-size="):
|
||||
has_block_size_arg = True
|
||||
if arg == "--compilation-config" or arg.startswith("--compilation-config="):
|
||||
has_compilation_config = True
|
||||
if arg == "--model":
|
||||
if i + 1 < len(args):
|
||||
model_path = args[i + 1]
|
||||
@@ -57,21 +51,7 @@ def main():
|
||||
if (not has_logits_processors_arg) and custom_logits_processors:
|
||||
args.extend(["--logits-processors", "mineru_vl_utils:MinerULogitsProcessor"])
|
||||
|
||||
# musa vllm v1 引擎特殊配置
|
||||
# device = get_device()
|
||||
# if device.startswith("musa"):
|
||||
# import torch
|
||||
# if torch.musa.is_available():
|
||||
# if not has_block_size_arg:
|
||||
# args.extend(["--block-size", "32"])
|
||||
# if not has_compilation_config:
|
||||
# args.extend(["--compilation-config", '{"cudagraph_capture_sizes": [1,2,3,4,5,6,7,8,10,12,14,16,18,20,24,28,30], "simple_cuda_graph": true}'])
|
||||
|
||||
# corex vllm v1 引擎特殊配置
|
||||
device_type = os.getenv("MINERU_LMDEPLOY_DEVICE", "")
|
||||
if device_type.lower() == "corex":
|
||||
if not has_compilation_config:
|
||||
args.extend(["--compilation-config", '{"cudagraph_mode": "FULL_DECODE_ONLY", "level": 0}'])
|
||||
args = mod_kwargs_by_device_type(args, vllm_mode="server")
|
||||
|
||||
# 重构参数,将模型路径作为位置参数
|
||||
sys.argv = [sys.argv[0]] + ["serve", model_path] + args
|
||||
|
||||
@@ -202,6 +202,10 @@ def model_init(model_name: str):
|
||||
if hasattr(torch, 'mlu') and torch.mlu.is_available():
|
||||
if torch.mlu.is_bf16_supported():
|
||||
bf_16_support = True
|
||||
elif device_name.startswith("sdaa"):
|
||||
if hasattr(torch, 'sdaa') and torch.sdaa.is_available():
|
||||
if torch.sdaa.is_bf16_supported():
|
||||
bf_16_support = True
|
||||
|
||||
if model_name == 'layoutreader':
|
||||
# 检测modelscope的缓存目录是否存在
|
||||
|
||||
@@ -98,7 +98,12 @@ def get_device():
|
||||
if torch.mlu.is_available():
|
||||
return "mlu"
|
||||
except Exception as e:
|
||||
pass
|
||||
try:
|
||||
if torch.sdaa.is_available():
|
||||
return "sdaa"
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
return "cpu"
|
||||
|
||||
|
||||
|
||||
@@ -432,6 +432,9 @@ def clean_memory(device='cuda'):
|
||||
elif str(device).startswith("mlu"):
|
||||
if torch.mlu.is_available():
|
||||
torch.mlu.empty_cache()
|
||||
elif str(device).startswith("sdaa"):
|
||||
if torch.sdaa.is_available():
|
||||
torch.sdaa.empty_cache()
|
||||
gc.collect()
|
||||
|
||||
|
||||
@@ -476,5 +479,8 @@ def get_vram(device) -> int:
|
||||
elif str(device).startswith("mlu"):
|
||||
if torch.mlu.is_available():
|
||||
total_memory = round(torch.mlu.get_device_properties(device).total_memory / (1024 ** 3)) # 转为 GB
|
||||
elif str(device).startswith("sdaa"):
|
||||
if torch.sdaa.is_available():
|
||||
total_memory = round(torch.sdaa.get_device_properties(device).total_memory / (1024 ** 3)) # 转为 GB
|
||||
|
||||
return total_memory
|
||||
|
||||
@@ -1 +1 @@
|
||||
__version__ = "2.7.4"
|
||||
__version__ = "2.7.6"
|
||||
|
||||
Reference in New Issue
Block a user