[TensorRT] INTERNAL ERROR: Assertion failed: f != 0 && (f & (f - 1)) == 0
Description
when I convert my onnx model to trt fp16 model, it works, however, when I convert to int8 mode, it raised the following error,
Building an engine from file test.onnx; this may take a while...
[TensorRT] INTERNAL ERROR: Assertion failed: f != 0 && (f & (f - 1)) == 0
../builder/tacticOptimizer.cpp:3523
Aborting...
Any help would be appreciated!
Environment
TensorRT Version: 7.0.0.11 GPU Type: 2080ti Nvidia Driver Version: 430.64 CUDA Version: 10.0 CUDNN Version: 7.6.5 Operating System + Version: ubuntu Python Version (if applicable): 3.6.10 TensorFlow Version (if applicable): PyTorch Version (if applicable): 1.4 Baremetal or Container (if container which image + tag): Container
Relevant Files
class MyCalibrator(trt.IInt8EntropyCalibrator2):
def __init__(self, calibData, cache_file):
# Whenever you specify a custom constructor for a TensorRT class,
# you MUST call the constructor of the parent explicitly.
trt.IInt8EntropyCalibrator2.__init__(self)
self.cache_file = cache_file
# Every time get_batch is called, the next batch of size batch_size will be copied to the device and returned.
self.data = calibData
self.batch_size = 140
self.current_index = 0
# Allocate enough memory for a whole batch.
self.device_input = cuda.mem_alloc(self.data[0].nbytes * self.batch_size)
def get_batch_size(self):
return self.batch_size
# TensorRT passes along the names of the engine bindings to the get_batch function.
# You don't necessarily have to use them, but they can be useful to understand the order of
# the inputs. The bindings list is expected to have the same ordering as 'names'.
def get_batch(self, names):
if self.current_index + self.batch_size > self.data.shape[0]:
return None
current_batch = int(self.current_index / self.batch_size)
if current_batch % 10 == 0:
print("Calibrating batch {:}, containing {:} images".format(current_batch, self.batch_size))
batch = self.data[self.current_index:self.current_index + self.batch_size].ravel()
cuda.memcpy_htod(self.device_input, batch)
self.current_index += self.batch_size
return [self.device_input]
def read_calibration_cache(self):
# If there is a cache, use it instead of calibrating again. Otherwise, implicitly return None.
if os.path.exists(self.cache_file):
with open(self.cache_file, "rb") as f:
return f.read()
def write_calibration_cache(self, cache):
with open(self.cache_file, "wb") as f:
f.write(cache)
Steps To Reproduce
Hi @xkyi ,
Can you share an ONNX model that reproduces this issue?
Hi @rmccorm4 , the ONNX model is https://drive.google.com/file/d/1KaLNW8l8duyLI0rs7B0vOBRCqGBRpFdl/view?usp=sharing
Hi, @xkyi, I meet the same problem with you. How do you solve the problem? I look forward to hearing from you.