Skip to content

Commit 8b04dd6

Browse files
AndyLiu93RunningLeon
authored andcommitted
[Featuure] Support Vacc Backend (open-mmlab#1679)
* [Enhancement] Support vacc backend * update vacc wrapper * vacc docs * update vacc docs and remove some comments * update vacc backend configs * get vacc_det real output * Fix vacc: pre-commit run * fix pre-commit * update vacc quantize * update vacc docs. * update vacc docs. * [Fix]vacc wrapper and support set calib_num * add vacc_seg model_type * update vacc_det type * update vacc_det type * fix typo * [Fix] some typo * feats: update mmseg vacc sample * feats: update mmseg vacc sample * feats: update mmdet vacc sample * feats: update vacc quant_dataset func. * update vacc wrapper exit-code * update vacc segmentor setting * update vacc seg base_decode_head rewriter * fix vacc wrapper outputs
1 parent 413cc76 commit 8b04dd6

23 files changed

+1156
-4
lines changed

configs/_base_/backends/vacc.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
backend_config = dict(
2+
type='vacc',
3+
common_config=dict(name='end2end'),
4+
model_inputs=[
5+
dict(
6+
shape=dict(input=[1, 3, 224, 224]),
7+
qconfig=dict(
8+
dtype='fp16',
9+
calibrate_mode='percentile',
10+
weight_scale='max',
11+
data_transmode=1,
12+
per_channel=False,
13+
cluster_mode=0,
14+
skip_conv_layers=[],
15+
calib_num=1000,
16+
))
17+
])
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
_base_ = ['./classification_static.py', '../_base_/backends/vacc.py']
2+
3+
backend_config = dict(
4+
common_config=dict(
5+
vdsp_params_info=dict(
6+
vdsp_op_type=300,
7+
iimage_format=5000,
8+
iimage_width=256,
9+
iimage_height=256,
10+
iimage_width_pitch=256,
11+
iimage_height_pitch=256,
12+
short_edge_threshold=256,
13+
resize_type=1,
14+
color_cvt_code=2,
15+
color_space=0,
16+
crop_size=224,
17+
meanr=22459,
18+
meang=22340,
19+
meanb=22136,
20+
stdr=21325,
21+
stdg=21284,
22+
stdb=21292,
23+
norma_type=3)),
24+
model_inputs=[
25+
dict(shape=dict(input=[1, 3, 224, 224]), qconfig=dict(dtype='fp16'))
26+
])
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
_base_ = ['./classification_static.py', '../_base_/backends/vacc.py']
2+
3+
backend_config = dict(model_inputs=[
4+
dict(shape=dict(input=[1, 3, 224, 224]), qconfig=dict(dtype='int8'))
5+
])
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
_base_ = ['../_base_/base_static.py', '../../_base_/backends/vacc.py']
2+
3+
onnx_config = dict(input_shape=[416, 416])
4+
5+
backend_config = dict(
6+
common_config=dict(
7+
vdsp_params_info=dict(
8+
vdsp_op_type=303,
9+
iimage_format=5000,
10+
iimage_width=640,
11+
iimage_height=640,
12+
oimage_width=416,
13+
oimage_height=416,
14+
iimage_width_pitch=640,
15+
iimage_height_pitch=640,
16+
resize_type=1,
17+
color_cvt_code=2,
18+
color_space=0,
19+
padding_value_r=114,
20+
padding_value_g=114,
21+
padding_value_b=114,
22+
edge_padding_type=0,
23+
meanr=0,
24+
meang=0,
25+
meanb=0,
26+
stdr=23544,
27+
stdg=23544,
28+
stdb=23544,
29+
norma_type=3)),
30+
model_inputs=[
31+
dict(shape=dict(input=[1, 3, 416, 416]), qconfig=dict(dtype='fp16'))
32+
])
33+
34+
partition_config = dict(
35+
type='vacc_det',
36+
apply_marks=True,
37+
partition_cfg=[
38+
dict(
39+
save_file='model.onnx',
40+
start=['detector_forward:input'],
41+
end=['yolo_head:input'],
42+
output_names=[f'pred_maps.{i}' for i in range(3)])
43+
])
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
_base_ = ['../_base_/base_static.py', '../../_base_/backends/vacc.py']
2+
3+
onnx_config = dict(input_shape=[416, 416])
4+
5+
backend_config = dict(model_inputs=[
6+
dict(shape=dict(input=[1, 3, 416, 416]), qconfig=dict(dtype='int8'))
7+
])
8+
9+
partition_config = dict(
10+
type='vacc_det',
11+
apply_marks=True,
12+
partition_cfg=[
13+
dict(
14+
save_file='model.onnx',
15+
start=['detector_forward:input'],
16+
end=['yolo_head:input'],
17+
output_names=[f'pred_maps.{i}' for i in range(3)])
18+
])
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
_base_ = ['./segmentation_static.py', '../_base_/backends/vacc.py']
2+
3+
onnx_config = dict(input_shape=[512, 512])
4+
5+
backend_config = dict(
6+
common_config=dict(
7+
vdsp_params_info=dict(
8+
vdsp_op_type=301,
9+
iimage_format=5000,
10+
iimage_width=512,
11+
iimage_height=512,
12+
oimage_width=512,
13+
oimage_height=512,
14+
iimage_width_pitch=512,
15+
iimage_height_pitch=512,
16+
resize_type=1,
17+
color_cvt_code=2,
18+
color_space=0,
19+
meanr=22459,
20+
meang=22340,
21+
meanb=22136,
22+
stdr=21325,
23+
stdg=21284,
24+
stdb=21292,
25+
norma_type=3)),
26+
model_inputs=[dict(shape=dict(input=[1, 3, 512, 512]))])
27+
28+
codebase_config = dict(model_type='vacc_seg')
29+
30+
partition_config = dict(
31+
type='vacc_seg',
32+
apply_marks=True,
33+
partition_cfg=[
34+
dict(
35+
save_file='model.onnx',
36+
start=['segmentor_forward:output'],
37+
# 'decode_head' will skip `ArgMax`
38+
# 'seg_maps' will skip `Resize` and `ArgMax`
39+
end=['decode_head:input'],
40+
output_names=['feat'])
41+
])
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
_base_ = ['./segmentation_static.py', '../_base_/backends/vacc.py']
2+
3+
onnx_config = dict(input_shape=[512, 512])
4+
5+
backend_config = dict(model_inputs=[
6+
dict(shape=dict(input=[1, 3, 512, 512]), qconfig=dict(dtype='int8'))
7+
])
8+
9+
partition_config = dict(
10+
type='vacc_seg',
11+
apply_marks=True,
12+
partition_cfg=[
13+
dict(
14+
save_file='model.onnx',
15+
start=['segmentor_forward:output'],
16+
# 'decode_head' will skip `ArgMax`
17+
# 'seg_maps' will skip `Resize` and `ArgMax`
18+
end=['decode_head:input'],
19+
output_names=['feat'])
20+
])

docs/en/05-supported-backends/vacc.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# VACC Backend
2+
3+
- cmake 3.10.0+
4+
- gcc/g++ 7.5.0
5+
- llvm 9.0.1
6+
- ubuntu 18.04
7+
8+
## PCIE
9+
10+
### 1.package
11+
12+
- dkms (>=1.95)
13+
- linux-headers
14+
- dpkg (Ubuntu)
15+
- rpm (CentOS)
16+
- python2
17+
- python3
18+
19+
Check if there is a vacc card:`lspci -d:0100`
20+
21+
1. Requirements
22+
23+
```bash
24+
sudo apt-get install dkms dpkg python2 python3
25+
```
26+
27+
2. install driver
28+
29+
```bash
30+
sudo dpkg -i vastai-pci_xx.xx.xx.xx_xx.deb
31+
```
32+
33+
3. Verify installation
34+
35+
```bash
36+
dpkg --status vastai-pci-xxx
37+
38+
#output
39+
Package: vastai-pci-dkms
40+
Status: install ok installed
41+
……
42+
Version: xx.xx.xx.xx
43+
Provides: vastai-pci-modules (= xx.xx.xx.xx)
44+
Depends: dkms (>= 1.95)
45+
Description: vastai-pci driver in DKMS format.
46+
47+
lsmod | grep vastai_pci
48+
49+
#output
50+
vastai_pci xxx x
51+
```
52+
53+
4. Upgrade driver
54+
55+
```bash
56+
sudo dpkg -i vastai-pci_dkms_xx.xx.xx.xx_xx.deb
57+
```
58+
59+
5. Uninstall driver
60+
61+
```bash
62+
sudo dpkg -r vastai-pci_dkms_xx.xx.xx.xx_xx
63+
```
64+
65+
### 2.reboot pcie
66+
67+
```bash
68+
sudo chmod 666 /dev/kchar:0 && sudo echo reboot > /dev/kchar:0
69+
```
70+
71+
## SDK
72+
73+
### step.1
74+
75+
```bash
76+
pip install torch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0
77+
pip install onnx==1.10.0 tqdm==4.64.1
78+
pip install h5py==3.8.0
79+
pip install decorator==5.1.1 scipy==1.7.3
80+
```
81+
82+
### step.2
83+
84+
```bash
85+
sudo vi ~/.bashrc
86+
87+
export VASTSTREAM_PIPELINE=true
88+
export VACC_IRTEXT_ENABLE=1
89+
export TVM_HOME="/opt/vastai/vaststream/tvm"
90+
export VASTSTREAM_HOME="/opt/vastai/vaststream/vacl"
91+
export LD_LIBRARY_PATH=$TVM_HOME/lib:$VASTSTREAM_HOME/lib
92+
export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/vacc/python:$TVM_HOME/topi/python:${PYTHONPATH}:$VASTSTREAM_HOME/python
93+
94+
source ~/.bashrc
95+
```
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# VACC Backend
2+
3+
- cmake 3.10.0+
4+
- gcc/g++ 7.5.0
5+
- llvm 9.0.1
6+
- ubuntu 18.04
7+
8+
## PCIE
9+
10+
### 1.package
11+
12+
- dkms (>=1.95)
13+
- linux-headers
14+
- dpkg (Ubuntu)
15+
- rpm (CentOS)
16+
- python2
17+
- python3
18+
19+
查看是否有瀚博推理卡:`lspci -d:0100`
20+
21+
1. 环境准备
22+
23+
```bash
24+
sudo apt-get install dkms dpkg python2 python3
25+
```
26+
27+
2. driver安装
28+
29+
```bash
30+
sudo dpkg -i vastai-pci_xx.xx.xx.xx_xx.deb
31+
```
32+
33+
3. 查看安装
34+
35+
```bash
36+
# 1.查看deb包是否安装成功
37+
dpkg --status vastai-pci-xxx
38+
39+
#output
40+
Package: vastai-pci-dkms
41+
Status: install ok installed
42+
……
43+
Version: xx.xx.xx.xx
44+
Provides: vastai-pci-modules (= xx.xx.xx.xx)
45+
Depends: dkms (>= 1.95)
46+
Description: vastai-pci driver in DKMS format.
47+
48+
# 2.查看驱动是否已加载到内核
49+
lsmod | grep vastai_pci
50+
51+
#output
52+
vastai_pci xxx x
53+
```
54+
55+
4. 升级驱动
56+
57+
```bash
58+
sudo dpkg -i vastai-pci_dkms_xx.xx.xx.xx_xx.deb
59+
```
60+
61+
5. 卸载驱动
62+
63+
```bash
64+
sudo dpkg -r vastai-pci_dkms_xx.xx.xx.xx_xx
65+
```
66+
67+
### 2.reboot pcie
68+
69+
```bash
70+
sudo chmod 666 /dev/kchar:0 && sudo echo reboot > /dev/kchar:0
71+
```
72+
73+
## SDK
74+
75+
### step.1
76+
77+
```bash
78+
pip install torch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0
79+
pip install onnx==1.10.0 tqdm==4.64.1
80+
pip install h5py==3.8.0
81+
pip install decorator==5.1.1 scipy==1.7.3
82+
```
83+
84+
### step.2
85+
86+
```bash
87+
sudo vi ~/.bashrc
88+
89+
export VASTSTREAM_PIPELINE=true
90+
export VACC_IRTEXT_ENABLE=1
91+
export TVM_HOME="/opt/vastai/vaststream/tvm"
92+
export VASTSTREAM_HOME="/opt/vastai/vaststream/vacl"
93+
export LD_LIBRARY_PATH=$TVM_HOME/lib:$VASTSTREAM_HOME/lib
94+
export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/vacc/python:$TVM_HOME/topi/python:${PYTHONPATH}:$VASTSTREAM_HOME/python
95+
96+
source ~/.bashrc
97+
```

mmdeploy/apis/vacc/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) OpenMMLab. All rights reserved.
2+
from mmdeploy.backend.vacc import is_available
3+
from ..core import PIPELINE_MANAGER
4+
5+
__all__ = ['is_available']
6+
7+
if is_available():
8+
try:
9+
from mmdeploy.backend.vacc import from_onnx as _from_onnx
10+
from_onnx = PIPELINE_MANAGER.register_pipeline()(_from_onnx)
11+
__all__ += ['from_onnx']
12+
except Exception:
13+
pass

0 commit comments

Comments
 (0)