Getting set up with libtorch c++

Hey yall, having some trouble getting a basic nn Module working with libtorch. I’m trying to copy the example found here Using the PyTorch C++ Frontend — PyTorch Tutorials 2.3.0+cu121 documentation

#include <torch/torch.h>

struct Net : torch::nn::Module {
  Net(int64_t N, int64_t M) {
    W = register_parameter("W", torch::randn({N, M}), true);
    b = register_parameter("b", torch::randn(M), true);
  }
  torch::Tensor forward(torch::Tensor input) {
    return torch::addmm(b, input, W);
  }
  torch::Tensor W, b;
};

But I’m getting this error:

Exception has occurred: W32/0xC0000005
Unhandled exception at 0x00007FF868671241 (vcruntime140.dll) in bmo.exe: 0xC0000005: Access violation reading location 0x0000001B8210038C.

On this line:

W = register_parameter("W", torch::randn({N, M}), true);

Libtorch version 2.2.2
C++ compiler MSVC v142 - VS 2019 C++ x64/x86
Windows