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


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();
//Also results in segfault

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


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());