Skip to content

Replace httpstan wrapper with BridgeStan #424

@simeoncarstens

Description

@simeoncarstens

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    StanRelates to Stan model support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions