Probabilistic programming languages (PPLs) make encoding and automatically solving statistical inference problems relatively easy by separating models from the inference algorithm. A popular choice for solving inference problems is to use Monte Carlo inference algorithms. For higher-order functional PPLs, these inference algorithms rely on execution suspension to perform inference, most often enabled through a full continuation-passing style (CPS) transformation. However, standard CPS transformations for PPL compilers introduce significant overhead, a problem the community has generally overlooked. State-of-the-art solutions either perform complete CPS transformations with performance penalties due to unnecessary closure allocations or use efficient, but complex, low-level solutions that are often not available in high-level languages. In contrast to prior work, we develop a new approach that is both efficient and easy to implement using higher-order languages. Specifically, we design a novel static suspension analysis technique that determines the parts of a program that require suspension, given a particular inference algorithm. The analysis result allows selectively CPS transforming the program only where necessary. We formally prove the correctness of the suspension analysis and implement both the suspension analysis and selective CPS transformation in the Miking CorePPL compiler. We evaluate the implementation for a large number of Monte Carlo inference algorithms on real-world models from phylogenetics, epidemiology, and topic modeling. The evaluation results demonstrate significant improvements across all models and inference algorithms.
翻译:概率编程语言(PPL)通过将模型与推理算法分离,使编码和自动求解统计推理问题相对容易。解决推理问题的常用方法是使用蒙特卡洛推理算法。对于高阶函数式PPL,这些推理算法依赖于执行悬挂(suspension)来执行推理,通常通过完整的续延传递风格(CPS)转换实现。然而,PPL编译器的标准CPS转换会引入显著开销,这一问题在学界普遍被忽视。现有解决方案要么执行完整的CPS转换,因不必要的闭包分配导致性能损失,要么使用高效但复杂的底层解决方案,而这在高级语言中往往不可用。与先前工作不同,我们开发了一种新方法,既高效又易于使用高阶语言实现。具体而言,我们设计了一种新颖的静态悬挂分析技术,该技术能够针对特定推理算法确定程序中需要悬挂的部分。分析结果允许仅对程序必要部分进行选择性CPS转换。我们形式化证明了悬挂分析的正确性,并在Miking CorePPL编译器中实现了悬挂分析与选择性CPS转换。我们使用来自系统发育学、流行病学和主题建模的真实世界模型,对大量蒙特卡洛推理算法进行了评估。评估结果表明,所有模型和推理算法均实现了显著改进。