发表机构
Université Clermont Auvergne; Clermont Auvergne INP; CNRS; LIMOS(克莱蒙奥弗涅大学; 克莱蒙奥弗涅国立理工学院; 法国国家科学研究中心; 克莱蒙奥弗涅信息、建模与优化系统实验室)
机构由 AI 辅助整理,请以论文原文为准。AI 中文总结
本研究检验PRNG完整状态转移能否确保跨库可复现性,发现即使相同算法实现间也存在差异,强调实现保真度是科学可复现性的必要条件,并提出实用指南。
AI 中文摘要
伪随机数生成器(PRNG)是多个科学领域中不可或缺的计算工具,包括蒙特卡洛模拟、随机计算和人工智能(AI)。此类应用的可复现性关键取决于PRNG实现能否在从相同内部状态初始化时,跨软件环境生成相同序列。这些算法能够模拟随机过程,同时提供确定性和可重复的行为,从而促进可复现的实验。现代PRNG实现可以通过种子或更准确地说是超过传统整数种子容量的初始状态进行初始化。然而,仅依赖简单种子通常不足以确保跨不同实现的一致程序执行轨迹。一个自然的假设是,无论使用何种软件库,转移生成器的完整内部状态都应保证输出相同。本研究通过调查完整初始状态能否确保PRNG流的跨库保真度和可移植性,来检验这一假设的有效性。我们聚焦于两种广泛部署的生成器——Mersenne Twister和Philox,并评估它们在四个主要Python生态系统——Random、NumPy、PyTorch和TensorFlow中的实现。我们将这些实现产生的序列与在相同初始化条件下原始参考算法生成的序列进行比较。我们的结果表明,即使实现声称遵循相同的底层算法,也不能仅从PRNG状态转移就假设可复现性。虽然多种实现成功实现了保真度,但在其他实现中观察到了显著差异。最值得注意的是,PyTorch中的Philox实现与参考算法存在根本性不兼容,导致无法跨环境精确复现生成器输出。这些发现挑战了获取PRNG完整内部状态足以确保跨软件栈可复现性的普遍预期。它们进一步强调,实现特定的设计选择可能为实验复制引入隐藏障碍,尤其是在依赖多个框架的AI工作流中。这项工作表明,PRNG的实现保真度是科学可复现性的必要条件,并做出了两项主要贡献。首先,它确定了在Python科学和AI生态系统中实现可靠PRNG使用和可复现性的实用指南。其次,它评估了通过用户级技术(无需修改库源代码)能在多大程度上恢复跨库可移植性和保真度。
英文摘要
Pseudorandom number generators (PRNGs) constitute indispensable computational tools across multiple scientific domains, including Monte Carlo simulations, stochastic computing, and artificial intelligence (AI). The reproducibility of such applications critically depends on the ability of PRNG implementations to generate identical sequences across software environments when initialized from the same internal state. These algorithms enable the simulation of stochastic processes while providing deterministic and repeatable behaviour, thereby facilitating reproducible experiments. Modern PRNG implementations may be initialized through either a seed or, more accurately, an initial state that exceeds the capacity of a conventional integer seed. However, reliance on a simple seed alone frequently proves insufficient to ensure consistent program execution traces across different implementations. A natural assumption is that transferring the complete internal state of a generator should guarantee identical outputs regardless of the software library used. This study examines the validity of this assumption by investigating whether complete initial states can ensure cross-library fidelity and portability of PRNG streams. We focus on two widely deployed generators, Mersenne Twister and Philox, and evaluate their implementations across four major Python ecosystems-Random, NumPy, PyTorch, and TensorFlow. We compare the sequences produced by these implementations against those generated by the original reference algorithms under identical initialization conditions. Our results demonstrate that reproducibility cannot be assumed from PRNG state transfer alone, even when implementations claim to follow the same underlying algorithm. While fidelity was successfully achieved for several implementations, significant discrepancies were observed in others. Most notably, the Philox implementation in PyTorch exhibits fundamental incompatibilities with the reference algorithm, preventing exact reproduction of generator outputs across environments. These findings challenge the common expectation that access to a full internal state of a PRNG is sufficient to ensure reproducibility across software stacks. They further highlight that implementation-specific design choices can introduce hidden barriers to experimental replication, particularly in AI workflows that rely on multiple frameworks. This work shows that implementation fidelity of a PRNG is a necessary condition for scientific reproducibility and makes two primary contributions. First, it identifies practical guidelines for achieving reliable PRNG usage and reproducibility within the Python scientific and AI ecosystem. Second, it evaluates the extent to which cross-library portability and fidelity can be recovered through user-level techniques, without requiring modifications to library source code.