Abstract
DynamicPPL.jl is a modular Julia library designed to provide high-performance execution for dynamic probabilistic programming. By leveraging Julia’s unique type inference and multiple dispatch capabilities, DynamicPPL enables flexible model specification without the runtime overhead typically associated with dynamic probabilistic programming languages (PPLs). This paper details the architectural innovations of DynamicPPL and evaluates its performance against Stan across a variety of benchmark models, demonstrating that it can achieve competitive and sometimes superior execution speeds.
Introduction
Probabilistic Programming Languages (PPLs) facilitate Bayesian inference by allowing researchers to express models as code. Historically, a significant trade-off has existed between flexibility and performance. Statically compiled languages like Stan offer exceptional speed but struggle with dynamic models where the parameter space or model structure changes during execution (e.g., non-parametric models). Conversely, dynamic PPLs offer flexibility at the cost of significant runtime overhead. DynamicPPL.jl, the core infrastructure for the Turing.jl ecosystem, addresses this gap by generating efficient machine code that rivals the performance of Stan while maintaining support for dynamic model dimensionality.
System Architecture
The performance of DynamicPPL is rooted in several key technical innovations:
- The @model Macro: A domain-specific language (DSL) that uses intuitive "tilde notation" (e.g.,
y ~ Normal(mu, sigma)) for model specification. - Typed Tracing via VarInfo: This mechanism is central to DynamicPPL's efficiency. An initial execution uses
UntypedVarInfoto record variable names and types. Once the model structure is traced, the system switches toTypedVarInfo, a strictly typed representation that allows the Julia compiler to generate highly optimized machine code for the sampling process. - Contextual Dispatch: The framework employs "contexts" (e.g.,
LikelihoodContext,PriorContext) to alter model behavior without code modification. This allows the same model code to be used for computing log-joint probabilities, likelihoods, or priors simply by swapping the execution context. - Automatic Differentiation (AD) Integration: DynamicPPL is designed for seamless integration with Julia’s AD ecosystem, supporting libraries like
ForwardDiff.jlandTracker.jl, which are essential for modern gradient-based inference algorithms like Hamiltonian Monte Carlo (HMC).
Performance Evaluation
The researchers evaluated DynamicPPL (via Turing.jl) against Stan using eight standard benchmark models, ranging from high-dimensional Gaussians to complex latent variable models like Latent Dirichlet Allocation (LDA).
As shown in Table 1, DynamicPPL is highly competitive. It outperformed Stan in three of the eight benchmarks: the 10,000-D Gaussian, Naive Bayes, and Logistic Regression. Notably, in the Logistic Regression benchmark, Turing achieved an execution time of ~4.2s compared to Stan’s ~60.9s.
However, Stan remains significantly faster in time-series models such as Stochastic Volatility and the Semi-supervised HMM. In the latter, Stan was approximately 90 times faster (~5.0s vs ~463.2s). Analysis suggests this discrepancy is primarily due to overhead within the Tracker.jl AD library rather than inherent limitations in the core DynamicPPL design.
Discussion and Future Work
The evaluation demonstrates that dynamic traces can be optimized effectively. By performing type inference on a program's trace and re-executing with concrete types, DynamicPPL achieves a form of "Just-In-Time" optimization specifically for probabilistic models. Furthermore, the modular nature of DynamicPPL allows it to serve as a standalone foundation for other Julia-based PPLs, fostering a collaborative ecosystem.
Future development will focus on mitigating AD-related bottlenecks by integrating more modern systems like Zygote.jl. Additionally, the authors plan to implement automated dependency analysis to avoid redundant computations during sampling and enhance support for compositional and hierarchical modeling.
Summary updated