Runtime error - Unsupported value kind: Tensor

I am getting this runtime error while trying to do scripting using torch.jit.script on my initialized and built model.
The error is not giving any more detail or any description of where exactly the issue is.
Any pointer to what might be causing this would be helpful. Thanks!

Could you provide more information to reproduce the error?

I am not sure exactly how to reproduce the error, as I don’t have any clue what might be causing it.
My code base is quite large, multiple files are involved. I made changes (mostly datatypes, type annotation and wherever I got runtime error from torch.jit.script call) to support Torchscript.
If I get some idea in what cases that error might come, then I may write a custom code snippet to reproduce that error.
For now I have attached a screenshot of the error I got, with the call stack internal to torch.jit.script call (after disabling ‘justMyCode’). Hope this gives some idea!

Have you found out? I have met the same problem when use torch_tensorrt.compile.

I could resolve this error through some rigorous debugging. Turned out that there was a method which expected 3 arguments, but only 2 were being passed as the third argument (=None) was not being used in the method which was required to be scripted.
A better error description, at least giving some idea of location of the error, would have been helpful here.

2 Likes

Hi, yes, I found out. Please see my recent post with the description of resolution.

Thanks a lot! It solves my problem

A better error description, at least giving some idea of location of the error, would have been helpful here.

Agree. If anyone else is looking for a hacky way to hunt down a bug, the error will print a path

miniconda3/lib/python3.12/site-packages/torch/jit/_recursive.py

You can just vim <your_path> and add

print('---\n', concrete_type, method_stubs, property_stubs)

This will give you a hint for where it happens.

2 Likes

For some input parameter which has default value None, try to add typing.Optional like follows

def forward(self, x: Tensor, context: Optional[Tensor]=None):
     ...