* fix

* fix

* update

* fix
pull/2070/head
RunningLeon 2023-05-10 15:28:08 +08:00 committed by GitHub
parent 49103cb72e
commit 162f4cbe6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 125 deletions

View File

@ -1,59 +0,0 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os
import subprocess
# list of tuple: onnx filename, download_url and model_config.
CONFIGS = [
[
'hrnet.onnx',
'https://media.githubusercontent.com/media/tpoisonooo/mmdeploy-onnx2ncnn-testdata/main/hrnet.onnx', # noqa: E501
'~/mmpretrain/configs/hrnet/hrnet-w18_4xb32_in1k.py',
],
[
'resnet18.onnx',
'https://media.githubusercontent.com/media/tpoisonooo/mmdeploy-onnx2ncnn-testdata/main/resnet18.onnx', # noqa: E501
'~/mmpretrain/configs/resnet/resnet18_8xb16_cifar10.py',
],
[
'mobilenet-v2.onnx',
'https://media.githubusercontent.com/media/tpoisonooo/mmdeploy-onnx2ncnn-testdata/main/mobilenet-v2.onnx', # noqa: E501
'~/mmpretrain/configs/mobilenet_v2/mobilenet-v2_8xb32_in1k.py',
]
]
def prepare_dataset():
DATASET = (
'dataset',
'https://media.githubusercontent.com/media/tpoisonooo/mmdeploy-onnx2ncnn-testdata/main/dataset.tar' # noqa: E501
) # noqa: E501
os.system('wget {}'.format(DATASET[1]))
os.system('tar xvf dataset.tar')
return DATASET[0]
def main():
"""test `tools/onnx2ncnn_quant_table.py`
First quantize onnx model to ncnn with ppq.
"""
data_dir = prepare_dataset()
for conf in CONFIGS:
model = conf[0]
os.system('wget {}'.format(conf[1]))
model_cfg = conf[2]
deploy_cfg = 'configs/mmpretrain/classification_ncnn-int8_static.py'
quant_cmd = [
'python', 'tools/onnx2ncnn_quant_table.py', '--onnx', model,
'--deploy-cfg', deploy_cfg, '--model-cfg', model_cfg, '--out-onnx',
'quant.onnx', '--out-table', 'ncnn.table', '--image-dir', data_dir
]
print(' '.join(quant_cmd))
print(subprocess.call(quant_cmd))
if __name__ == '__main__':
main()

View File

@ -78,3 +78,58 @@ jobs:
python -m pip install mmcv-lite
python tools/scripts/build_ubuntu_x64_ncnn.py 8
python -c 'import mmdeploy.apis.ncnn as ncnn_api; assert ncnn_api.is_available(with_custom_ops=True)'
test_ncnn_ptq:
runs-on: [self-hosted, linux-3090]
container:
image: openmmlab/mmdeploy:ubuntu20.04-cuda11.3
options: "--gpus=all --ipc=host"
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install dependencies
run: |
apt-get update
apt-get install ninja-build -y
python3 -V
python3 -m pip install openmim
python3 -m pip install -r requirements.txt
python3 -m mim install $(cat requirements/codebases.txt | grep mmpretrain)
python3 -m pip install numpy==1.22.0
python3 -m pip list
- name: Install mmdeploy
run: |
rm -rf .eggs && python3 -m pip install -e .
python3 tools/check_env.py
- name: Install ppq
run: |
git clone -b v0.6.6 --depth 1 https://github.com/openppl-public/ppq
cd ppq
python3 -m pip install -r requirements.txt
python3 setup.py install
- name: Test ncnn + ppq pipeline
run: |
export PYTHONPATH=${PWD}/ppq:${PYTHONPATH}
export LD_LIBRARY_PATH="/root/workspace/mmdeploy/build/lib:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH="/root/workspace/mmdeploy/mmdeploy/lib:${LD_LIBRARY_PATH}"
export work_dir=./work_dir
mkdir -p $work_dir
export model_cfg=$work_dir/resnet18_8xb32_in1k.py
export deploy_cfg=configs/mmpretrain/classification_ncnn-int8_static.py
export checkpoint=$work_dir/resnet18_8xb32_in1k_20210831-fbbb1da6.pth
export input_img=tests/data/tiger.jpeg
python3 -m mim download mmpretrain --config resnet18_8xb32_in1k --dest $work_dir
python3 tools/torch2onnx.py $deploy_cfg $model_cfg $checkpoint $input_img --work-dir $work_dir
wget https://media.githubusercontent.com/media/tpoisonooo/mmdeploy-onnx2ncnn-testdata/main/dataset.tar
tar xvf dataset.tar
python3 tools/onnx2ncnn_quant_table.py \
--onnx $work_dir/end2end.onnx \
--deploy-cfg $deploy_cfg \
--model-cfg $model_cfg \
--out-onnx $work_dir/quant.onnx \
--out-table $work_dir/ncnn.table \
--image-dir ./dataset
ls -sha $work_dir/quant.onnx
cat $work_dir/ncnn.table

View File

@ -48,7 +48,7 @@ jobs:
python -m pip install -r requirements/backends.txt
python -m mim install "mmcv>=2.0.0"
python -m mim install -r requirements/codebases.txt
python -m pip install -U numpy clip numba transformers
python -m pip install clip numba transformers numpy==1.23
python -m pip list
- name: Install mmyolo
run: |

View File

@ -1,65 +0,0 @@
name: quantize
on:
push:
paths-ignore:
- "demo/**"
- "tools/**"
pull_request:
paths-ignore:
- "demo/**"
- "tools/**"
- "docs/**"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test_ncnn_PTQ:
runs-on: ubuntu-20.04
container:
image: pytorch/pytorch:1.8.0-cuda11.1-cudnn8-devel
strategy:
matrix:
torch: [1.8.0+cu111]
include:
- torch: 1.8.0+cu111
torch_version: torch1.8
torchvision: 0.9.0+cu111
steps:
- uses: actions/checkout@v2
- name: Install system dependencies
run: |
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
apt-get update && apt-get install -y wget ffmpeg libsm6 libxext6 git ninja-build libglib2.0-0 libxrender-dev
apt-get clean
rm -rf /var/lib/apt/lists/*
- name: Install PyTorch
run: python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
- name: Install dependencies
run: |
python -V
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -U numpy
- name: Install mmpretrain
run: |
python -m pip install openmim
python -m mim install $(cat requirements/codebases.txt | grep mmpretrain)
git clone --depth 1 --branch 1.x https://github.com/open-mmlab/mmpretrain.git ~/mmpretrain
cd ~/mmpretrain && python -m pip install . && cd -
- name: Install ppq
run: |
python -m pip install protobuf==3.20.0
git clone https://github.com/openppl-public/ppq ~/ppq
cd ~/ppq && git checkout edbecf44c7b203515640e4f4119c000a1b66b33a
python -m pip install -r requirements.txt
python setup.py install
cd -
- name: Run tests
run: |
echo $(pwd)
python .github/scripts/quantize_to_ncnn.py

32
.github/workflows/stale.yml vendored 100644
View File

@ -0,0 +1,32 @@
name: 'Close stale issues and PRs'
on:
schedule:
# check issue and pull request once at 01:30 a.m. every day
- cron: '30 1 * * *'
permissions:
contents: read
jobs:
stale:
permissions:
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v7
with:
stale-issue-message: 'This issue is marked as stale because it has been marked as invalid or awaiting response for 7 days without any further response. It will be closed in 5 days if the stale label is not removed or if there is no further response.'
stale-pr-message: 'This PR is marked as stale because there has been no activity in the past 45 days. It will be closed in 10 days if the stale label is not removed or if there is no further updates.'
close-issue-message: 'This issue is closed because it has been stale for 5 days. Please open a new issue if you have similar issues or you have any new updates now.'
close-pr-message: 'This PR is closed because it has been stale for 10 days. Please reopen this PR if you have any updates and want to keep contributing the code.'
# only issues/PRS with following labels are checked
any-of-labels: 'invalid, awaiting response, duplicate'
days-before-issue-stale: 7
days-before-pr-stale: 45
days-before-issue-close: 5
days-before-pr-close: 10
# automatically remove the stale label when the issues or the pull requests are updated or commented
remove-stale-when-updated: true
operations-per-run: 50