Transmuting prompts into weights

Hanna Mazzawi, Benoit Dherin, Michael Munn, Michael Wunder, Javier GonzalvoarXiv 2025 · DOI

Abstract

Researchers from Google Research have introduced Thought Patching, a theoretical framework designed to "distill" text instructions directly into a large language model's (LLM) weights. By mathematically transmuting prompts into reusable "thought vectors" and "thought matrices," the method provides a formal justification for popular heuristic methods like activation steering and model editing. This approach allows models to internalize instructions, enabling them to follow complex directives without requiring the original prompt at inference time.

1. Introduction

Controlling LLMs typically falls into two categories: Prompt Engineering (crafting specific text instructions) and Direct Intervention. Direct interventions include activation steering (adding "steering vectors" to internal states) and model editing (modifying weight matrices to update facts).

While effective, these interventions have historically been empirical—used because they work rather than because their underlying mathematics are fully understood. For example, the common practice of averaging the difference between "happy" and "sad" activations to create a sentiment steering vector has lacked a first-principles theoretical foundation. This paper addresses this gap by connecting textual instructions to specific, permanent changes in a model’s architecture.

2. Methodology: Thought Patching

The authors introduce the Thought Patching algorithm, which conceptualizes a prompt's influence as an "implicit weight update." The goal is to move from token-dependent patches to "thought patches"—reusable, constant updates consisting of a thought vector ($\delta(I)$) and a thought matrix ($\Delta(I)$).

Algorithm 1: The Thought Patching procedure for distilling instructions into model weights.

As detailed in Algorithm 1, the process involves two primary forward passes to "bake" an instruction $I$ into a model:

  1. Contextual Pass: The model processes the full prompt (Instruction + Input) to establish "ground truth" internal activations.
  2. Non-Contextual Pass: The model processes only the Input using the current patched weights.
  3. Optimization: The discrepancy between these two passes is calculated. The thought vector is derived from the mean of these discrepancies, while the thought matrix is found by solving a least-squares minimization problem.

For modern architectures like Gemma, the authors adapted this by "absorbing" updates into specific projection weights ($W_{up}$, $W_{gate}$, and $W_{down}$) to ensure architectural compatibility.

3. Experimental Evaluation

The researchers evaluated Thought Patching across several task types to test its versatility:

  • Arithmetic: Simple single-digit multiplication and summation tasks.
  • Detoxification: Using the ParaDetox dataset to transform toxic sentences into neutral ones.
  • Linguistic & Knowledge Tasks: French/Spanish-to-English translation and Country-to-Capital factual retrieval.
  • New Knowledge Integration: A synthetic dataset of key-value pairs to test if the model could learn entirely new information not present in its pre-training.

4. Key Results

The experimental results demonstrate that patched models can match or even exceed the performance of models using explicit prompts.

Comparison of detoxification performance between the original model with context and the patched model without context.

In the detoxification task (Figure 3), the patched model achieved a toxicity score of 6.22%, which was slightly lower (better) than the 6.7% achieved by the original model with an explicit "please detoxify" prompt. In arithmetic tasks, the patched model achieved 100% accuracy, reaching parity with full-context prompting using as few as 10 examples. Furthermore, the method successfully injected synthetic dictionaries of up to 32 pairs with 91-100% accuracy, proving the weights can absorb entirely new, non-latent information.

5. Theoretical Insights

Beyond performance, the paper provides several key justifications for existing steering techniques:

  • Steering Justification: The common heuristic of averaging contrastive activations is mathematically proven to be the least-squares approximation of the optimal thought vector.
  • Low-Rank Edits: The authors show that optimal weight updates naturally emerge as a sum of rank-one matrices, providing a formal theoretical backbone for popular editing techniques like ROME.
  • Internalization: Once the weights are patched, the model behaves as if the instruction is present, effectively internalizing the prompt into its parameters.

6. Limitations and Future Work

Despite its success, Thought Patching is currently sensitive to syntactic overfitting. If the evaluation prompt is phrased differently than the prompts used during the patching phase, performance can drop significantly. Future work will focus on improving robustness through advanced regularization and exploring how these patches scale to highly complex, multi-step reasoning instructions.

7. Conclusion

By transmuting prompts into weights, Thought Patching offers a bridge between prompt engineering and model fine-tuning. This framework not only explains the success of current steering methods but also provides a scalable way to bake instructions and new knowledge directly into LLMs, reducing inference-time overhead while maintaining high precision.

Summary updated

BibTeX
@misc{mazzawi2025transmuting,
  author = {Hanna Mazzawi and Benoit Dherin and Michael Munn and Michael Wunder and Javier Gonzalvo},
  title = {{Transmuting prompts into weights}},
  year = {2025},
  eprint = {2510.08734},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.08734},
}
Figure