Skip to content

🐛 [Bug] RuntimeError: required keyword attribute 'to' is undefined #1755

New issue

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

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

Already on GitHub? # to your account

Closed
bowang007 opened this issue Mar 21, 2023 · 0 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@bowang007
Copy link
Collaborator

Bug Description

Run into this error when using Python APIs:

DEBUG: [Torch-TensorRT TorchScript Conversion Context] - Evaluating %3 : int = prim::Constant[value=1]()
Traceback (most recent call last):
  File "add.py", line 41, in <module>
    main()
  File "add.py", line 27, in main
    trt_mod = torch_tensorrt.compile(scripted_model, **compile_settings)
  File "/home/bo/.virtualenvs/my_env/lib/python3.8/site-packages/torch_tensorrt/_compile.py", line 125, in compile
    return torch_tensorrt.ts.compile(
  File "/home/bo/.virtualenvs/my_env/lib/python3.8/site-packages/torch_tensorrt/ts/_compiler.py", line 136, in compile
    compiled_cpp_mod = _C.compile_graph(module._c, _parse_compile_spec(spec))
RuntimeError: required keyword attribute 'to' is undefined

To Reproduce

Every model I tested failed, even for some very small models like :

class Add(torch.nn.Module):

    def __init__(self):
        super(Add, self).__init__()

    def forward(self, x, y):
        return x + y


def main():

    model = Add().eval().cuda()
    scripted_model = torch.jit.script(model)
    torch.jit.save(scripted_model, "add.jit")
    compile_settings = {
        "inputs": [torch_tensorrt.Input([1, 3, 5, 5]), torch_tensorrt.Input([1, 3, 5, 5])],
        "enabled_precisions": {torch.float32},
    }

    trt_mod = torch_tensorrt.compile(scripted_model, **compile_settings)
    # import pdb; pdb.set_trace()
    print("done")
    input_tensor1 = torch.randint(0, 5, (1, 3, 5, 5), dtype=torch.float32).cuda()
    input_tensor2 = torch.randint(0, 5, (1, 3, 5, 5), dtype=torch.float32).cuda()

    norm_trt_ts = torch_tensorrt.compile(model, compile_settings)
    trt_outputs = norm_trt_ts.forward(input_tensor1, input_tensor2)
@bowang007 bowang007 added the bug Something isn't working label Mar 21, 2023
@bowang007 bowang007 self-assigned this Mar 21, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants