Skip to content

Executing a TorchScript that returns multiple values, throws an excetion  #745

Closed
@kaiidams

Description

@kaiidams

Probably TorchScript.forward() may return IValue to encapsulate values like C++ LibTorch, or return object.

def a(x, y):
    return x + y, x - y

a = torch.jit.script(a)
a.save('test.pt')
var loaded = torch.jit.load("test.pt");
var x = torch.rand(3, 4);
var y = torch.rand(3, 4);
loaded.forward(x, y)

output:

System.Runtime.InteropServices.ExternalException (0x80004005): Expected Tensor but got Tuple
Exception raised from reportToTensorTypeError at C:\actions-runner\_work\pytorch\pytorch\builder\windows\pytorch\aten\src\ATen\core\ivalue.cpp:908 (most recent call first):
00007FFE0480DA5A00007FFE0480C270 c10.dll!c10::initLogging [<unknown file> @ <unknown line number>]
00007FFE0480D40A00007FFE0480C270 c10.dll!c10::initLogging [<unknown file> @ <unknown line number>]
00007FFE0480EAF100007FFE0480C270 c10.dll!c10::initLogging [<unknown file> @ <unknown line number>]
00007FFE0480E76500007FFE0480C270 c10.dll!c10::initLogging [<unknown file> @ <unknown line number>]
00007FFE0480B70F00007FFE0480B6A0 c10.dll!c10::Error::Error [<unknown file> @ <unknown line number>]
00007FFE04809F3600007FFE04809E70 c10.dll!c10::detail::torchCheckFail [<unknown file> @ <unknown line number>]
00007FFDE9670C1700007FFDE9670B70 torch_cpu.dll!c10::IValue::reportToTensorTypeError [<unknown file> @ <unknown line number>]
00007FFDE934ED5600007FFDE934ED10 torch_cpu.dll!c10::IValue::toTensor [<unknown file> @ <unknown line number>]
00007FFE05A81ADE00007FFE05A81980 LibTorchSharp.dll!THSJIT_Module_forward [C:\Users\kaiida\Source\Repos\dotnet\TorchSharp\src\Native\LibTorchSharp\THSJIT.cpp @ 142]
00007FFE10F370ED <unknown symbol address> !<unknown symbol> [<unknown file> @ <unknown line number>]

   at TorchSharp.torch.CheckForErrors() in C:\Users\kaiida\Source\Repos\dotnet\TorchSharp\src\TorchSharp\Torch.cs:line 489
   at TorchSharp.torch.jit.ScriptModule.forward(Tensor x, Tensor y) in C:\Users\kaiida\Source\Repos\dotnet\TorchSharp\src\TorchSharp\JIT\ScriptModule.cs:line 340
   at Submission#24.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
   at TorchSharp.torch.CheckForErrors() in C:\Users\kaiida\Source\Repos\dotnet\TorchSharp\src\TorchSharp\Torch.cs:line 489
   at TorchSharp.torch.jit.ScriptModule.forward(Tensor x, Tensor y) in C:\Users\kaiida\Source\Repos\dotnet\TorchSharp\src\TorchSharp\JIT\ScriptModule.cs:line 340
   at Submission#24.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions