Knowledge Circuits in Pretrained Transformers

Yunzhi Yao, Ningyu Zhang, Zekun Xi, Mengru Wang, Ziwen Xu, Shumin Deng, Huajun Chen

Abstract

While previous research focused on isolated "knowledge neurons," this study identifies Knowledge Circuits—specialized subgraphs of attention heads and multilayer perceptrons (MLPs) that collaborate to retrieve and process facts. By analyzing these circuits, we gain insights into the mechanics of factual recall, the causes of hallucinations, and the limitations of current model-editing techniques. This framework moves beyond identifying where information is stored to understanding the logistics of how it is retrieved and utilized.

Introduction: Beyond Knowledge Neurons

For years, the interpretability community has largely adhered to the "Knowledge Neuron" thesis, which posits that factual information is stored within specific Multilayer Perceptrons (MLPs) acting as key-value memories. However, this view is increasingly seen as an oversimplification. While MLPs may store components of a fact, they do not operate in a vacuum.

This research introduces the concept of Knowledge Circuits—the holistic computation graphs that move information from a subject token to the final prediction. By identifying these circuits, researchers can better diagnose why models hallucinate and why current model-editing techniques often lead to overfitting or "broken" logic.

Methodology

The authors developed a framework to discover and categorize these circuits using two primary techniques:

  1. Circuit Discovery via Causal Mediation: To find the circuit for a specific fact (e.g., "The official language of France is..."), the researchers systematically "knock out" (zero ablate) edges and nodes in the model's computation graph. If removing a component significantly degrades the model's ability to predict the correct answer ("French"), that component is identified as a critical node in the Knowledge Circuit.
  2. Information Analysis (Logit Lens): Once a circuit is identified, the "Logit Lens" is used to map internal hidden states at various layers directly into the vocabulary space. This allows researchers to visualize the "evolution" of a prediction as it moves through the model.

Functional Roles

The study categorizes components into specific functional roles:

  • Relation Heads: These process the specific relationship requested (e.g., "official language").
  • Mover Heads: These extract the relevant information from the subject's position and move it to the final token for prediction.

Experimental Setup and Datasets

The study evaluated GPT-2 (Medium and Large) and TinyLLAMA using the LRE (Logit-based Relation Extraction) dataset. The researchers sampled 47 different relations across four distinct categories:

  • Factual: (e.g., Capital City, Landmark Country)
  • Commonsense: (e.g., Fruit Inside Color, Object Superclass)
  • Linguistic: (e.g., Antonyms, Verb Past Tense)
  • Bias: (e.g., Occupation Gender, Name Religion)

Key Insights

Knowledge as a Distributed Process

Factual recall is a "team sport." It involves a sophisticated flow where earlier layers aggregate information about the subject, and later layers—specifically Mover Heads—extract that information to make the final prediction. The study found that circuits containing less than 10% of the model's total computation graph can maintain over 70% of the original performance on factual tasks.

The "Noise" Factor

Intriguingly, isolated knowledge circuits sometimes outperform the full model. For instance, on the "Landmark-country" task, the isolated circuit achieved a Hit@10 of 0.36, compared to the full model's 0.16. This suggests that much of the model's remaining architecture acts as "noise" that can interfere with specific factual recall.

Hallucination as a Routing Error

The authors discovered that during hallucinations, the correct information is often present in the model's earlier layers. The failure occurs because the "Mover Head" either fails to activate or incorrectly selects the wrong information to move to the output. This suggests that hallucinations are often routing failures rather than a lack of underlying knowledge.

The Mechanics of Model Editing

When using tools like ROME to edit a model, the underlying circuit changes. An edit typically shifts the behavior of a Mover Head, forcing it to extract the newly edited information from the subject's position. However, the researchers noted that simple fine-tuning (FT-M) often "overfits" by writing a signal into the very first layer, causing the model to output the edited answer even when the prompt is unrelated. This demonstrates that the edit did not update the knowledge so much as it broke the circuit's logic.

In-Context Learning (ICL)

During In-Context Learning, the model does not just rely on its static internal memory; it builds new circuits on the fly. These dynamic circuits often utilize "Induction Heads" that look back at provided examples to identify and replicate patterns, showing the flexibility of the Transformer architecture.

Limitations and Future Directions

While the Knowledge Circuit framework is powerful, it faces several challenges:

  • Computational Cost: Finding circuits via ablation is extremely time-consuming, often taking days for medium-sized models.
  • Granularity: The current study treats entire attention heads and MLP blocks as single units; future work could investigate individual neurons.
  • The Logit Lens Gap: Mapping intermediate layers to the final vocabulary is an imperfect representation, as the model's internal representation may shift significantly between layers.

Ultimately, the authors suggest that these circuits could be used to build "circuit breakers" to prevent models from outputting biased or harmful information by targeting the specific subgraphs responsible for those behaviors.

Summary updated

BibTeX
@inproceedings{yao2024knowledge,
  author = {Yunzhi Yao and Ningyu Zhang and Zekun Xi and Mengru Wang and Ziwen Xu and Shumin Deng and Huajun Chen},
  title = {{Knowledge Circuits in Pretrained Transformers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=YVXzZNxcag},
}
Figure