torch::Generator seeding segfault (at::Generator mutex)

Hi,

I would like to create a RNG generator which can be seeded individually (as opposed to the global torch::manual_seed(123).

However, I keep running into segmentation faults. I understood the at::Generator is not thread-safe, and therefore a mutex is necessary, but even just creating the mutex gives me a segfault:

auto gen_cpu = torch::Generator();
std::lock_guard<std::mutex> lock(gen_cpu.mutex());
//Results in segfault
auto gen_cpu = torch::Generator();
gen_cpu.set_current_seed(0);
//Also results in segfault

Any help with how the Generator should be created and seeded without segfaults?

Thanks!

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;