NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Efficiently Vectorized MCMC on Modern Accelerators

Hugh Dance, Pierre Glaser, Peter Orbanz, Ryan P Adams

The Synchronization Bottleneck in Vectorized MCMC

Modern scientific computing relies heavily on automatic vectorization tools, such as JAX’s vmap, to run multiple Markov chain Monte Carlo (MCMC) chains in parallel on hardware accelerators like GPUs. While this approach is easy to implement—often requiring just a single function call over single-chain code—it hits a major performance snag with algorithms that rely on while loops, such as the No-U-Turn Sampler (NUTS) or Slice Sampling.

Because GPUs execute instructions in "lock-step," a vectorized batch of chains is only as fast as its slowest member. If 99 chains finish their work in 10 iterations but one outlier chain requires 1,000, the GPU effectively sits idle for 99% of the time, waiting for that single chain to finish. This "synchronization barrier" leads to massive inefficiencies, especially as the number of parallel chains increases.

Statistics showing how the maximum number of iterations across chains far exceeds the average.

As illustrated above, the average number of iterations needed for the slowest chain in a batch of 1024 is often significantly higher than the average for a single chain. The potential for speedup is highest when the distribution of loop iterations is highly skewed—i.e., when chains are usually fast but occasionally very slow.

Transforming MCMC into Finite State Machines

To bypass these synchronization bottlenecks, the authors propose a novel framework that reimagines MCMC kernels as Finite State Machines (FSMs). By moving the while loop to the outermost layer of the execution, chains are no longer forced to wait for each other at every iteration. They only synchronize once the entire batch has collected the required number of samples.

A conceptual diagram showing how a single while loop is broken into three FSM states.

The methodology relies on a few key steps:

  1. FSM Conversion: The standard MCMC sample function is broken down into contiguous, loop-free code blocks called states. A transition function then dictates which state a chain should move to next based on its internal logic (e.g., whether a slice sampling condition was met).
  2. Vectorized Step Function: Instead of vectorizing the entire sampling loop, the framework vectorizes a single FSM step. In each step, every chain progresses one state forward. Crucially, different chains can be in different states simultaneously within the same vectorized call.
  3. Optimizations:
  4. Step Bundling: To reduce the overhead of the FSM "switch" logic, sequential states are grouped together, allowing a chain to potentially traverse multiple states in a single execution cycle.
  5. Cost Amortization: For expensive operations like log-probability calculations, the function is called only once per vectorized step, even if multiple states require it.

The authors also derive a theoretical "efficiency bound" that predicts the maximum possible speedup based on the distribution of loop iterations across chains.

Key Results and Benchmarks

The researchers evaluated their FSM approach across several challenging benchmarks, including Gaussian Process Regression on the Real Estate UCI dataset, NUTS evaluation on PosteriorDB datasets, and synthetic benchmarks like a 100-dimensional correlated mixture of Gaussians.

The FSM-based MCMC implementations consistently outperformed standard vectorized baselines (such as BlackJAX):

  • HMC-NUTS: Achieved nearly an order of magnitude (10x) speedup for 100 chains on a correlated Gaussian mixture.
  • Elliptical Slice Sampling: Showed a 3x improvement in Effective Sample Size per second (ESS/sec) on the Real Estate GPR task.
  • Delayed Rejection MH: The "condensed" FSM version achieved a 3x efficiency gain over the standard implementation.
  • Transport Elliptical Slice Sampling (TESS): Improved ESS/sec in almost all benchmark cases, often doubling the performance of the best existing adaptive HMC variants.

Limitations and Future Work

While highly effective, the FSM approach does have limitations. The "run-and-mask" nature of GPU vectorization means that in every FSM step, the GPU technically executes the code for all states and then masks out the ones not relevant to a specific chain. If an algorithm has too many states, this branching overhead could eventually outweigh the benefits of de-synchronization.

Additionally, while the paper outlines an automated construction process, achieving peak performance currently requires manual optimizations like step bundling. Because speedups are highly dependent on specific GPU architectures and how efficiently they handle masked vector operations, future work will likely focus on automated tools for FSM optimization tailored to specific hardware.

Summary updated

BibTeX
@inproceedings{dance2025efficiently,
  author = {Hugh Dance and Pierre Glaser and Peter Orbanz and Ryan P Adams},
  title = {{Efficiently Vectorized MCMC on Modern Accelerators}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=Mlmpf4Izrj},
}
Figure