pytorch / TensorRT

PyTorch/TorchScript/FX compiler for NVIDIA GPUs using TensorRT
https://pytorch.org/TensorRT
BSD 3-Clause "New" or "Revised" License
2.6k stars 351 forks source link

🐛 [Bug] Encountered bug for nn.LSTM with half dtype #2666

Open johnzlli opened 9 months ago

johnzlli commented 9 months ago

Bug Description

When running the compiled LSTM model for half dtype with torch-tensorrt, I get this errors: RuntimeError: Input and parameter tensors are not the same dtype, found input tensor with Float and parameter tensor with Half

Here is the test code:

import torch
import torch.nn as nn
import torch_tensorrt

class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.relu = nn.ReLU()
        self.lstm = nn.LSTM(800, 800)

    def forward(self, input_x):
        x = self.relu(input_x)
        x = self.lstm(x)[0]
        return x

model = Model().eval().half().cuda()
x = torch.randn(50, 50, 800).half().cuda()
script_model = torch.jit.trace(model, x)
trt_ts_model = torch_tensorrt.compile(script_model, ir="torchscript", inputs=[x], enabled_precisions=[torch.half], truncate_long_and_double=True)
res = trt_ts_model(x)

Expected behavior

Environment

Build information about Torch-TensorRT can be found by turning on debug messages

Additional context

bowang007 commented 8 months ago

This PR might be helpful for type issues: https://github.com/pytorch/TensorRT/pull/2469 However, I would recommend using Dynamo path since which is being actively supported right now. Thanks!

johnzlli commented 8 months ago

This PR might be helpful for type issues: #2469 However, I would recommend using Dynamo path since which is being actively supported right now. Thanks!

Thanks for your reply! It seems that this PR do not fix the issues and the bug is still active.