NVIDIA-AI-IOT / torch2trt

An easy to use PyTorch to TensorRT converter
MIT License
4.62k stars 677 forks source link

bindings[0] exceed min ~ max range at index 3 #859

Open jihad-akl opened 1 year ago

jihad-akl commented 1 year ago

I converted a torch model with multiple input but it is not working

input_shape = (1, 3 , 32, 96) input_tensor = torch.ones(input_shape).cuda() print("creating engine") engine = torch2trt(self.net, [input_tensor], min_shape= [(1, 3, 32, 32)],max_shape= [(1, 3, 960, 960)],fp16_mode= True) print("engine done") torch.save(engine.state_dict(), 'model.pth')

the model is created but in inference if i give a shape other than (1, 3 , 32, 96) i get an error:

[05/05/2023-07:45:37] [TRT] [E] 3: [executionContext.cpp::setBindingDimensions::966] Error Code 3: API Usage Error (Parameter check failed at: runtime/api/executionContext.cpp::setBindingDimensions::966, condition: profileMinDims.d[i] <= dimensions.d[i]. Supplied binding dimension [1,3,32,64] for bindings[0] exceed min ~ max range at index 3, maximum dimension in profile is 96, minimum dimension in profile is 96, but supplied dimension is 64.

jihad-akl commented 1 year ago

Update: putting s to min_shape and max_shape it result to an error:

creating engine /opt/conda/lib/python3.8/site-packages/torch/nn/functional.py:3728: UserWarning: nn.functional.upsample is deprecated. Use nn.functional.interpolate instead. warnings.warn("nn.functional.upsample is deprecated. Use nn.functional.interpolate instead.") [05/05/2023-11:29:34] [TRT] [E] 3: [network.cpp::addPoolingNd::1025] Error Code 3: API Usage Error (Parameter check failed at: optimizer/api/network.cpp::addPoolingNd::1025, condition: allDimsGtEq(windowSize, 1) && volume(windowSize) < MAX_KERNEL_DIMS_PRODUCT(nbSpatialDims) ) Traceback (most recent call last): File "test_to_ocr_torch_tensorrt.py", line 10, in model = TextSystem(args=ModelArgs(det_model_path=det_model_path, use_gpu=True, File "/test/PytorchOCR/text_system.py", line 16, in init self.text_detector = TextDetector(args, kwargs) File "/test/PytorchOCR/text_detector.py", line 270, in init engine = torch2trt(self.net, [input_tensor], min_shapes= [(1, 3, 32, 32)], max_shapes= [(1, 3, 960, 960)],fp8_mode= True) File "/opt/conda/lib/python3.8/site-packages/torch2trt-0.4.0-py3.8.egg/torch2trt/torch2trt.py", line 778, in torch2trt outputs = module(inputs) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1204, in _call_impl result = forward_call(input, kwargs) File "/test/PytorchOCR/modeling/architectures/base_model.py", line 88, in forward x = self.neck(x) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1204, in _call_impl result = forward_call(*input, kwargs) File "/test/PytorchOCR/modeling/necks/db_fpn.py", line 214, in forward in5 = self.ins_conv3 File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1204, in _call_impl result = forward_call(*input, *kwargs) File "/test/PytorchOCR/modeling/necks/db_fpn.py", line 184, in forward out = x + self.se_block(x) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1204, in _call_impl result = forward_call(input, kwargs) File "/test/PytorchOCR/modeling/backbones/det_mobilenet_v3.py", line 71, in forward outputs = self.avg_pool(inputs) File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1204, in _call_impl result = forward_call(*input, **kwargs) File "/opt/conda/lib/python3.8/site-packages/torch2trt-0.4.0-py3.8.egg/torch2trt/torch2trt.py", line 310, in wrapper converter"converter" File "/opt/conda/lib/python3.8/site-packages/torch2trt-0.4.0-py3.8.egg/torch2trt/converters/AdaptiveAvgPool2d.py", line 22, in convert_AdaptiveAvgPool2d layer.stride = stride AttributeError: 'NoneType' object has no attribute 'stride'

vjixy commented 1 year ago

I am facing the same issue