Towards Understanding Fine-Tuning Mechanisms of LLMs via Circuit Analysis

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

TL;DR

This paper uses Mechanistic Interpretability to peek inside Large Language Models (LLMs) during the fine-tuning process, specifically focusing on mathematical tasks where pre-trained models initially struggle. The authors discover that fine-tuning primarily rewires the connections (edges) between model components rather than changing the components (nodes) themselves. Leveraging this insight, they introduce CircuitLoRA, a more efficient fine-tuning method that dynamically allocates parameters to the most heavily rewired layers, boosting accuracy by an average of 2.46% over standard LoRA.

What Problem Does This Paper Address?

Fine-tuning is the standard way to adapt pre-trained LLMs to specific tasks, but how the model actually updates its internal representations remains a bit of a black box. Mechanistic Interpretability (MI) attempts to solve this by reverse-engineering models into "circuits"—computational subgraphs of nodes (model components like attention heads) and edges (information flow between them).

Overview of the circuit analysis framework during fine-tuning.

Previous MI studies on fine-tuning mostly looked at tasks the pre-trained model was already good at. In those cases, fine-tuning just seemed to add a few minor components to existing circuits. But what happens in a more realistic scenario where the pre-trained model initially performs poorly and has to genuinely learn a new domain? This paper addresses that gap by tracking how circuits evolve when an LLM is fine-tuned on challenging mathematical tasks, and then uses those insights to build a better fine-tuning algorithm.

Methods

  • Circuit Discovery: The authors use Edge Attribution Patching with Integrated Gradients (EAP-IG) to identify circuits at various checkpoints during the fine-tuning process. They evaluate these circuits based on faithfulness (how well the circuit's output matches the full model's output) and robustness (how stable the circuit is when the input data is perturbed).
  • CircuitLoRA: Standard Low-Rank Adaptation (LoRA) applies the same rank (parameter budget) across all targeted layers. The authors propose CircuitLoRA, a two-phase method. First, it identifies "Critical Layers" by finding the edges that change the most during fine-tuning. Second, it assigns higher-rank LoRA modules to these highly active layers and standard-rank modules to the rest.
  • Union Circuits: To study complex, multi-step reasoning, the authors approximate the circuit of a compositional task (e.g., subtract, then multiply) by simply merging the circuits of its primitive subtasks, creating a "Union Circuit."

Datasets

Because the authors needed tasks where pre-trained models fail but fine-tuned models succeed, they built a custom suite of mathematical datasets:

  • Addition and Subtraction (Add/Sub): Ranging from numbers within 100 up to 500.
  • Multiplication and Division (Mul/Div)
  • Arithmetic and Geometric Sequences
  • Least Common Multiple (LCM)
  • Function Evaluation: Computing values for linear functions ($y = mx + b$).
  • Compositional Tasks: Two-step operations combining the above (e.g., (61 - 45) * 45 =).

Key Insights and Ideas

  • Fine-tuning is about rewiring, not rebuilding: The most surprising finding is that fine-tuning induces massive structural changes to the edges of a circuit, while the nodes remain relatively static. Edge change rates were consistently 2 to 4 times higher than node change rates. Fine-tuning reorganizes how existing components talk to each other.
Evolution of circuits showing higher change rates for edges compared to nodes.
  • Circuits converge as the model learns: By tracking checkpoints, the authors observed that as the model's accuracy improves, the number of node and edge modifications decreases. The circuit physically stabilizes as the model masters the task.
  • Interpretability can directly improve efficiency: MI is often used just for post-hoc analysis. This paper proves MI can be used proactively. By knowing where the model wants to rewire itself (the Critical Layers), we can allocate our parameter budget more effectively during Parameter-Efficient Fine-Tuning (PEFT).
  • Circuits are composable: You don't necessarily need to extract a massive, complex circuit for a multi-step task. The "Union Circuit" (combining the Add circuit and the Multiply circuit) is highly faithful to the true compositional circuit, meaning LLMs handle complex tasks by chaining together modular, primitive circuits.

Key Results

  • CircuitLoRA Outperforms Baselines: Across five mathematical tasks, CircuitLoRA achieved an average performance improvement of 2.46% over standard LoRA with comparable parameter sizes. For example, on the Add/Sub (within 300) task, CircuitLoRA hit 83.10% accuracy compared to standard LoRA's 80.50%.
  • High Faithfulness: The circuits discovered by EAP-IG consistently captured over 80% of the full model's performance across most tasks, proving they are accurate representations of the model's internal logic.
  • Union Circuit Efficiency: On compositional tasks, a Union Circuit using just the top 5% of edges from its subtasks successfully recovered 89.2% of the model's behavior. Furthermore, using Union Circuits to guide CircuitLoRA achieved 65.50% accuracy on two-step tasks, beating standard LoRA (64.70%) without needing to run expensive circuit discovery on the complex task itself.

Limitations and Future Work

  • Domain Specificity: The study relies entirely on mathematical and arithmetic tasks. The authors acknowledge that it remains to be seen if these specific circuit dynamics (like the heavy reliance on edge rewiring) generalize to other domains like creative writing, coding, or logical QA.
  • Complexity of Composition: The compositional experiments were limited to two-step arithmetic.
  • Future Work: The authors suggest applying these circuit-based methods to a wider variety of tasks to validate their generality, and extending the compositional analysis to multi-step tasks to better understand deep circuit interactions.

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