TL;DR
Researchers have demonstrated that Transformers can learn to predict sequences from Permuted Congruential Generators (PCGs)—the sophisticated pseudorandom number generators used in libraries like NumPy. By using curriculum learning and scaling context length relative to the generator's modulus, these models can uncover hidden deterministic patterns even when the output is heavily truncated or scrambled by complex bitwise operations.
The Challenge of Permuted Congruential Generators
Pseudorandom Number Generators (PRNGs) are designed to produce sequences that look like pure noise to statistical tests, yet they are governed by hidden deterministic rules. While previous work showed Transformers could learn simple Linear Congruential Generators (LCGs), this paper tackles PCGs.
PCGs are significantly harder to "crack" because they apply a series of "permutations"—bitwise shifts, XORs, and rotations—to the internal state before outputting a number. This scrambling makes the relationship between the internal state and the observed output highly non-linear. The authors wanted to know: can a general-purpose Transformer architecture discover these algebraic rules from data alone, without being told the generator's parameters?
Methods and Datasets
The authors used a standard GPT-style decoder-only Transformer equipped with Rotary Positional Embeddings (RoPE). The model was trained on an autoregressive next-token prediction task.
Two key strategies were employed to handle the difficulty of the task:
- Curriculum Learning: For large moduli ($m \ge 2^{20}$), models trained from scratch often hit a "stagnation phase" where loss refuses to drop. The authors used a curriculum where the model is first trained on smaller, easier moduli and then gradually transitioned to larger ones.
- Scaling Context: The researchers found that the amount of "in-context" information (the number of previous sequence elements) must grow as the generator's complexity increases to achieve high accuracy.
The study utilized synthetic datasets generated from four specific PCG variants:
- XSLRR: XORShift Low with Random Rotation.
- XSHRR: XORShift High with Random Rotation.
- XSHRS: XORShift High with Random Shift.
- TLCG: Truncated LCG (a simpler baseline).
The experiments scaled up to a modulus of $2^{22}$, using datasets containing up to 5 billion tokens. They tested two settings: "Separate" (one model per generator) and "Combined" (one model learning all four variants simultaneously).
Key Insights and Discoveries
- The $\sqrt{m}$ Scaling Law: The most significant discovery is that the number of in-context elements required for near-perfect prediction scales as $\sqrt{m}$ (where $m$ is the modulus). This is a steeper requirement than the $m^{0.25}$ law observed for simpler LCGs, reflecting the added complexity of PCG permutations.
- Spontaneous Bitwise Interpretability: PCA revealed that the model organizes its token embeddings into clusters based on "zero-runs" (the number and arrangement of contiguous zeros in the binary representation). This suggests the model has internalized the bitwise rotational symmetries inherent in the PCG algorithm.
- Multi-task Specialization: In the "Combined" dataset setting, the model's internal MLP layers spontaneously learned to differentiate between the four generator types without any explicit labels, effectively performing "generator identification" before predicting the next number.
- Robustness to Information Loss: Surprisingly, the model could still achieve high accuracy even when the output was truncated to a single bit. This indicates that Transformers are remarkably adept at reconstructing global state from extremely sparse local observations.
Key Results
Models achieved >90% test accuracy on unseen generator parameters $(a, c)$, proving they aren't just memorizing sequences but learning the underlying recurrence rules. Curriculum learning was shown to be "critically necessary" for large moduli, successfully removing the initial loss stagnation and broadening the range of stable learning rates.
Furthermore, the authors showed that the Transformer-based attack scales much more favorably than a brute-force search baseline ($m^{0.53}$ vs $m^{2.5}$ in terms of inference compute).
Limitations and Future Work
- Non-Cryptographic Focus: The study focuses on PCGs, which are widely used for simulations (like in NumPy) but are not "cryptographically secure." The authors note that attacking true cryptographic primitives (like AES or ChaCha20) remains a much higher hurdle.
- Context Window Limits: Because the required context length grows with $\sqrt{m}$, scaling this approach to 64-bit or 128-bit generators would require massive context windows that exceed current hardware capabilities.
- Mechanistic Gaps: While the embedding clusters are well-understood, a full "circuit-level" explanation of how the attention heads and MLPs collaborate to compute the specific bitwise permutations is still an open area for research.
Summary updated