Open przybyszewskiw opened 4 years ago
Hi @przybyszewskiw,
Thanks for sharing this issue.
There is an experimental PR to support adding custom converters for user defined methods.
https://github.com/NVIDIA-AI-IOT/torch2trt/pull/175
Because the grid map seems to be constant for a given image shape, I'm curious if this would help here.
For example,
def convert_example(ctx):
module = ctx.method_args[0]
feature_map = ctx.method_args[1]
grid_size = feature_map.shape[-2:]
# ... (insert TensorRT code to add grid as constant)
output = ctx.method_return
output._trt = # ... set output _trt attribute to constant
class Example(nn.Module):
@tensorrt_method(convert_example)
def forward(self, feature_map):
# ...
Please let me know if this helps or you run into any issues.
Best, John
Got the similar error here:
TypeError: add_constant(): incompatible function arguments. The following argument types are supported:
1. (self: tensorrt.tensorrt.INetworkDefinition, shape: tensorrt.tensorrt.Dims, weights: tensorrt.tensorrt.Weights) -> tensorrt.tensorrt.IConstantLayer
Invoked with: <tensorrt.tensorrt.INetworkDefinition object at 0x7fa66bc4aca8>, (336,), array([ 0 ..... 335])
I think mine is caused by the unsupported function torch.arange since it shows
Warning: Encountered known unsupported method torch.arange
Hello, I also faced the same problem. Did you able to solve it?
File "/media/duygu/3a331d5c-a3b3-468b-b8f7-06df52fefee6/ocakirog/tensorrt_local/torch2trt/torch2trt/torch2trt.py", line 364, in wrapper
ret = attr(*args, **kwargs)
TypeError: add_constant(): incompatible function arguments. The following argument types are supported:
1. (self: tensorrt.tensorrt.INetworkDefinition, shape: tensorrt.tensorrt.Dims, weights: tensorrt.tensorrt.Weights) -> tensorrt.tensorrt.IConstantLayer
For me, it was this line which induced the error.
File "/home/xxx/python3.8/site-packages/torch/nn/modules/batchnorm.py", line 147, in forward
self.num_batches_tracked = self.num_batches_tracked + 1 # type: ignore[has-type]
It doesn't make sense that tensorrt doesn't support batchnorm.
Then I realized that I forgot to call model.eval()
.
For the following code:
I get an error:
I'm using
PyTorch
version 1.6.0a0+9907a3e andTensorRT
7.1.2-1+cuda11.0. I was tryingtorch2trt
both with and without plugins.