Maybe you want to take a look at this post:

  
    
    
    Reading tensors in C++ saved with `torch.save` C++
  
  
    I am trying to read tensors saved with torch.save() from C++. I tried reproducing this test case: 


That is reading a file created with: 


I modified the test case example to: 
#include <torch/torch.h>
#include <iostream>

int main()
{
  std::ifstream input_stream("ivalue.pt");
    std::vector<char> input;
    input.insert(
        input.begin(),
        std::istream_iterator<char>(input_stream),
        std::istream_iterator<char>());
    std::cout << input.size() << std::endl;
    torch::IVa…
  


I had similar issues some time ago and using binary streams fixed the issue.