x-stable-diffusion icon indicating copy to clipboard operation
x-stable-diffusion copied to clipboard

AttributeError: module 'numpy' has no attribute 'bool'

Open ClementCJ opened this issue 2 years ago • 2 comments

After got unet.engine, then run "python demo.py", and got the following errors, who know this issue, thanks! (env_py39) [jch@localhost TensorRT]$ python demo.py [12/27/2022-06:37:00] [TRT] [W] The getMaxBatchSize() function should not be used with an engine built from a network created with NetworkDefinitionCreationFlag::kEXPLICIT_BATCH flag. This function will always return 1. /home/jch/anaconda3/envs/env_py39/lib/python3.9/site-packages/tensorrt/init.py:166: FutureWarning: In the future np.bool will be defined as the corresponding NumPy scalar. (This may have returned Python scalars in past versions. bool: np.bool, Traceback (most recent call last): File "/home/jch/work/x-stable-diffusion/TensorRT/demo.py", line 125, in model = TrtDiffusionModel(args) File "/home/jch/work/x-stable-diffusion/TensorRT/demo.py", line 48, in init self.unet = TRTModel(args.trt_unet_save_path) File "/home/jch/work/x-stable-diffusion/TensorRT/trt_model.py", line 41, in init self.inputs, self.outputs, self.bindings, self.stream = self.allocate_buffers( File "/home/jch/work/x-stable-diffusion/TensorRT/trt_model.py", line 79, in allocate_buffers dtype = trt.nptype(engine.get_binding_dtype(binding)) File "/home/jch/anaconda3/envs/env_py39/lib/python3.9/site-packages/tensorrt/init.py", line 166, in nptype bool: np.bool, File "/home/jch/anaconda3/envs/env_py39/lib/python3.9/site-packages/numpy/init.py", line 284, in getattr raise AttributeError("module {!r} has no attribute " AttributeError: module 'numpy' has no attribute 'bool' Segmentation fault

ClementCJ avatar Dec 27 '22 11:12 ClementCJ

Hi @ClementCJ, I think that inputs datatype from TensorRT model may not been supported by TensorRT. Please make sure that inputs are in float32 type. You can print out engine.get_binding_dtype(binding) to see what is data type of the input.

Toan-Do avatar Dec 27 '22 13:12 Toan-Do

@Toan-Do , The reason was found, because numpy==1.24.0, the version is too high. (env_py39) [jch@localhost TensorRT]$ python Python 3.9.15 (main, Nov 24 2022, 14:31:59) [GCC 11.2.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information.

import numpy as np np.version '1.24.0' np.bool :1: FutureWarning: In the future np.bool will be defined as the corresponding NumPy scalar. (This may have returned Python scalars in past versions. Traceback (most recent call last): File "", line 1, in File "/home/jch/anaconda3/envs/env_py39/lib/python3.9/site-packages/numpy/init.py", line 284, in getattr raise AttributeError("module {!r} has no attribute " AttributeError: module 'numpy' has no attribute 'bool'

However, when I downgraded the numpy version to 1.19.0, the python demo.py prompt was executed: (env_py39) [jch@localhost TensorRT]$ python demo.py RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xd . Check the section C-API incompatibility at the Troubleshooting ImportError section at https://numpy.org/devdocs/user/troubleshooting-importerror.html#c-api-incompatibility for indications on how to solve this problem . Traceback (most recent call last): File "/home/jch/work/x-stable-diffusion/TensorRT/demo.py", line 4, in from trt_model import TRTModel File "/home/jch/work/x-stable-diffusion/TensorRT/trt_model.py", line 7, in import pycuda.driver as cuda File "/home/jch/anaconda3/envs/env_py39/lib/python3.9/site-packages/pycuda-2022.2.2-py3.9-linux-x86_64.egg/pycuda/driver.py", line 66, in from pycuda._driver import * # noqa SystemError: initialization of _driver raised unreported exception

So, I upgraded numpy to 1.24.0 again. and modify the file "/home/jch/anaconda3/envs/env_py39/lib/python3.9/site-packages/tensorrt/init.py " line 166. bool: np.bool --> bool: np.bool_

Eventually, the problem is solved.

ClementCJ avatar Dec 28 '22 11:12 ClementCJ