Installing and Obstructing Heuristics: Learning Dynamics in Nim

Leo Villani, Sultan Daniels, Ijin Yu, Anant SahaiCompLearn @ ICML 2026

TL;DR

Researchers have found that large language models (LLMs) don't just "flip a switch" from random guessing to algorithmic mastery; instead, they often plateau at intermediate "half-baked" heuristics. By using the game of Nim as a controlled laboratory, the authors demonstrate that these heuristics can be intentionally implanted or bypassed through specific training curricula and representational constraints.

What Problem Does This Paper Address?

When an LLM solves a math problem or follows a complex logic chain, is it actually "reasoning," or is it just using a clever shortcut? In most real-world benchmarks, the space of possible shortcuts is messy and unknown. This makes it hard to tell if a model has truly learned an algorithm or is just exploiting a statistical quirk.

The authors tackle this by using Nim, a simple mathematical game. In the version studied (single-pile bounded Nim), the optimal strategy is purely modular arithmetic: to win, you must leave your opponent with a pile size that is a multiple of $(MR + 1)$, where $MR$ is the move limit. Because the "ground truth" is a clear mathematical rule ($n \pmod m$), the researchers can precisely identify when a model has learned the full rule versus a "coarse" version of it (e.g., learning whether a number is even or odd before learning its exact value mod 6).

Methods

The researchers fine-tuned the Pythia family of models (70M to 410M parameters) on synthetic Nim games described in natural language. They employed several clever techniques to probe the learning process:

  • Coset Analysis: They didn't just track overall accuracy. They tracked "coarsened" accuracy to see if models were learning factors of the target modulus (e.g., if the goal is mod 9, does the model first master mod 3?).
  • Prefinetuning: They "primed" models by training them on simpler modular tasks (like explicit "10 mod 3" questions) before moving to the full Nim game to see if heuristics could be "installed."
  • Curriculum Learning: They compared "Hard-first" (training on prime moduli like 5 and 7, which have no sub-factors) vs. "Composite-first" (training on moduli like 4, 6, and 8) to see how it affected the discovery of the final algorithm.
  • Shortcut Intervention: They intentionally "poisoned" some data so that player names were secretly tied to specific moves. They then tested two ways to stop the model from cheating: DANN (adversarial training) and Contrastive Name Invariance (a loss function that forces the model's internal "thoughts" to be identical regardless of the player's name).

Datasets

The study uses entirely synthetic datasets generated via templates:

  • Nim Prompts: Natural language descriptions of game states, move limits, and histories.
  • Modular Reduction: Explicit arithmetic prompts (e.g., "What is $x \pmod k$?") used for pre-training.
  • Cheat/Neutral Pairs: A specialized dataset for the shortcut experiments where certain player name pairs were deterministically mapped to specific "cheat" moves.

Key Insights and Ideas

  • The "Plateau" Phenomenon: Models training on composite moduli (like $m=6$) often hit a long performance plateau. During this time, they aren't just failing; they have mastered a "coarse" version of the rule (like parity). Models training on prime moduli ($m=7$) don't have these "stepping stone" heuristics available and tend to "grok" the full rule suddenly.
  • Heuristics are Transferable: You can "install" a specific plateau. If you pre-train a model on mod-3 arithmetic, it will reliably get "stuck" on a mod-3 heuristic when later trying to learn a mod-9 Nim game.
  • Obfuscation vs. Erasure: This is a major "aha" moment. When the researchers used adversarial training (DANN) to stop the model from using "cheat" names, the model didn't stop cheating—it just learned to hide the "cheat signal" in its internal layers so the adversary couldn't see it, while still using that hidden info to make the final prediction.
  • Hard-First is Better: Starting a curriculum with "hard" tasks (prime moduli) prevents the model from settling into lazy heuristics early on, leading to better overall performance across all tasks.

Key Results

  • Scale Matters: Larger models (410M) were much more susceptible to these intermediate coset plateaus than the smallest (70M) models.
  • Shortcut Suppression: While adversarial training failed (obfuscation), the Contrastive Invariance method successfully induced "grokking" of the true Nim rule in 2 out of 5 seeds, even when the "cheat" shortcut was available.
  • Acceleration: Prefinetuning on a "clean" task (one without sub-heuristics) can significantly speed up the learning of a more complex downstream task. For example, pre-training on $MR=4$ (mod 5) allowed a model to master $MR=8$ (mod 9) in 5,000 steps, compared to 30,000+ steps for the baseline.

Limitations and Future Work

The authors acknowledge that Nim is a "toy" setting. It remains to be seen if these "coset heuristics" exist in more complex, real-world reasoning tasks like coding or legal analysis. Furthermore, the success of their interventions (like the contrastive loss) was highly seed-dependent, meaning it worked perfectly sometimes and failed others.

Future work aims to provide a more "mechanistic" account—literally mapping the circuits inside the transformer—to explain why specific heuristics (like parity) are so much more attractive to the model than others.

Summary updated

BibTeX
@inproceedings{villani2026installing,
  author = {Leo Villani and Sultan Daniels and Ijin Yu and Anant Sahai},
  title = {{Installing and Obstructing Heuristics: Learning Dynamics in Nim}},
  booktitle = {CompLearn @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=kull6mg0vR},
}
Figure