DOCS: Quantifying Weight Similarity for Deeper Insights into Large Language Models

Zeping Min, Xinshang Wang

Abstract

Understanding the internal mechanics of Large Language Models (LLMs) often relies on analyzing internal representations—the activations produced during inference. However, these representations can be misleading due to residual connections that mask the unique logic of individual layers. This paper introduces DOCS (Distribution of Cosine Similarity), a novel metric designed to measure the similarity of weight matrices directly. By applying Extreme Value Theory to fit neuron-wise similarities to a Gumbel distribution, DOCS provides a discriminative tool that reveals functional layer clustering and structural patterns invisible to traditional metrics like CKA or CCA.

Introduction

To interpret how LLMs process information, researchers typically examine "representations"—the thoughts or activations a model generates. The authors of this study argue that this approach has significant limitations. Because residual connections allow data to bypass layer logic, two layers may produce nearly identical outputs despite having entirely different internal weights.

Furthermore, existing analytical tools such as Centered Kernel Alignment (CKA) or Canonical Correlation Analysis (CCA) suffer from a mathematical "blind spot": they are non-discriminative for orthogonal matrices. Since many modern LLMs utilize orthogonal initialization or maintain near-orthogonality during training, these tools often produce noisy, low-resolution heatmaps that obscure the model's true structural organization. DOCS is proposed as a mathematically robust alternative that looks directly at the weights to provide higher sensitivity.

Methodology

DOCS measures the similarity between two weight matrices $W$ through a four-step statistical framework:

  1. Compute Pairwise Cosine Similarities: The metric calculates the cosine similarity between every possible pair of column vectors (neurons) between two matrices.
  2. Extract Maximums: For each neuron in the first matrix, the algorithm identifies the single neuron in the second matrix with which it aligns most strongly.
  3. Fit a Gumbel Distribution: Rather than simple averaging, which is susceptible to outlier noise, the authors fit the maximum similarity values to a Gumbel distribution. This is a technique from Extreme Value Theory used to model the behavior of maximums.
  4. Calculate the Index: The "location parameter" ($u$) of the resulting Gumbel distribution serves as the final similarity index.

This approach is formally proven (Theorem 1) to distinguish between orthogonal matrices where previous methods would fail, making it a more precise instrument for architectural analysis.

Experimental Setup

The researchers evaluated DOCS across several prominent open-source LLM families, focusing on their weight structures rather than text datasets:

  • Meta-Llama: Llama 3.1 (8B, 70B, and Instruct variants).
  • Google Gemma: Gemma-2 (9B and 27B).
  • Mistral/Mixtral: Mistral-7B and Mixtral-8x7B (Mixture-of-Experts).
  • 01-ai Yi: Yi-1.5-9B.

Key Insights and Results

Weights vs. Activations

The study demonstrates that representation similarity is consistently higher than weight similarity across all tested models. This confirms the hypothesis that residual connections "mask" the specific transformations occurring within individual layers. DOCS allows researchers to see past this mask to the actual logic encoded in the weights.

Functional Layer Clustering

DOCS reveals that LLMs are not uniform stacks of layers. Instead, they organize into "functional clusters." For example, in Llama 3.1-8B, layers 7–12 exhibit high internal similarity, suggesting they function as a collective unit for a specific stage of processing. Additionally, many models show a "U-Turn" pattern where the first and last layers are highly similar, likely due to their shared proximity to the token embedding space.

The Impact of Instruction Tuning

When comparing base models to their instruction-tuned counterparts, DOCS scores remain remarkably high (often >0.7). This suggests that instruction tuning is a relatively "light" process that does not fundamentally re-wire the model’s knowledge base, but rather fine-tunes the existing foundational structure.

Sensitivity and Pattern Recognition

DOCS proved significantly more sensitive than traditional metrics. On Llama 3.1-8B, DOCS achieved a Gini coefficient of 0.0745, compared to 0.0488 for Linear CKA. This higher sensitivity allowed the researchers to uncover hidden patterns, such as in the Yi-1.5-9B model, where Layer 9 was found to be nearly identical to Layer 25—a repetition that was completely invisible to activation-based analysis.

Mixture-of-Experts (MoE) Dynamics

In MoE models like Mixtral, DOCS identified that specific experts within a layer often diverge significantly from their peers. This "odd one out" phenomenon is likely a result of data load imbalances during the training process, where certain experts specialize in ways others do not.

Conclusion and Future Work

DOCS provides a new lens for understanding the structural composition of LLMs. By focusing on weights rather than activations, it reveals a more granular view of how models are organized and how they change during fine-tuning. While currently limited to decoder-only architectures, the metric's ability to identify redundant or highly similar layers suggests significant potential for future applications in model pruning and compression. Future research may extend this framework to encoder-decoder models and explore automated methods for optimizing model depth based on DOCS clusters.

Summary updated

BibTeX
@inproceedings{min2025docs,
  author = {Zeping Min and Xinshang Wang},
  title = {{DOCS: Quantifying Weight Similarity for Deeper Insights into Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=XBHoaHlGQM},
}
Figure