Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: len() should return >= 0 with LPPool2d operator #896

Open
Thrsu opened this issue Nov 27, 2023 · 3 comments
Open

ValueError: len() should return >= 0 with LPPool2d operator #896

Thrsu opened this issue Nov 27, 2023 · 3 comments

Comments

@Thrsu
Copy link

Thrsu commented Nov 27, 2023

Description:

The error message is as below:

Traceback (most recent call last):
  ...
    model_trt = torch2trt(model, [input_data])
  File "/root/miniconda3/envs/nnsmith/lib/python3.9/site-packages/torch2trt-0.4.0-py3.9.egg/torch2trt/torch2trt.py", line 778, in torch2trt
    outputs = module(*inputs)
  File "/root/miniconda3/envs/nnsmith/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/root/miniconda3/envs/nnsmith/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1568, in _call_impl
    result = forward_call(*args, **kwargs)
  File "/root/miniconda3/envs/nnsmith/lib/python3.9/site-packages/torch/nn/modules/pooling.py", line 984, in forward
    return F.lp_pool2d(input, float(self.norm_type), self.kernel_size,
  File "/root/miniconda3/envs/nnsmith/lib/python3.9/site-packages/torch2trt-0.4.0-py3.9.egg/torch2trt/torch2trt.py", line 300, in wrapper
    outputs = method(*args, **kwargs)
  File "/root/miniconda3/envs/nnsmith/lib/python3.9/site-packages/torch/nn/functional.py", line 1042, in lp_pool2d
    return (torch.sign(out) * relu(torch.abs(out))).mul(kw * kh).pow(1.0 / norm_type)
  File "/root/miniconda3/envs/nnsmith/lib/python3.9/site-packages/torch2trt-0.4.0-py3.9.egg/torch2trt/torch2trt.py", line 309, in wrapper
    converter["converter"](ctx)
  File "/root/miniconda3/envs/nnsmith/lib/python3.9/site-packages/torch2trt-0.4.0-py3.9.egg/torch2trt/converters/mul.py", line 15, in convert_mul
    input_a_trt, input_b_trt = broadcast_trt_tensors(ctx.network, [input_a_trt, input_b_trt], len(output.shape))
  File "/root/miniconda3/envs/nnsmith/lib/python3.9/site-packages/torch2trt-0.4.0-py3.9.egg/torch2trt/torch2trt.py", line 193, in broadcast_trt_tensors
    if len(t.shape) < broadcast_ndim:
ValueError: __len__() should return >= 0

Reproduce:

Here is a minimal script to reproduce the issue:

import torch
from torch.nn import Module
from torch2trt import torch2trt

model = torch.nn.LPPool2d(2, 2, 2,).eval().cuda()
input_data = torch.randn([1, 3, 7, 7], dtype=torch.float32).cuda()
model_trt = torch2trt(model, [input_data])

Environment

  • torch: 2.1.1
  • torch2trt: 0.4.0
  • tensorrt: 8.6.1
@farzanehnakhaee70
Copy link

Hi,
Is there any update for this issue?

@hongliyu0716
Copy link

The ReLU6 operator has the same problem, here is the script:

import torch
from torch.nn import Module
from torch2trt import torch2trt

model = torch.nn.ReLU6().eval().cuda()
input_data=torch.randint(1, 100, [4, 10], dtype=torch.uint8).cuda()
model_trt = torch2trt(model, [input_data])

@jikechao
Copy link

jikechao commented Mar 21, 2024

I came across the same issue when using InstanceNorm2d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants