It seems the default constructor torch::Generator() leaves the pointer to GeneratorImpl a nullptr.
I took another route and fixed it using:
auto cpu_gen = at::detail::createCPUGenerator();
{
    std::lock_guard<std::mutex> lock(cpu_gen.mutex());
    cpu_gen.set_current_seed(0);
}
std::cout<<"gen_cpu"<<torch::rand(5,cpu_gen)<<std::endl;