[KongchangAI]
· 2 min read· 1,042 words

Let the Model "Sleep" Before Answering: How a Sleep Mechanism Improves In-Context Learning Efficiency

Let the Model "Sleep" Before Answering: How a Sleep Mechanism Improves In-Context Learning Efficiency

A few extra recurrent forward passes over the context significantly boost few-shot learning efficiency and generalization.

RSS's study *Sample-Efficient In-Context Adaptation via Sleep* systematically examined a sleep mechanism on general Transformers. Sleep means the model performs N recurrent forward passes over the context to refine internal representations. Pretraining language models up to 1.2B parameters on up to 100B tokens showed that larger N enables faster learning on few-shot tasks and lower OOD next-token loss; on code tasks, N=2 and N=4 reached baseline loss with 2.10× and 2.39× fewer context tokens.

Large models' ability to learn in context is being redefined by a counterintuitive training method: letting the model "sleep" before giving an answer. A study from RSS titled Sample-Efficient In-Context Adaptation via Sleep systematically examined the effects of a sleep mechanism on general tasks, concluding that letting a Transformer perform multiple recurrent forward passes over the context not only helps the model learn few-shot tasks faster, but also achieves lower next-token prediction loss in out-of-distribution evaluation.

Source of the study Sample-Efficient In-Context Adaptation via Sleep

Sleep Mechanism: Baking "Thinking It Through a Few More Times" into Pretraining

Sleep refers to the model performing N recurrent forward passes while processing a segment of context to repeatedly refine its internal representations. This idea was previously validated in a relatively narrow setting—mainly on SSM-attention hybrid models, to improve long-context reasoning. This study pushes the question further: for pure Transformer language models, on general, non-synthetic tasks, does the sleep mechanism also bring gains in in-context adaptation?

To answer this, the research team pretrained language models with up to 1.2B parameters on up to 100B tokens, embedding the sleep mechanism into training. This scale indicates that the conclusions were not obtained on toy models, but are empirical results with some engineering reference value.

In-Context Learning refers to the ability of large models to complete new tasks using only a few examples (few-shot) provided in the prompt, without updating parameters. The key to this ability lies in whether the model can efficiently extract task patterns from the context, and sample efficiency—i.e., how many context tokens are needed to reach target performance—directly determines actual deployment cost. The sleep mechanism works precisely on this dimension: it does not change model parameters, but strengthens the refinement of representations over the same context by adding recurrent computation at inference time, thereby allowing each token to be used more fully.

SSM-attention hybrid models refer to architectures that contain both state space model (SSM, e.g., Mamba) layers and attention layers. SSMs are good at processing long sequences with linear complexity, while attention layers retain precise token-to-token interaction capabilities; mixing the two can balance efficiency and effectiveness in long-context scenarios. Previously, the sleep mechanism was mainly validated on such hybrid models, because recurrent forward passes naturally align with the recursive characteristics of SSMs. This study transfers it to pure Transformers, meaning that the mechanism does not depend on the recursive structure of a specific architecture, but holds as a general means of representation refinement.

Core Finding: Longer Sleep Buys Faster In-Context Learning

The study's most critical set of results is: longer sleep (i.e., a larger number of recurrent forward passes N) lets the model learn faster on multiple few-shot algorithmic tasks and question-answering tasks, while also achieving lower next-token prediction loss in out-of-distribution evaluation. In other words, sleep brings more than "memorizing the context"—it makes the model's representations of the context more generalizable.

Data on held-out code tasks illustrate the efficiency difference even more clearly: models with N=2 and N=4 require only 2.10× and 2.39× fewer context tokens, respectively, than the no-sleep baseline to reach the same loss level as the baseline. This means that from the same segment of context, the sleep model can extract more usable information—which is precisely the definition of sample efficiency.

Sleep Is Not Better the Longer It Is, but a Trade-off Between Efficiency and Latency

The study does not claim that indefinitely extending sleep yields continued benefits. The authors explicitly position this work as a step toward finding a better trade-off between in-context adaptation and decoding latency. The larger N is, the higher the inference-time computational overhead, so small values such as N=2 or N=4 are more realistic in terms of efficiency—judging from the code-task data, a modest increase in the number of recurrent passes already yields considerable token savings.

Decoding latency refers to the inference time required for the model to generate each token. At inference time, the sleep mechanism performs N recurrent forward passes over the same context, so the larger N is, the higher the computational overhead and latency of a single context processing step. The trade-off here is: increasing N can improve context information utilization and reduce the number of tokens needed, but pushes up latency; while reducing N lowers latency but may require longer context to achieve the same effect. The reason N=2 or N=4 is realistic is precisely that they strike a good balance between token savings and latency increase.

The Boundaries of the Method's Significance

The value of this study lies in decoupling the sleep mechanism from a specific architecture (SSM-attention hybrid models) and a specific capability (long-context reasoning), validating its transferability to general Transformers and general tasks. However, the source material itself does not disclose more task types, model-family extensions, or the specific measurement methods for latency, so on the question of "whether sleep should become a standard part of pretraining," only a cautiously optimistic judgment can currently be made: it offers a feasible path to improve information utilization under a limited context budget, rather than a fully validated general solution.

For those building applications, this study points to a variable worth watching—the allocation of computation at the inference stage. In scenarios with limited context length and scarce user-interaction samples, multiple rounds of lightweight representation refinement may be more cost-effective than stuffing in more tokens.

One-line Summary

Letting a Transformer perform a few more recurrent forward passes over the context can significantly improve few-shot learning efficiency and generalization.

Paragraph Summary

RSS's study Sample-Efficient In-Context Adaptation via Sleep systematically examined the effects of a sleep mechanism on general Transformers. Sleep refers to the model performing N recurrent forward passes while processing context to refine its internal representations. The study pretrained language models with up to 1.2B parameters on up to 100B tokens, finding that a larger N lets the model learn faster on multiple few-shot algorithmic and question-answering tasks and achieve lower next-token prediction loss in out-of-distribution evaluation. On held-out code tasks, models with N=2 and N=4 reached baseline loss levels with 2.10× and 2.39× fewer context tokens, respectively. The authors position the work as a step toward improving the trade-off between in-context adaptation and decoding latency, rather than claiming that longer sleep is always better.

#sleep mechanism#in-context learning#Transformer#few-shot learning#sample efficiency#decoding latency
Share:

Related articles