Towards Understanding Fine-Tuning Mechanisms of LLMs via Circuit Analysis

Xu Wang, Yan Hu, Wenyu Du, Reynold Cheng, Benyou Wang, Difan Zou

TL;DR

Researchers have used Mechanistic Interpretability to peek under the hood of LLM fine-tuning, discovering that the process primarily "rewires" existing connections (edges) rather than creating new components (nodes). By leveraging these insights, they developed CircuitLoRA, a fine-tuning method that achieves significantly higher accuracy and parameter efficiency by prioritizing layers where the most internal "circuit" changes occur.

What Problem Does This Paper Address?

While fine-tuning is the standard way to adapt Large Language Models (LLMs) to specific domains, we still treat it largely as a "black box." We know it works, but we don't fully understand how the model’s internal machinery changes to acquire new skills.

Previous studies in Mechanistic Interpretability (MI) often focused on tasks where models were already proficient (e.g., the Indirect Object Identification task). This paper tackles a more practical and challenging scenario: How does a model evolve when it starts with near-zero accuracy on a task and must be fine-tuned to succeed? The authors specifically look at mathematical reasoning, where pre-trained models often struggle but show massive gains after targeted training.

Methods

The authors employ Circuit Analysis to identify the specific subgraphs (circuits) within the model responsible for a task.

  1. Circuit Discovery: They use Edge Attribution Patching with Integrated Gradients (EAP-IG). This technique identifies which "edges" (information flows between attention heads and MLPs) are most critical for a specific output.
  2. CircuitLoRA: Based on the observation that certain layers undergo more structural changes than others, the authors proposed an adaptive version of Low-Rank Adaptation (LoRA). Instead of giving every layer the same rank, CircuitLoRA identifies "Critical Layers" (those with the most edge score changes) and assigns them higher ranks, while keeping ranks lower for stable layers.
  3. Union Circuits: For complex, multi-step tasks (e.g., (61 - 45) * 45), they tested whether the circuit for the whole task could be approximated by simply combining the circuits of the individual subtasks (subtraction and multiplication).
Figure 1. The workflow of understanding fine-tuning mechanisms using circuits. The initial pre-trained model shows low accuracy on tasks. The corresponding circuits were found in both the pre-trained model and the fine-tuned model, and the fine-tuning mechanism was understood by comparing the changes in the circuits before and after.

Datasets

The study focuses on five challenging mathematical benchmarks where pre-trained models (like Pythia-1.4B and GPT-Neo-2.7B) initially perform poorly:

  • Addition and Subtraction (Add/Sub): Categorized by number ranges (100 to 500).
  • Multiplication and Division (Mul/Div): 2,000 instances of basic operations.
  • Arithmetic and Geometric Sequences: Recognizing and extending patterns.
  • Least Common Multiple (LCM): Calculating the LCM of two integers.
  • Function Evaluation: Computing values for linear functions ($y = mx + b$).

Key Insights and Ideas

  • Latent Potential: Surprisingly, pre-trained models already contain "latent" circuits for tasks they fail. Even when accuracy is near zero, the identified circuits are highly robust and faithful to the model's (incorrect) behavior, providing a stable foundation for fine-tuning.
  • Rewiring vs. Rebuilding: The most significant "aha" moment is that fine-tuning is an edge-centric process. While the nodes (the components like attention heads) remain largely the same, the edges (the connections between them) undergo massive reconfiguration. Edge change rates were 2–4x higher than node change rates across all tasks.
  • Structural Convergence: As the model’s accuracy improves, its internal circuits stabilize. The number of modifications to the circuit decreases over time, suggesting the model is "settling" into a specialized structure.
  • The Power of the Union: For compositional tasks, the "Union Circuit" (the combined edges of subtask circuits) recovered nearly 90% of the model's behavior. This suggests that complex reasoning in LLMs is modular and can be understood by breaking it down into simpler, discovered primitives.
Figure 3. The structural differences of Add/Sub(100) circuit (24 layers) and evolution of circuits across checkpoints in terms of node and edge changes. Left: Differences of Add/Sub(100) circuit before and after fine-tuning. The layout organizes nodes hierarchically from input to output (logits). Nodes and edges are color-coded based on their status: added (blue), removed (red), or unchanged (grey/white). Darker grey nodes indicate higher degrees. Top Right: Node and edge changes between checkpoints during fine-tuning in three tasks. The left chart depicts the number of node changes per transition, while the right chart focuses on edge changes. Bottom Right: Change rate of Add/Sub, Sequence, LCM three tasks. Bars with diagonal lines represent the change rate of edges.

Key Results

  • Superior Efficiency: CircuitLoRA consistently outperformed standard LoRA. For example, on the "Add/Sub within 300" task, CircuitLoRA achieved 82.70% accuracy, significantly higher than standard LoRA (78.30%) despite using a similar parameter budget.
  • Performance Boost: Across all five math tasks, the circuit-aware approach provided an average performance improvement of 2.46% over standard baselines.
  • Compositional Success: In two-step operation tasks, using the Union Circuit to identify critical layers for fine-tuning resulted in a 65.50% accuracy, beating standard LoRA configurations (which hovered around 60-61%) with the same number of parameters.
Table 1. Performance metrics for Add/Sub (within 300) and four other math tasks: Mul/Div, Sequence, LCM, and Function across different configurations. The control groups of CircuitLoRA (ro = 8, rc = 32) are LoRA (ro = 16) and RandomLoRA (ro = 8, rc = 32), and the control groups of CircuitLoRA (ro = 16, rc = 64) are LoRA (ro = 32) and RandomLoRA (ro = 16, rc = 64). Here, ro and rc represent the ranks used in CircuitLoRA, where rc is the rank for critical layer modules, and ro is the rank for non-critical layer modules. Model Accuracy is expressed as percentages.

Limitations and Future Work

While groundbreaking, the study has a few boundaries:

  • Task Domain: The research is heavily focused on mathematical tasks. Whether these "edge-rewiring" mechanisms hold true for linguistic style transfer or factual knowledge updates remains to be seen.
  • Compositional Depth: The authors only explored two-step compositions. Real-world reasoning often involves many more steps, and it's unclear if the "Union Circuit" approach scales to deeper chains of thought.
  • Model Scale: While they tested models up to 6.7B parameters, the dynamics might shift in "frontier" models (100B+ parameters) where emergent behaviors are more pronounced.

The authors suggest that future work should extend this analysis to more diverse tasks and explore how these circuit insights can be used to detect and mitigate "knowledge conflicts" during fine-tuning.

Summary updated

BibTeX
@inproceedings{wang2025towards,
  author = {Xu Wang and Yan Hu and Wenyu Du and Reynold Cheng and Benyou Wang and Difan Zou},
  title = {{Towards Understanding Fine-Tuning Mechanisms of LLMs via Circuit Analysis}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=45EIiFd6Oa},
}
Figure