NVIDIA-AI-IOT / torch2trt

An easy to use PyTorch to TensorRT converter
MIT License
4.6k stars 675 forks source link

Bug of Linear #191

Closed xieydd closed 4 years ago

xieydd commented 4 years ago

The default of torch2trt Linear input`s shape is [Batch,feature_in], the most of situation is [Batch,*,feature_in] in pytorch api, if add a test in

@add_module_test(torch.float32, torch.device('cuda'), [(1, 10,10)])

it will be a error, i think this is a bug, @jaybdub Can you take a look at it. same error in #161

jaybdub commented 4 years ago

Hi xieydd,

Thanks for sharing!

Yes, I'll take a look soon.

Best, John

jaybdub commented 4 years ago

This is now fixed in this PR (which is merged into master)

https://github.com/NVIDIA-AI-IOT/torch2trt/pull/196

Please try it out and let me know if it works for your use case.

Best, John

ma-siddiqui commented 4 years ago

Thank you very much. Really appreciate it. I cloned the latest repo and run the code. Unfortunately it is throwing exceptions in Linear converter with the below errors. Please have a look. thanks in advance.

[TensorRT] ERROR: (Unnamed Layer* 1168) [Shuffle]: uninferred dimensions are not an exact divisor of input dimensions, so inferred dimension cannot be calculated Traceback (most recent call last): File "python3.7/site-packages/torch2trt/torch2trt.py", line 202, in wrapper converter'converter' File "..python3.7/site-packages/torch2trt/converters/Linear.py", line 9, in convert_Linear inputtrt = trt(ctx.network, input) File "...python3.7/site-packages/torch2trt/torch2trt.py", line 116, in trt_ num_dim = len(t._trt.shape) # non-leaf tensors must already have _trt, get shape from that ValueError: len() should return >= 0 Terminated

ma-siddiqui commented 4 years ago

Also it seems some issue in function { def num_slice_types(slices): }

File "python3.7/site-packages/torch2trt/converters/getitem.py", line 18, in num_slice_types for s in slices: TypeError: 'int' object is not iterable

xieydd commented 4 years ago

@jaybdub It works, thanks a lot.