Skip to content

Add new backends: stanr & stanli - #1911

Open
andrjohns wants to merge 4 commits into
paul-buerkner:masterfrom
andrjohns:stanr-stanli
Open

Add new backends: stanr & stanli#1911
andrjohns wants to merge 4 commits into
paul-buerkner:masterfrom
andrjohns:stanr-stanli

Conversation

@andrjohns

Copy link
Copy Markdown
Contributor

This PR adds support for two new backends: stanr and stanli.

The stanr package is a new in-memory interface for Stan (a modern rstan alternative). stanr uses broadly the same API as cmdstanr, so a lot of the existing machinery can be reused as-is.

A much more exciting addition is the stanli backend! This uses the brilliant stanli project by @seantalts to provide interpreted execution for Stan models - no compilation required!

stanli interop is provided by the stanr package using the same API as the normal compiled approach, so there's no additional maintenance/burden for brms

With this branch, brms can now be used with no c++ compilation/toolchain required!

# install.packages('stanr', repos = c('https://andrjohns.r-universe.dev', 'https://cloud.r-project.org'))

fit <- brm(time ~ age * sex, data = kidney, backend = 'stanli')

@wds15

wds15 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Whow! BTW... Stanli brings WALNUTS under the hood. Is that functionality also exported here?

I have no clue how close this is to be merge ready for brms, but I must say I would be blown away if this makes it... and enables C++ free super fast sampling for (all?) brms models...a dream!

@andrjohns

Copy link
Copy Markdown
Contributor Author

Whow! BTW... Stanli brings WALNUTS under the hood. Is that functionality also exported here

Yep! For both the stanli and stanr backends:

fit <- brm(time ~ age * sex, data = kidney, backend = 'stanli', engine = 'walnuts')

@paul-buerkner

Copy link
Copy Markdown
Owner

Very cool, thank you! Quick question: do you transform the objects in to rstan::stanfit objects after fitting? My plan is to abandon the transformations and just store the fitted model objects of whatever backend we used (no transformation to stanfit anymore). however, this requires adding functions for parameter renaming and information extraction per backend rather than just rstan. So I am thinking (aloud with you right now) how to best approach this topic in light of the new backends that you propose to add.

@gravesti

Copy link
Copy Markdown

I added a big fix PR on @andrjohns's fork but now realise it's not actually in the code that changed. It's a small fix to make sure the right variables get included by brms after sampling with these alternative backends. Might not be needed if the post-processing changes.
andrjohns#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants