Skip to content

Commit

Permalink
improvement(installation): add script install mmdeploy (#919)
Browse files Browse the repository at this point in the history
* feat(tools): add build ubuntu x64 ncnn

* ci(tools): add ncnn auto install

* fix(ci): auto install ncnn

* fix(tools): no interactive

* docs(build): add script build

* CI(ncnn): script install ncnn

* docs(zh_cn): fix error os

* fix

* CI(tools/script): test ort install passed

* update

* CI(tools): support pplnn

* CI(build): add pplnn

* docs(tools): update

* fix

* CI(tools): script install torchscript

* docs(build): add torchscript

* fix(tools): clean code and doc

* update

* fix(CI): requirements install failed

* debug CI

* update

* update

* update

* feat(tools/script): support user specify make jobs

* fix(tools/script): fix build pplnn with cuda

* fix(tools/script): torchscript add tips and simplify install mmcv

* fix(tools/script): check nvcc version first

* fix(tools/scripts): pplnn checkout

* fix(CI): add simple check install succcess

* fix

* debug CI

* fix

* fix(CI): pplnn install mis wheel

* fix(CI): build error

* fix(CI): remove misleading message
  • Loading branch information
tpoisonooo authored Aug 26, 2022
1 parent b1e7579 commit 4534598
Show file tree
Hide file tree
Showing 19 changed files with 1,018 additions and 8 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/backend-ncnn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ jobs:
strategy:
matrix:
python-version: [3.7]
torch: [1.9.0]
include:
- torch: 1.9.0
torch_version: torch1.9
torchvision: 0.10.0
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down Expand Up @@ -65,3 +60,23 @@ jobs:
echo $(pwd)
ln -s build/bin/mmdeploy_onnx2ncnn ./
python3 .github/scripts/test_onnx2ncnn.py --run 1
script_install:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install mmdeploy
run: |
python3 tools/scripts/build_ubuntu_x64_ncnn.py
python3 -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu
python3 -m pip install mmcv-full==1.5.1 -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8.0/index.html
python3 -c 'import mmdeploy.apis.ncnn as ncnn_api; assert ncnn_api.is_available() and ncnn_api.is_custom_ops_available()'
39 changes: 39 additions & 0 deletions .github/workflows/backend-ort.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: backend-ort

on:
push:
paths-ignore:
- "demo/**"
- "tools/**"

pull_request:
paths-ignore:
- "demo/**"
- "tools/**"
- "docs/**"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
script_install:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install mmdeploy
run: |
python3 tools/scripts/build_ubuntu_x64_ort.py
python3 -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu
python3 -m pip install mmcv-full==1.5.1 -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8.0/index.html
python3 -c 'import mmdeploy.apis.onnxruntime as ort_api; assert ort_api.is_available() and ort_api.is_custom_ops_available()'
39 changes: 39 additions & 0 deletions .github/workflows/backend-pplnn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: backend-pplnn

on:
push:
paths-ignore:
- "demo/**"
- "tools/**"

pull_request:
paths-ignore:
- "demo/**"
- "tools/**"
- "docs/**"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
script_install:
runs-on: ubuntu-18.04
strategy:
matrix:
python-version: [3.7]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install mmdeploy
run: |
python3 tools/scripts/build_ubuntu_x64_pplnn.py
python3 -m pip install torch==1.8.2 torchvision==0.9.2 --extra-index-url https://download.pytorch.org/whl/lts/1.8/cpu
python3 -m pip install mmcv-full==1.5.1 -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8.0/index.html
python3 -c 'import mmdeploy.apis.pplnn as pplnn_api; assert pplnn_api.is_available()'
36 changes: 36 additions & 0 deletions .github/workflows/backend-torchscript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: backend-ort

on:
push:
paths-ignore:
- "demo/**"
- "tools/**"

pull_request:
paths-ignore:
- "demo/**"
- "tools/**"
- "docs/**"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
script_install:
runs-on: ubuntu-18.04
strategy:
matrix:
python-version: [3.7]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install mmdeploy
run: |
python3 tools/scripts/build_ubuntu_x64_torchscript.py
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Please read [getting_started](docs/en/get_started.md) for the basic usage of MMD

- [Build](docs/en/01-how-to-build/build_from_source.md)
- [Build from Docker](docs/en/01-how-to-build/build_from_docker.md)
- [Build from Script](docs/en/01-how-to-build/build_from_script.md)
- [Build for Linux](docs/en/01-how-to-build/linux-x86_64.md)
- [Build for Win10](docs/en/01-how-to-build/windows.md)
- [Build for Android](docs/en/01-how-to-build/android.md)
Expand Down
1 change: 1 addition & 0 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ MMDeploy 是 [OpenMMLab](https://openmmlab.com/) 模型部署工具箱,**为

- [快速上手](docs/zh_cn/get_started.md)
- [编译](docs/zh_cn/01-how-to-build/build_from_source.md)
- [一键式脚本安装](docs/zh_cn/01-how-to-build/build_from_script.md)
- [Build from Docker](docs/zh_cn/01-how-to-build/build_from_docker.md)
- [Build for Linux](docs/zh_cn/01-how-to-build/linux-x86_64.md)
- [Build for Win10](docs/zh_cn/01-how-to-build/windows.md)
Expand Down
31 changes: 31 additions & 0 deletions docs/en/01-how-to-build/build_from_script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Build from Script

Through user investigation, we know that most users are already familiar with python and torch before using mmdeploy. Therefore we provide scripts to simplify mmdeploy installation.

Assuming you have a python ready (whether `conda` or `pyenv`), run this script to install mmdeploy + ncnn backend, `nproc` is not compulsory.

```bash
$ cd /path/to/mmdeploy
$ python3 tools/scripts/build_ubuntu_x64_ncnn.py $(nproc)
..
```

A sudo password may be required during this time, and the script will try its best to build and install mmdeploy SDK and demo:

- Detect host OS version, `make` job number, whether use `root` and try to fix `python3 -m pip`
- Find the necessary basic tools, such as g++-7, cmake, wget, etc.
- Compile necessary dependencies, such as pyncnn, protobuf

The script will also try to avoid affecting host environment:

- The dependencies of source code compilation are placed in the `mmdeploy-dep` directory at the same level as mmdeploy
- The script would not modify variables such as PATH, LD_LIBRARY_PATH, PYTHONPATH, etc.

Here is the verified installation script. If you want mmdeploy to support multiple backends at the same time, you can execute each script once:

| script | OS version |
| :-----------------------------: | :---------: |
| build_ubuntu_x64_ncnn.py | 18.04/20.04 |
| build_ubuntu_x64_ort.py | 18.04/20.04 |
| build_ubuntu_x64_pplnn.py | 18.04/20.04 |
| build_ubuntu_x64_torchscript.py | 18.04/20.04 |
2 changes: 1 addition & 1 deletion docs/en/01-how-to-build/build_from_source.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Build From Source
# Build from Source

## Download

Expand Down
18 changes: 18 additions & 0 deletions docs/en/01-how-to-build/linux-x86_64.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,21 @@ You can also activate other engines after the model.
make -j$(nproc) && make install
```

- pplnn

```Bash
cd ${MMDEPLOY_DIR}
mkdir -p build && cd build
cmake .. \
-DCMAKE_CXX_COMPILER=g++-7 \
-DMMDEPLOY_BUILD_SDK=ON \
-DMMDEPLOY_BUILD_EXAMPLES=ON \
-DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \
-DMMDEPLOY_TARGET_DEVICES="cuda;cpu" \
-DMMDEPLOY_TARGET_BACKENDS=pplnn \
-Dpplcv_DIR=${PPLCV_DIR}/cuda-build/cuda-build/install/lib/cmake/ppl \
-Dpplnn_DIR=${PPLNN_DIR}/pplnn-build/install/lib/cmake/ppl
make -j$(nproc) && make install
```
1 change: 1 addition & 0 deletions docs/en/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ You can switch between Chinese and English documents in the lower-left corner of

01-how-to-build/build_from_source.md
01-how-to-build/build_from_docker.md
01-how-to-build/build_from_script.md
01-how-to-build/cmake_option.md

.. toctree::
Expand Down
31 changes: 31 additions & 0 deletions docs/zh_cn/01-how-to-build/build_from_script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 一键式脚本安装

通过用户调研,我们得知多数使用者在了解 mmdeploy 前,已经熟知 python 和 torch 用法。因此我们提供脚本简化 mmdeploy 安装。

假设您已经准备好 Python3.6 pip 以上环境(无论 conda 或 pyenv),运行这个脚本来安装 mmdeploy + ncnn backend,`nproc` 可以不指定。

```bash
$ cd /path/to/mmdeploy
$ python3 tools/scripts/build_ubuntu_x64_ncnn.py $(nproc)
..
```

期间可能需要 sudo 密码,脚本会尽最大努力完成 mmdeploy SDK 和 demo:

- 检测系统版本、make 使用的 job 个数、是否 root 用户,也会自动修复 pip 问题
- 寻找必须的基础工具,如 g++-7、cmake、wget 等
- 编译必须的依赖,如 pyncnn、 protobuf

脚本也会尽量避免影响 host 环境:

- 源码编译的依赖,都放在与 mmdeploy 同级的 `mmdeploy-dep` 目录中
- 不会主动修改 PATH、LD_LIBRARY_PATH、PYTHONPATH 等变量

这是已验证的安装脚本。如果想让 mmdeploy 同时支持多种 backend,每个脚本执行一次即可:

| script | OS version |
| :-----------------------------: | :---------: |
| build_ubuntu_x64_ncnn.py | 18.04/20.04 |
| build_ubuntu_x64_ort.py | 18.04/20.04 |
| build_ubuntu_x64_pplnn.py | 18.04/20.04 |
| build_ubuntu_x64_torchscript.py | 18.04/20.04 |
4 changes: 2 additions & 2 deletions docs/zh_cn/01-how-to-build/build_from_source.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 源码安装
# 源码手动安装

如果环境允许(网络良好且宿主机强劲),我们建议使用 [docker 方式](build_from_docker.md)
如果网络良好,我们建议使用 [docker](build_from_docker.md) [一键式脚本](build_from_script.md) 方式

## 下载

Expand Down
18 changes: 18 additions & 0 deletions docs/zh_cn/01-how-to-build/linux-x86_64.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,21 @@ pip install -e .
make -j$(nproc) && make install
```

- pplnn

```Bash
cd ${MMDEPLOY_DIR}
mkdir -p build && cd build
cmake .. \
-DCMAKE_CXX_COMPILER=g++-7 \
-DMMDEPLOY_BUILD_SDK=ON \
-DMMDEPLOY_BUILD_EXAMPLES=ON \
-DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \
-DMMDEPLOY_TARGET_DEVICES="cuda;cpu" \
-DMMDEPLOY_TARGET_BACKENDS=pplnn \
-Dpplcv_DIR=${PPLCV_DIR}/cuda-build/cuda-build/install/lib/cmake/ppl \
-Dpplnn_DIR=${PPLNN_DIR}/pplnn-build/install/lib/cmake/ppl
make -j$(nproc) && make install
```
1 change: 1 addition & 0 deletions docs/zh_cn/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

01-how-to-build/build_from_source.md
01-how-to-build/build_from_docker.md
01-how-to-build/build_from_script.md
01-how-to-build/cmake_option.md

.. toctree::
Expand Down
Loading

0 comments on commit 4534598

Please sign in to comment.