This release cycle is dedicated to some nice "slice of life" features for Stan users and developers.
First, for users we've started adding vectorized binary functions to the language. This means that users can now right code such as
matrix[17, 93] u[12];
matrix[17, 93] z[12];
z = pow(u, 2.0);
which provides the same results as calling
for (i in 1:17) {
for (j in 1:93) {
for (k in 1:12) {
z[i, j, k] = pow(u[i, j k], 2.0);
}
}
}
The official docs are not updated from 2.24 until the full release of 2.25 so until then you can find the list of binary vectorized functions here.
Other noticable user facing changes in the language functions include allong C0 in gaussian_dlm_obs_lpdf
and gaussian_dlp_obs_rng to now be a positive semidefinite matrix and making binomial_lpmf work more reliably when the probability parameter is 0.0 or 1.0
For folks who have wanted to try out Stan's OpenCL GLM functions, we've rewritten them to accept parameters or data for any of their input arguments. Users will most likely have the easiest time accessing these through the cmdstan backend when working with brms generated models.
For cmdstan users we've added an option to control the significant figures for values when working with stansummary
. Users can also now download specific stanc3 version and we fixed a little bug when building some boost related thing son MacOS.
An appropriate segue into the stan math changes, because of some things that changed in the backend users who utilize the ODE solvers in Stan may see a small performance decrease. To fix that you can add the STAN_COMPILER_OPTIMS
flag to the make/local
to turn on link time optimization for Stan which should remove any performance issues (turning this on can actually speed up some other Stan models).
The Stan math backend is undergoing a lot of changes at the moment (we've had 99 PRs since the lease release!). You can check them out in more detail in the individual notes below, but we've re-worked some major parts of Stan so that we can be wayy more efficient at matrix algebra. A lot of changes were focused around getting this to work while making sure there was not a serious performance hit to current stan programs and the fast stuff we are writing now gives the same numeric answers from our current methods.
@t4c1 figured out a wonderfully nice pattern for writing reverse mode autodiff functions which we call reverse_pass_callback()
. reverse_pass_callback()
breaks up the fact that reverse mode autodiff is
- Running the regular function
- Saving the data
- Adding a callback to a stack to calculate the adjoints in the reverse pass.
The pattern leads to some rather pretty code. It also leads to 15% speedup or so in some cases which is nice.
We've had to considerably beef up our test suite in order to handle all of the above, and we added sanitizers to all the tests as well now to make sure things are sque ̢͛e ͙̑ä͔͓́͞ķ̘̃͞y̲̥̑́ ̨̅c̨̲̝̟̞̓̾̀́̉l̜̞̘͈̔̋̓̓̆͝ͅͅ ͔̤̝̦̞̙͐͐̀́̕͡e̲͎͉͓͎͓̿͊̌̅͡͡ ͙̩̜̞͚̬͛̃̒̅͠͝ã͔̼͈͒̋̿̔̿͟ͅͅ ̧͚͉̱͉̻̈́̊͐̄̊̎ṅ̛̫̦͎͖̅͛̉͟͡ͅn͕̪͈̠͚̊͂̒̃̋͜͠n͖̖͇̺͇̯̎̈͛̓̇̕n̨̲͙͚͉̅́͒̀̕͡ͅ (̵͔͝s̵̢̑ê̷̳q̶̠͆ ̵͔̽f̷̣̿a̷̞̅u̷̺͠l̷̯͂ ̴̟́c̷̈́ͅo̸͖̊r̴̢̕e̷̩̓ ̷͔͑ḑ̷̒u̸̯̚m̴̌ͅp̵̪͊)̴̠̅
Bad jokes aside it's a lot of testing so seg faults and the like should have a much lower chance of getting near users.
These are a few of the highlights, but please check out the full release notes below for more details
I can't add review comments as it's a gist, so I am posting a rewrite. The joke seems fine, but I would not want to scare people with seg faults in an announcement :) Maybe I am too uptight, idk :)
In the end, you mention release notes that are currently not available so I removed that.
Stan 2.25 Release candidate announcement
This release cycle is dedicated to some nice "slice of life" features for Stan users and developers.
Vectorized binary functions
First, for users, we've started adding vectorized binary functions to the language. This means that users can now write code such as
which provides the same results as calling
The official docs are not updated from 2.24 until the full release of 2.25. Until then, the list of vectorized functions should suffice:
Improved reliability and minor cmdstan user-facing improvements
C0
ingaussian_dlm_obs_lpdf
andgaussian_dlp_obs_rng
to now be a positive semidefinite matrix.binomial_lpmf
now works more reliably when the probability parameter is 0.0 or 1.0.stansummary
.User controlled unnormalized distribution syntax for the
target +=
As you are probably aware
and
behave differently. The functional form and hence
target +=
includes normalizing constants (likelog√2π
innormal_lpdf
). The sampling statement form (with~
) drops normalizing constants and everything else not relevant for computing the autodiff gradient in the samplers and optimizers.We have now added the option of using unnormalized distribution with the
target +=
syntax as well. This can be done by using the_lupdf
or_lupmf
suffix. So for exampleis now equivalent to the sampling statement above. Official documentation for this feature is still a work in progress, but in the meantime you can read more on this here.
This feature will especially be useful with
reduce_sum
where the sampling statements can not be used.Simplified makefile acces to C++ compiler optimizations
The backend Stan Math library is in the middle of a large refactor. The details are given below. Due to some of the changes in the backend, users who utilize the ODE solvers in Stan may see a small performance decrease in some cases. To fix that you can add the
STAN_COMPILER_OPTIMS
flag to themake/local
to turn on link-time optimization for Stan which should remove any performance issues. Turning these optimizations can actually lead to speedups in other models as well. We are still investigating where and when this is beneficial in order to handle these optimizations automatically in the next releases.OpenCL support
Users can now use GLM functions with OpenCL for cases where any argument is a parameter, we've rewritten them to accept parameters or data for any of their input arguments.
Changes in the Stan backend
The Stan Math backend is undergoing a lot of changes at the moment (we've had 99 PRs since the last release!). There are three larger projects that are in lead by Ben Bales, Steve Bronder and Tadej Ciglarič. These are:
Almost all functions in the Stan Math library were refactored to handle Eigen expressions and use Eigen expressions internally. This will lead to better efficiency in the future but for some functions we have already observed significant even now.
We have reworked some major parts of Stan so that we can be way more efficient at matrix algebra. This is still a work in progress, but you can read more on that in [this thread]. While this has not been exposed to Stan, we had to make some changes in the backend that are used in current Stan programs as well. We made sure there was not a serious performance hit to current Stan programs and that the fast stuff we are writing now gives the same numeric answers from our current methods.
Tadej figured out a wonderfully nice pattern for writing reverse mode autodiff functions which we call
reverse_pass_callback()
.reverse_pass_callback()
breaks up the fact that reverse mode autodiff isThe pattern leads to some rather pretty code. It also leads to 15% speedup or so in some cases which is nice.
We would also like to note that we have put a lot of effort into testing these backend changes. We are running function level performance tests and also check all Math functions for leaks with an address sanitizer. But we still need your help in making sure none of these refactors affected your Stan models. So please try your models and report if you see any improvements or more importantly any performance regressions.
Please test the release candidate with your models and report back your findings. The Stan development team appreciates your time and help in making Stan more efficient while maintaining a high level of reliability.
If everything goes according to plan, the 2.25 version will be released next Thursday.