Libtorch run on Windows Error


(Hai Bi) #1

I passed compiling codes as instruction, but when I run on the windows 10,
the following error came out, anybody can creating network by using libtorch c++ on windows, could you help me?

error

and It runs normally on Linux.

#include <torch/torch.h>

// Define a new Module.
struct Net : torch::nn::Module {
  Net() {
    // Construct and register two Linear submodules.
    fc1 = register_module("fc1", torch::nn::Linear(8, 64));
    fc2 = register_module("fc2", torch::nn::Linear(64, 1));
  }

  // Implement the Net's algorithm.
  torch::Tensor forward(torch::Tensor x) {
    // Use one of many tensor manipulation functions.
    x = torch::relu(fc1->forward(x));
    x = torch::dropout(x, /*p=*/0.5);
    x = torch::sigmoid(fc2->forward(x));
    return x;
  }

  // Use one of many "standard library" modules.
  torch::nn::Linear fc1{nullptr}, fc2{nullptr};
};
int main(int argc, char* argv[]){
// Create a new Net.
Net net;
return 0;
}

(Hylke Kleve) #2

I’m getting the same crash in the constructor. What i can see is that the register_module(...) call tries to insert an element into a borked children_ object.

UPDATE:

Found it. There is a layout mismatch between debug/release. This messes up the inline defined register_module. In a Release build everything works as intended. The std:: objects in OrderedDict have different layouts. Maybe a debug dll or pimpl Module?

UPDATE:

Reported it as an issue on GitHub


(Lawrence Lewis) #3

I think this has been resolved. It’s a combination of things. See https://github.com/pytorch/pytorch/issues/15757