inisis / OnnxSlim

A Toolkit to Help Optimize Onnx Model
MIT License
71 stars 8 forks source link

[Bug] OnnxSlim BUG #30

Open WangHHY19931001 opened 1 day ago

WangHHY19931001 commented 1 day ago

ocr.zip

in package, onnx_run_mod.py is start point 2.3\ppocr\en_number_mobile_v2.0_rec_infer.onnx is src onnx 2.3\ppocr\en_number_mobile_v2.0_rec_infer_onnxoptimizer.onnx is after onnxoptimizer onnx 2.3\ppocr\en_number_mobile_v2.0_rec_infer_onnxslim.onnx is after onnxslim onnx

onnx_run_mod.py use src onnx is work, use after onnxoptimizer onnx is work, but use after onnxslim onnx it not work

WangHHY19931001 commented 1 day ago

pip list Package Version


absl-py 2.1.0 aiohappyeyeballs 2.4.2 aiohttp 3.10.8 aiosignal 1.3.1 albucore 0.0.17 albumentations 1.4.16 annotated-types 0.7.0 async-timeout 4.0.3 attrs 24.2.0 build 1.2.2 certifi 2024.8.30 charset-normalizer 3.3.2 click 8.1.7 cnocr 2.3.0.3 cnstd 1.2.4.2 colorama 0.4.6 coloredlogs 15.0.1 contourpy 1.3.0 cycler 0.12.1 datasets 3.0.1 dill 0.3.8 docker-pycreds 0.4.0 eval_type_backport 0.2.0 exceptiongroup 1.2.2 filelock 3.16.1 flatbuffers 24.3.25 fonttools 4.54.1 frozenlist 1.4.1 fsspec 2024.6.1 gitdb 4.0.11 GitPython 3.1.43 h5py 3.12.1 huggingface-hub 0.25.1 humanfriendly 10.0 idna 3.10 imageio 2.35.1 iniconfig 2.0.0 Jinja2 3.1.4 keras 3.5.0 Keras-Preprocessing 1.1.2 kiwisolver 1.4.7 lazy_loader 0.4 lightning-utilities 0.11.7 markdown-it-py 3.0.0 MarkupSafe 2.1.5 matplotlib 3.9.2 mdurl 0.1.2 ml_dtypes 0.5.0 mpmath 1.3.0 multidict 6.1.0 multiprocess 0.70.16 namex 0.0.8 ncnn 1.0.20240820 networkx 3.3 numpy 1.26.4 onnx 1.16.2 onnxoptimizer 0.3.13 onnxruntime 1.19.2 onnxslim 0.1.35 opencv-python 4.10.0.84 opencv-python-headless 4.10.0.84 optree 0.12.1 packaging 24.1 pandas 2.2.3 pillow 10.4.0 pip 24.2 pip-tools 7.4.1 platformdirs 4.3.6 pluggy 1.5.0 pnnx 20240819 Polygon3 3.0.9.1 portalocker 2.10.1 protobuf 5.28.2 psutil 6.0.0 py-cpuinfo 9.0.0 pyarrow 17.0.0 pyclipper 1.3.0.post5 pydantic 2.9.2 pydantic_core 2.23.4 Pygments 2.18.0 pyparsing 3.1.4 pyproject_hooks 1.1.0 pyreadline3 3.5.4 pytest 8.3.3 python-dateutil 2.9.0.post0 pytorch-lightning 2.4.0 pytz 2024.2 pywin32 308 PyYAML 6.0.2 requests 2.32.3 rich 13.8.1 scikit-image 0.24.0 scipy 1.14.1 seaborn 0.13.2 sentry-sdk 2.14.0 setproctitle 1.3.3 setuptools 75.1.0 shapely 2.0.6 six 1.16.0 smmap 5.0.1 sympy 1.13.3 tifffile 2024.9.20 tomli 2.0.1 torch 2.4.1 torchmetrics 1.4.2 torchvision 0.19.1 tqdm 4.66.5 typing_extensions 4.12.2 tzdata 2024.2 ultralytics 8.2.103 ultralytics-thop 2.0.8 Unidecode 1.3.8 urllib3 2.2.3 wandb 0.18.2 wheel 0.44.0 xxhash 3.5.0 yarl 1.13.1

WangHHY19931001 commented 1 day ago

python --version Python 3.10.14

inisis commented 1 day ago

It seems some optimization passes produce wrong graph

image

inisis commented 7 hours ago

The root cause for this case it that when comparing LazyValues, I only take tensor.raw_data, this is a bug, see here https://github.com/inisis/OnnxSlim/blob/v0.1.35/onnxslim/third_party/onnx_graphsurgeon/ir/tensor.py#L318 so, the way to solve this problem is to compare tensor.

inisis commented 2 hours ago

see https://github.com/inisis/OnnxSlim/commit/d2e09c33d0de077c6fba426723f7bc09d20c9b60, however this is not the best solution, because the performance degrade, still have to find the root