Python Builder API doesn't work for conv3d

Description

The tensorrt.IConvolutionLayer in Python builder API doesn’t work for Conv3d, because stride and padding can’t be 3d (type is DimsHW, so must be 2d)

Environment

TensorRT Version: 8.6.1
Python Version (if applicable): 3.8

Relevant Files

Please attach or include links to any models, data, files, or scripts necessary to reproduce your issue. (Github repo, Google Drive, Dropbox, etc.)

Steps To Reproduce

Run the script below and it will fail at the last line.

import tensorrt as trt

EXPLICIT_BATCH = 1 << (int)(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH)

trt_logger = trt.Logger(trt.Logger.VERBOSE)
builder = trt.Builder(trt_logger)

network = builder.create_network(EXPLICIT_BATCH)
input = network.add_input(name="input", shape=(1, 32, 10, 10, 10), dtype=trt.float32)
conv3d = network.add_convolution_nd(
    input, 32, [3, 3, 3], np.ones((32, 32, 3, 3, 3), dtype=np.float32))
conv3d.padding = (1, 1, 1) # fail

Hi,

It appears that you are passing the incorrect type of data to ‘conv3d.padding,’ which requires input of ‘DimsHW’.

Please refer to the following document for more information.
https://docs.nvidia.com/deeplearning/tensorrt/api/python_api/infer/Graph/Layers.html#tensorrt.IConvolutionLayer

Thank you.

Yes, I also tried changing that line to

conv3d.padding = (1, 1)

and I got error like this:

[09/21/2023-09:50:37] [TRT] [E] 2: [helpers.h::getNbSpatialDims<nvinfer1::ConvolutionParameters>::106] Error Code 2: Internal Error (Assertion isNbDimsEq({params.kernelSize, params.prePadding, params.postPadding, params.stride, params.dilation}) failed. )
[09/21/2023-09:50:37] [TRT] [E] 4: (Unnamed Layer* 0) [Convolution]: number of dimensions in kernel (3), pre-padding (2), post-padding (2), strides(3), and dilation (3) do not match
[09/21/2023-09:50:37] [TRT] [E] 4: [network.cpp::validate::3121] Error Code 4: Internal Error (Layer (Unnamed Layer* 0) [Convolution] failed validation)

Hi,
Below link might help you with your query, Kindly check below link for all 3d support layers:

Thanks!

I have verified the same Conv3D works in C++ API. So I believe this is a bug on Python API.

Hi,

Could you please make sure, you are using the TensorRT version 8.6.1.
We are unable to reproduce the error, script is running successfully with a warning.

# python test.py
[09/29/2023-13:03:37] [TRT] [I] [MemUsageChange] Init CUDA: CPU +15, GPU +0, now: CPU 27, GPU 310 (MiB)
[09/29/2023-13:03:37] [TRT] [V] Trying to load shared library libnvinfer_builder_resource.so.8.6.1
[09/29/2023-13:03:37] [TRT] [V] Loaded shared library libnvinfer_builder_resource.so.8.6.1
[09/29/2023-13:03:43] [TRT] [I] [MemUsageChange] Init builder kernel library: CPU +424, GPU +74, now: CPU 528, GPU 384 (MiB)
[09/29/2023-13:03:43] [TRT] [V] CUDA lazy loading is enabled.
/my_data/266808/test.py:12: DeprecationWarning: Use padding_nd instead.
  conv3d.padding = (1, 1) # fail
PASS - End of Script

On replacing the conv3d.padding = (1, 1) with conv3d.padding_nd = (1, 1)

# python test.py
[09/29/2023-13:05:45] [TRT] [I] [MemUsageChange] Init CUDA: CPU +15, GPU +0, now: CPU 27, GPU 310 (MiB)
[09/29/2023-13:05:45] [TRT] [V] Trying to load shared library libnvinfer_builder_resource.so.8.6.1
[09/29/2023-13:05:45] [TRT] [V] Loaded shared library libnvinfer_builder_resource.so.8.6.1
[09/29/2023-13:05:51] [TRT] [I] [MemUsageChange] Init builder kernel library: CPU +424, GPU +74, now: CPU 528, GPU 384 (MiB)
[09/29/2023-13:05:51] [TRT] [V] CUDA lazy loading is enabled.
PASS - End of Script

Thank you.

Using padding_nd works for me, thanks!

I just realized that padding_nd is at the bottom of this section, so I missed it. It would be useful to add to the description of padding that there is padding_nd below if the padding is not 2d.