TokMem: Tokenized Procedural Memory for Large Language Models

Zijun Wu, Yongchang Hao, Lili Mou · DOI

Abstract

Large Language Models (LLMs) are typically steered via long, redundant prompts that consume context window and compute. TokMem introduces a modular framework that compresses complex task instructions into a single, trainable "procedural memory" token. By keeping the LLM backbone frozen and using these tokens to steer generation, TokMem achieves constant-size overhead, avoids catastrophic forgetting across over 1,000 tasks, and enables efficient multi-step tool use.

Introduction

Modern Large Language Models (LLMs) are primarily controlled through prompting. While effective, long prompts suffer from three major flaws:

  1. Efficiency: Self-attention scales quadratically with sequence length. Long instructions consume significant compute and shrink the available context window for actual data.
  2. Redundancy: Frequently used procedures (e.g., "format this as a JSON") are re-processed as raw text every time, forcing the model to re-interpret instructions rather than executing a known skill.
  3. Interference: Fine-tuning a model to learn new tasks often leads to "catastrophic forgetting," where new knowledge overwrites existing skills.

The authors distinguish between declarative memory (facts retrieved via RAG) and procedural memory (skills or "how-to" knowledge). They argue that current models treat procedures like facts, leading to a "slow interpretation" problem. TokMem addresses this by "compiling" instructions into specialized tokens.

Methodology: One-Token Procedural Memory

TokMem (One-Token Procedural Memory) replaces lengthy instructions with a single, trainable "memory token" ($m_i$) added to the model's vocabulary for each specific task.

Overview of TokMem encoding and inference procedures.

Encoding and Inference

During training, the LLM backbone remains frozen. Only the embedding of the new memory token is updated. The training sequence follows an "infix" layout: [Query] + [Memory Token] + [Response]. The authors found that placing the memory token after the query allows it to better condition its behavior on the specific details of the query.

At inference, the model analyzes the query and predicts which memory token to "recall" from its memory bank. To prevent newly trained tokens from "overpowering" older ones—a phenomenon known as norm inflation—a lightweight renormalization step rescales new embeddings to match the magnitude of existing ones.

Compositional Chaining

For complex tasks, TokMem can chain tokens. For example, a "parse" token might generate an intermediate thought, which then triggers a "search" token, followed by a "format" token. This modularity allows the model to solve multi-step problems by composing atomic skills.

Experimental Evaluation

The researchers evaluated TokMem across several diverse benchmarks, including Super-Natural Instructions (SNI) for atomic recall, APIGen for function-calling and compositional recall, and GSM8K for mathematical reasoning.

Performance comparison of TokMem against baselines across different model sizes and training sample counts.

Key Results

  • Scaling to 1,000 Tasks: On the SNI benchmark, TokMem maintained a routing accuracy of over 94% even when managing 1,000 different tasks. It consistently outperformed RAG and LoRA, which often suffer from noise and forgetting, respectively.
  • Efficiency: TokMem matches or exceeds the performance of Parameter-Efficient Fine-Tuning (PEFT) while using significantly fewer trainable parameters. For instance, it uses approximately 0.2M parameters compared to 3.41M for LoRA on a Llama 8B model.
  • Tool Use: In APIGen tests, TokMem achieved near-perfect tool selection (99.1% Avg F1) and significantly higher argument generation accuracy than In-Context Learning (ICL) or RAG.

Discussion and Conclusion

TokMem demonstrates that treating task instructions as "compiled skills" rather than textual data significantly improves LLM efficiency and scalability. Because the backbone is frozen and each task has its own token, adding new tasks has zero impact on the performance of previously learned ones, effectively solving the catastrophic forgetting problem.

However, some limitations remain. Currently, procedures must be manually defined or curated in the training data. Future research could explore using "teacher LLMs" to automatically decompose complex queries into procedural tokens. Additionally, there may be an upper limit to the procedural complexity a single vector can represent. Despite these challenges, TokMem provides a promising path toward more efficient and modular LLM architectures.

Summary updated

BibTeX
@inproceedings{wu2026tokmem,
  author = {Zijun Wu and Yongchang Hao and Lili Mou},
  title = {{TokMem: Tokenized Procedural Memory for Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=RWjEf9PdiJ},
}
Figure