Transformer可预测复杂伪随机数序列,揭示其内在结构与迁移规律。
Learning Pseudorandom Numbers with Transformers: Permuted Congruential Generators, Curricula, and Interpretability
- 用Transformer学习多种比特置换同余生成器的复杂序列
- 即使只输出1位,也能准确预测,且需序列长度随模数平方根增长
- 发现嵌入层存在旋转不变聚类,支持小模数向大模数迁移
我们研究Transformer模型对广义伪随机数生成器(PCG)序列的学习能力。相较于线性同余生成器(LCG),PCG通过一系列位级移、异或、旋转和截断操作增加难度。实验中,模型在模数达 $2^{22}$、参数量达5000万、数据量达50亿标记的条件下,仍能成功完成上下文预测任务,超越已有经典攻击方法。令人意外的是,即便输出仅保留1位,模型仍可可靠预测。当多种不同排列的PRNG共现于训练时,模型能联合学习其结构特征。我们发现存在模数 $m$ 的缩放律:实现近似完美预测所需的上下文序列长度与 $\ ext{\sqrt{m}}$ 成正比。对于 $m \geq 2^{20}$ 的情况,优化过程进入长期停滞期,必须引入小模数数据进行课程学习才可有效训练。此外,分析嵌入层揭示一种新型聚类现象:主成分自发将整数输入划分为位旋转不变簇,表明表示可从小模数迁移到大模数。
原文摘要 · Abstract (English)
We study the ability of Transformer models to learn sequences generated by Permuted Congruential Generators (PCGs), a widely used family of pseudo-random number generators (PRNGs). PCGs introduce substantial additional difficulty over linear congruential generators (LCGs) by applying a series of bit-wise shifts, XORs, rotations and truncations to the hidden state. We show that Transformers can nevertheless successfully perform in-context prediction on unseen sequences from diverse PCG variants, in tasks that are beyond published classical attacks. In our experiments we scale moduli up to $2^{22}$ using up to $50$ million model parameters and datasets with up to $5$ billion tokens. Surprisingly, we find even when the output is truncated to a single bit, it can be reliably predicted by the model. When multiple distinct PRNGs are presented together during training, the model can jointly learn them, identifying structures from different permutations. We demonstrate a scaling law with modulus $m$: the number of in-context sequence elements required for near-perfect prediction grows as $\sqrt{m}$. For larger moduli, optimization enters extended stagnation phases; in our experiments, learning moduli $m \geq 2^{20}$ requires incorporating training data from smaller moduli, demonstrating a critical necessity for curriculum learning. Finally, we analyze embedding layers and uncover a novel clustering phenomenon: the top principal components spontaneously group the integer inputs into bitwise rotationally-invariant clusters, revealing how representations can transfer from smaller to larger moduli.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。