sbi icon indicating copy to clipboard operation
sbi copied to clipboard

Is it possible to load the saved NeuralPosterior objects from C++?

Open hanyk opened this issue 2 years ago • 2 comments

Thanks for your amazing work! Is it possible to load the saved NeuralPosterior objects from C++ to allow a more efficient posterior.sample?

hanyk avatar Aug 09 '22 02:08 hanyk

thanks!

No, I don't think we have this option. Have you tried increasing sampling speed using the slice_np_vectorized option, or slice_np with num_workers>1?

janfb avatar Aug 09 '22 17:08 janfb

Thanks for your suggestion!I will try that later. I am not sure about the structure of NeuralPosterior objects . Is it a kind of PyTorch Model? If so, it may be converted to torch script and then loaded in C++ with libtorch.

hanyk avatar Aug 11 '22 03:08 hanyk

Hi! The NeuralPosterior is not a pytorch module. The returned nflows network is a torch.nn.Module though. I.e.

net = inference.append_simulations(theta, x).train()
--> net is a nn.Module

Hope that helps! Michale

michaeldeistler avatar Aug 23 '22 10:08 michaeldeistler

Thank you very much!

hanyk avatar Aug 25 '22 08:08 hanyk

Closing this for now, feel free to re-open if new questions come up (and feel free to write here if you managed to sample in c++ ;) )

michaeldeistler avatar Sep 01 '22 11:09 michaeldeistler