Stan support in Chainsail currently relies on wrapper around httpstan. So for every log-probability / gradient evaluation, the wrapper sends a HTTP request to the httpstan API that runs in a separate Docker container. This is very, very slow and very, very clunky.
Recently, BrigeStan was released. It allows
efficient in-memory access through Python, Julia, and R to the methods of a Stan model, including log densities, gradients, Hessians, and constraining and unconstraining transforms
and is exactly what we need. I did some preliminary tests and using BridgeStan yields a x1000 speed-up over using the existing httpstan wrapper 🤯 plus it might be easier to maintain; we could just bake it in as a system dependency into the user code container. My experiments stopped there because of the trouble of developing this under NixOS - BridgeStan requires stanc (the Stan compiler) and downloads binaries for that, which have an hardcoded RPATH, and furthermore, it requires GCC + dependencies. So under NixOS, without having packaged BridgeStan properly, developing this feature is very tiresome.
So the goal would be to replace the httpstan wrapper linked above with a wrapper around BridgeStan. Note, though, that the Stan model still has to be compiled before the log-probability and its gradient can be evaluated via BridgeStan. That would likely need to be done in the constructor of the wrapper.
Stan support in Chainsail currently relies on wrapper around
httpstan. So for every log-probability / gradient evaluation, the wrapper sends a HTTP request to thehttpstanAPI that runs in a separate Docker container. This is very, very slow and very, very clunky.Recently, BrigeStan was released. It allows
and is exactly what we need. I did some preliminary tests and using BridgeStan yields a x1000 speed-up over using the existing
httpstanwrapper 🤯 plus it might be easier to maintain; we could just bake it in as a system dependency into the user code container. My experiments stopped there because of the trouble of developing this under NixOS - BridgeStan requiresstanc(the Stan compiler) and downloads binaries for that, which have an hardcoded RPATH, and furthermore, it requires GCC + dependencies. So under NixOS, without having packaged BridgeStan properly, developing this feature is very tiresome.So the goal would be to replace the
httpstanwrapper linked above with a wrapper around BridgeStan. Note, though, that the Stan model still has to be compiled before the log-probability and its gradient can be evaluated via BridgeStan. That would likely need to be done in the constructor of the wrapper.