An unhandled exceptionMicrosoft C ++ exception: c10 :: Error at memory location

I’m trying to convert my network trained in pytorch to libtorch for inference. However, I run into this c++ exception:
There is an unhandled exception at 0x00007FFC58E69709 (located in cp.exe): Microsoft C ++ exception: c10 :: Error at memory location 0x0000008CF9F0F7B0.
Here is a piece of code for testing:

#include  <torch/script.h> 
#include <stdlib.h>
#include <memory>
#include <iostream>
int main() {
	torch::jit::script::Module module = torch::jit::load("F:\ \c.pt");
	std::vector<torch::jit::IValue> input;
    input.push_back (torch::ones({ 36, 9, 64,64 }));
	at::Tenser output = module.forward(input).toTenser();

pytorch1.4 libtorch1.4 VS2019 cpu

why it happened?Maybe the c.pt is wrong?

1 Like

Should be “F:\\c.pt”.

I modified it, still the same error

Please check the following things:

  1. All the DLLs in LibTorch are copied to the directory of the executable.
  2. You are not mixing the usage of different configurations.
  3. Make sure the module is saved when it is on CPU, not GPU.

I am getting exactly the same error but on a slightly different trivial example when using torchvision (C++) directly. The error appears when I try to use a VGG16 network but it works normally for a ResNet. I have submitted the issue in the torchvision repo: https://github.com/pytorch/vision/issues/2245

Can anyone verify if it is related to this bug or it is on the torchvision side?

I am getting exactly the same error on a totally different scenario with torch.cholesky_solve where on libtorch 1.4.0 I had none. I am really interested on this.
Downloaded previous 1.4.0 and confirmed the problem is with 1.5.0. Trying to write minimal reproducible example to report the bug.

Just solved my “bug” trying to produce the minimal reproducible example.
My VStudio 2019 Project was not properly configured. I was mixing libtorch 1.4 headers with 1.5 binaries :crazy_face: :crazy_face: :sweat_smile:
@Rem_H I recommend you copy the configuration from the cmake project created based on the minimal example here and using the x64 native Tools Command Prompt

Thanks,when i tried the example c++ program like

 #include <torch/torch.h>
 #include
 int main() {
torch::Tensor tensor = torch::rand({ 2, 3 });
 std::cout << tensor << std::endl;
 return 0;
 }

,it’s all right,but still same wrong with load the .pt file.