(manually cherry picked from commit 79128ea9, after removing the reference to the DIME sampler which is not in 6.x)