Manuscript Offprint

arXiv:2610.17686

Encoding Context into LLM Weights: What Makes It Context?

Yue Wang, Qizhou Wang, Feng Liu, Gang Niu, Masashi Sugiyama, Bo Han

ABSTRACT

Longer contexts allow large language models (LLMs) to condition their predictions on more information, but inference costs grow prohibitively with context length. An emerging alternative uses test-time updates to encode context as temporary changes to model weights. However, encoding this information into weights that already represent general knowledge obscures its role as context, so the LLM may fail to use it properly to condition subsequent inference. To restore this contextual role, we first associate each context with an identifier during encoding, thereby distinguishing the newly encoded information from pre-existing knowledge. Invoking the identifier at inference then enables the LLM to recite the encoded context. Nevertheless, successful recitation does not ensure that the LLM will use the recalled information as context. We therefore further introduce a prompting framework that explicitly guides the LLM to use this information as context. Across diverse controlled tasks and practical benchmarks, our method outperformed the baseline using only off-the-shelf LLMs, showing its advances in context encoding.

1 INTRODUCTION

Large language models (LLMs) have advanced substantially in recent years (Brown et al., 2020; Grattafiori et al., 2024; Guo et al., 2025), and a key foundation of this progress is their expanding capacity to process long contexts (Gemini Team et al., 2024) and to scale inference-time computation (Muennighoff et al., 2025). The former allows LLMs to ingest larger volumes of diverse inputs, including elaborate prompts, documents, multimodal data, dialogue histories, and tool-interaction records (Achiam et al., 2023). The latter supports test-time scaling through extended reasoning trajectories involving iterative refinement and verification (Wei et al., 2022; Snell et al., 2024).

These benefits, however, come with limitations. As context grows, key-value (KV) cache memory scales linearly and causal attention computation scales quadratically, imposing prohibitive hardware demands and deployment costs (Pope et al., 2023). Models may also lose track of relevant information in longer contexts (Liu et al., 2024; Du et al., 2025), which has been linked to boundary-token biases (Hsieh et al., 2024b), limited length generalization (Zhong et al., 2025), and attention dispersion (Veličković et al., 2024). LLMs are therefore constrained by their input context windows, reaching only the million-token scale even in the most advanced models (Yang et al., 2025; OpenAI, 2026), while their effectively usable length can be shorter (Hsieh et al., 2024a; An et al., 2025).

Taken together, the above observations reveal a tension: LLMs benefit from consuming more tokens at inference, yet an ever-growing context eventually exhausts the available context window. This tension motivates recent work on test-time context encoding (TCE) (Chen et al., 2023; Sun et al., 2025; Tandon et al., 2025; Zhang et al., 2025b; Behrouz et al., 2025b; Feng et al., 2026; Charakorn et al., 2026), which encodes prior context through temporary weight updates rather than retaining it in the input (Figure 1). By encoding context without occupying KV cache positions, TCE can potentially mitigate the computational costs and performance degradation associated with long input contexts. Ideally, an LLM should condition its predictions on encoded information as reliably as if that information remained within its effective input window. Prior work has reported promising TCE gains using autoregressive encoding (Chen et al., 2023; Tandon et al., 2025; Chen et al., 2026), often

(a)

(b)

Figure

(c)

Figure 1: Comparison of (a) full-context inference, (b) encoded-context inference with meta-trained TCE, and (c) encoded-context inference with ACE. Full-context inference jointly processes c1:Tc_{1:T} and x, becoming infeasible when their combined length exceeds the input context window. TCE and ACE instead encode the chunks c1:Tc_{1:T} into LLM weights, illustrated here as FFN weights. Prior TCE methods often rely on additional meta-training-based fine-tuning, whereas ACE operates directly on off-the-shelf LLMs without such fine-tuning.

paired with additional meta-training-based fine-tuning, given its “learning to (learn at test time)” nature (Sun et al., 2025), to improve the use of encoded information.

However, additional meta-training can itself improve downstream performance, making it difficult to attribute the reported gains specifically to context encoding. This leaves open whether TCE can work effectively with off-the-shelf LLMs. Although autoregressive objectives can enable memorization (Chen et al., 2023), our experiments in Section 4 showed that TCE without such fine-tuning remained far inferior to full-context inference, which retains the context in the input. This gap highlights the distinction between memorization and contextual use, as also discussed in prior work (Eyuboglu et al., 2025; Chen et al., 2026). We therefore investigate how off-the-shelf LLMs can reliably use encoded information as context without such task-specific meta-training.

This problem is nevertheless challenging because newly encoded context and pre-existing general knowledge share the same weights, while current TCE objectives provide no explicit signal that distinguishes the encoded information as active context. This lack of distinction, in turn, makes the influence of such information on subsequent inference difficult to control, leaving it uncertain whether the resulting LLM behavior will be reliably conditioned on that context. To this end, we propose Addressable Context Encoding (ACE), which makes encoded context distinguishable from pre-existing knowledge through a simple addressing mechanism. Specifically, during encoding, we associate each context with a unique identifier (UID), such as a randomly generated alphanumeric string. At inference, invoking the relevant UIDs directs the LLM to recite the associated content, thereby providing an explicit access path to the encoded information. Moreover, going beyond mere recitation, we wrap this addressing mechanism in a flexible prompting framework (Kojima et al., 2022) that further guides the LLM to selectively use and reason over the encoded information when responding to subsequent requests (Figure 1), thus making its behavior more controllable.

We stress-tested ACE on controlled tasks covering various aspects of context use, observing substantial improvements over classical TCE. For example, on two such tasks, Recall and Recognition, ACE increased accuracy from 1.5% to 75.6% and from 0.0% to 98.0%, respectively, on Qwen3.5-27B (Qwen, 2026). These benefits extended to long-context benchmarks, including RULER (Hsieh et al., 2024a), widely used in prior TCE studies (Tandon et al., 2025; Feng et al., 2026), and the more challenging LONGBENCH (Bai et al., 2024) and LONGBENCH V2 (Bai et al., 2025), which have received less attention in this setting. With Muse-Glimmer-30B (Meta, 2026), ACE improved RULER NIAH-3 accuracy from 8% to 63% and LongBench answer F1 from 14.0 to 19.2.

References (100)

Couldn't load all references. Reload the page to try again.