mmdeploy icon indicating copy to clipboard operation
mmdeploy copied to clipboard

[Bug] ImportError: cannot import name 'ts_optimizer' from 'mmdeploy.backend.torchscript'

Open volkov-maxim opened this issue 1 year ago • 0 comments

Checklist

  • [X] I have searched related issues but cannot get the expected help.
  • [X] 2. I have read the FAQ documentation but cannot get the expected help.
  • [X] 3. The bug has not been fixed in the latest version.

Describe the bug

I want to optimize ONNX model but every time I get warning:

02/28 15:49:54 - mmengine - INFO - Execute onnx optimize passes.
02/28 15:49:54 - mmengine - WARNING - Can not optimize model, please build torchscipt extension.
More details: https://github.com/open-mmlab/mmdeploy/tree/main/docs/en/experimental/onnx_optimizer.md

After running all commands from instruction I'm still get warning.

Then I "deep dive" in codebase and find that warning raises because ts_optimizer not imported.

Explain me please, what should I do to get optimized ONNX model?

Reproduction

Command for reproduction:

from mmdeploy.backend.torchscript import ts_optimizer

Environment

02/28 16:30:54 - mmengine - INFO - 

02/28 16:30:54 - mmengine - INFO - **********Environmental information**********
02/28 16:30:55 - mmengine - INFO - sys.platform: linux
02/28 16:30:55 - mmengine - INFO - Python: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
02/28 16:30:55 - mmengine - INFO - CUDA available: True
02/28 16:30:55 - mmengine - INFO - numpy_random_seed: 2147483648
02/28 16:30:55 - mmengine - INFO - GPU 0: NVIDIA GeForce GTX 1060 6GB
02/28 16:30:55 - mmengine - INFO - CUDA_HOME: /usr/local/cuda-12.3
02/28 16:30:55 - mmengine - INFO - NVCC: Cuda compilation tools, release 12.3, V12.3.107
02/28 16:30:55 - mmengine - INFO - GCC: x86_64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
02/28 16:30:55 - mmengine - INFO - PyTorch: 2.0.0+cu117
02/28 16:30:55 - mmengine - INFO - PyTorch compiling details: PyTorch built with:
  - GCC 9.3
  - C++ Version: 201703
  - Intel(R) oneAPI Math Kernel Library Version 2022.2-Product Build 20220804 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.7.3 (Git Hash 6dbeffbae1f23cbbeae17adb7b5b13f1f37c080e)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 11.7
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86
  - CuDNN 8.5
  - Magma 2.6.1
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.7, CUDNN_VERSION=8.5.0, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -D_GLIBCXX_USE_CXX11_ABI=0 -fabi-version=11 -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wunused-local-typedefs -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_DISABLE_GPU_ASSERTS=ON, TORCH_VERSION=2.0.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=1, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, 

02/28 16:30:55 - mmengine - INFO - TorchVision: 0.15.1+cu117
02/28 16:30:55 - mmengine - INFO - OpenCV: 4.7.0
02/28 16:30:55 - mmengine - INFO - MMEngine: 0.9.1
02/28 16:30:55 - mmengine - INFO - MMCV: 2.0.1
02/28 16:30:55 - mmengine - INFO - MMCV Compiler: GCC 9.3
02/28 16:30:55 - mmengine - INFO - MMCV CUDA Compiler: 11.7
02/28 16:30:55 - mmengine - INFO - MMDeploy: 1.3.0+fcd7d13
02/28 16:30:55 - mmengine - INFO - 

02/28 16:30:55 - mmengine - INFO - **********Backend information**********
02/28 16:30:55 - mmengine - INFO - tensorrt:	8.6.1
02/28 16:30:55 - mmengine - INFO - tensorrt custom ops:	Available
02/28 16:30:55 - mmengine - INFO - ONNXRuntime:	None
02/28 16:30:55 - mmengine - INFO - pplnn:	None
02/28 16:30:55 - mmengine - INFO - ncnn:	None
02/28 16:30:55 - mmengine - INFO - snpe:	None
02/28 16:30:55 - mmengine - INFO - openvino:	None
02/28 16:30:55 - mmengine - INFO - torchscript:	2.0.0
02/28 16:30:55 - mmengine - INFO - torchscript custom ops:	NotAvailable
02/28 16:30:55 - mmengine - INFO - rknn-toolkit:	None
02/28 16:30:55 - mmengine - INFO - rknn-toolkit2:	None
02/28 16:30:55 - mmengine - INFO - ascend:	None
02/28 16:30:55 - mmengine - INFO - coreml:	None
02/28 16:30:55 - mmengine - INFO - tvm:	None
02/28 16:30:55 - mmengine - INFO - vacc:	None
02/28 16:30:55 - mmengine - INFO - 

02/28 16:30:55 - mmengine - INFO - **********Codebase information**********
02/28 16:30:55 - mmengine - INFO - mmdet:	3.1.0
02/28 16:30:55 - mmengine - INFO - mmseg:	None
02/28 16:30:55 - mmengine - INFO - mmpretrain:	None
02/28 16:30:55 - mmengine - INFO - mmocr:	None
02/28 16:30:55 - mmengine - INFO - mmagic:	None
02/28 16:30:55 - mmengine - INFO - mmdet3d:	None
02/28 16:30:55 - mmengine - INFO - mmpose:	1.1.0
02/28 16:30:55 - mmengine - INFO - mmrotate:	None
02/28 16:30:55 - mmengine - INFO - mmaction:	None
02/28 16:30:55 - mmengine - INFO - mmrazor:	None
02/28 16:30:55 - mmengine - INFO - mmyolo:	None

Error traceback

>>> from mmdeploy.backend.torchscript import ts_optimizer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'ts_optimizer' from 'mmdeploy.backend.torchscript' (/project/lib/python3.10/site-packages/mmdeploy/backend/torchscript/__init__.py)

volkov-maxim avatar Feb 28 '24 13:02 volkov-maxim