# Pacing Outside the Box: RNNs Learn to Plan in Sokoban

*Work done at FAR AI.*

There has been a lot of conceptual work on [mesa-optimizers](https://www.lesswrong.com/tag/mesa-optimization): neural networks that develop internal goals that may differ from their training objectives (the [inner alignment](https://www.lesswrong.com/posts/pL56xPoniLvtMDQ4J/the-inner-alignment-problem) problem). There is an abundance of good ideas for empirical work ([find search](https://www.lesswrong.com/posts/FDjTgDcGPc7B98AES/searching-for-search-4) [in a NN](https://www.lesswrong.com/posts/tFYGdq9ivjA3rdaS2/high-level-interpretability-detecting-an-ai-s-objectives), [interpret it](https://www.lesswrong.com/posts/eqvvDM25MXLGqumnf/200-cop-in-mi-interpreting-reinforcement-learning)), but [very](https://www.lesswrong.com/posts/Jfmmfoeskims5jc5f/finding-the-estimate-of-the-value-of-a-state-in-rl-agents) [little](https://arxiv.org/abs/2402.11917) [actual ](https://unsearch.org/research/01_maze_transformer_world_representations/)$$$$[execution](https://www.lesswrong.com/posts/GfwdBoaLw3ef3zBqe/evidence-of-learned-look-ahead-in-a-chess-playing-neural), partly because we did not have a clear-cut example of a mesa-optimizer to study. Until now.[^lmseaff1jq8]

We have replicated the mesa-optimizer that [Guez et al. (2019)](https://arxiv.org/abs/1901.03559) found, and [released it open-source](https://github.com/AlignmentResearch/learned-planner) as a model organism for inner alignment research. In brief, Guez et al. trained a recurrent neural network (RNN) with model-free RL to play Sokoban. They noticed that if you give the RNN more time to think by repeating the initial observation at inference time, its performance increases. This is highly suggestive of planning!

We investigate this "planning effect" in a black-box way. We find that often, the RNN learns to "pace" before attempting to solve the level, likely to get more computation and find a solution. When we give the RNN time to think, it finds the solution in the extra thinking time and executes it straight away.

$$![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/animations/dfaca302a467b655849a9704644afa63b6b1036d590cac00.gif)

In other cases, the RNN sometimes starts with a greedy solution and locks itself out of the solution. With thinking time, the RNN finds the non-myopic solution, avoiding the lock and solving the level. Note that this greedy behavior may be bounded-rational given the -0.1 penalty per step: solving fewer levels but solving them more quickly can pay off.

![](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/animations/d627762f40a25ac02154504c2b3e24a38b11ace1105a9b2f.gif)

These are illustrative examples, but we have quantitative evidence too. We operationalize the pacing behavior as whatever creates a *cycle* in the sequence of environment states. If we give the RNN time to think at level start, it does not 'pace' anymore: 75% of cycles that occur in the first 5 steps disappear. Time to think in the middle of a level also substitutes cycles: 82% of N-step cycles disappear with N steps to think.

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXcozPooDFWj1fxKOSuupl795l7i6hkw7Krs4pdeRdkyRKgBSjiVSrBmVhJFgD4uaWnMvLIyBUqASBpzuccEh58AWRK5Wb_vqAjSz9W86KtAdP_LQN-11lbdC9OI9cFdoS2IQnT4MHBEt2EPPKwjxQmqqR5r?key=zpYRiFzYOH_-7540pGu6-Q)

The levels we use always have 4 boxes. Thinking time barely changes the average time the RNN takes to place boxes 1-3. But, when filtering only to levels that it cannot solve at 0 steps but can solve at 6 thinking steps, the time to place boxes 1-3 greatly increases, even though the time to place the 4th box barely changes. This indicates the NN is greedy by default, and thinking time remedies that.

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfoQ75qEAzvLwAZPlrOuTYvaaooFS2zu7iiP44Bw2Zr0LgQvODMCbWYwZr4sA_zoATECHCXnAcidLySC3LF3McjzMB88jiNbdCO4dmgTUzDIwPuwVYevAep8qhf3-uEDKi-rCDkHurBSU2Hpc-nmBYkzoo?key=zpYRiFzYOH_-7540pGu6-Q)

Understanding how neural networks reason, and ultimately locating where they evaluate plans, is crucial to solving inner alignment. This represents an important first step in our longer-term research agenda to automatically detect mesa-optimizers, understand their goals, and modify the goals or planning procedures to align with the intended objective.

For more information, read our [blog post](https://far.ai/post/2024-07-learned-planners/) or full paper [“Planning behavior in a recurrent neural network that plays Sokoban.”](https://arxiv.org/abs/2407.15421) And, if you're at ICML, come talk to us at the [Mechanistic Interpretability workshop](https://icml2024mi.pages.dev/) on Saturday!

If you are interested in working on problems in AI safety, we’re [hiring](https://far.ai/jobs/). We’re also open to exploring collaborations with researchers at other institutions – just reach out at [hello@far.ai](mailto:hello@far.ai).

[^lmseaff1jq8]: We believe LeelaChess is likely also planning. Thanks to Jenner et al., we have a handle on where the values may be represented and a starting place to understand the planning algorithm. However, it is likely to be much more complicated than the RNN we present, and it is not clearly doing iterative planning.