TL;DR
This paper applies "zigzag persistence," a technique from Topological Data Analysis (TDA), to track how Large Language Models (LLMs) dynamically rearrange prompt representations across their layers. By tracking the birth and death of topological features, the authors identify four distinct phases of information processing and demonstrate that this geometric insight can be used to effectively prune redundant model layers with minimal performance loss.
The Problem: Static Snapshots of a Dynamic Process
Despite the massive success of LLMs, their internal decision-making processes remain largely a black box. While previous research has studied the geometry of LLM internal representations (e.g., by measuring intrinsic dimension), these approaches typically evaluate each layer in isolation. They provide a static snapshot but fail to capture the dynamic trajectory of how data points (prompts) move and change their relative positions as they flow continuously through the network's depth.
The authors tackle this gap by treating the sequential layers of an LLM as a discrete time series. They aim to understand not just what a representation looks like at layer 10 versus layer 20, but exactly how the structural relationships between prompts evolve to get there.
Methods: Zigzag Persistence
To track these dynamic changes, the authors utilize zigzag persistence, a specialized TDA framework designed for time-varying point clouds.
- Point Cloud Generation: They extract the hidden state embeddings of the last token of various prompts at every layer of the model.
- Filtration: At each layer, they construct a $k$-Nearest Neighbors (kNN) graph to connect nearby prompt embeddings.
- Zigzag Persistence: Unlike standard persistent homology, which looks at a single static dataset at different scales, zigzag persistence tracks topological features—specifically $p$-dimensional "holes" or loops—as they are born and die across layers.
- Topological Descriptors: They introduce two novel metrics to summarize this complex data:
- Births' Relative Frequency: Measures the rate at which new topological features are created, indicating how aggressively the model is rearranging prompts.
- Inter-Layer Persistence: Measures how long features survive across multiple layers, indicating phases of representational stability.
Key Insights: The 4 Phases of LLM Processing
By tracking short-lived and long-lived topological features across diverse datasets (SST, The Pile, MATH, GitHub Code), the authors discovered that LLMs process information in four distinct phases:
- Early to Middle Layers (Rapid Rearrangement): A massive number of short-lived features are born, indicating the model is quickly shifting prompts around, likely for local contextualization.
- Middle Layers (Stable Relationships): Long-lived features peak here. The relative positions of prompts become stable, suggesting the formation of semantic abstractions.
- Middle to Late Layers (Refinement): Long-lived features persist, but the creation of new short-lived features plateaus. The model is making minor adjustments rather than massive structural changes.
- Last Layers (Final Output Preparation): A sudden spike in new feature births and a drop in persistence indicates a final, abrupt rearrangement of points to predict the next token.
Topological Universality: These four phases appeared consistently across different model architectures (Llama 2, Llama 3, Mistral, Pythia) and datasets, suggesting a fundamental, universal mechanism in how transformer models compute.
Application: Principled Layer Pruning
Because the "Middle to Late" phase (Phase 3) consists mostly of stable features and minor adjustments, the authors hypothesized that layers in this phase contribute the least to overall performance and are prime candidates for pruning.
They designed a pruning criterion based on their TDA metrics, specifically targeting layers in the Phase 3 plateau (where Inter-Layer Persistence of short-lived features is within 10% of its maximum).
This zigzag-based pruning strategy achieved results comparable to state-of-the-art similarity-based pruning methods. For example, when pruning 9 layers from Llama 3 8B, their method maintained a 70.00% accuracy on the Winogrande benchmark (compared to 77.10% unpruned). This exactly matches the performance retention of competing methods while offering a more principled, system-level geometric justification for why those layers are safe to cut.
Limitations and Future Work
The authors acknowledge that defining the criterion for connecting points (the kNN graph and the choice of $k$) is delicate. Furthermore, the current framework only analyzes static, pre-trained models. A highly promising future direction is applying zigzag persistence to track the evolution of internal representations during the training process to gain insights into learning dynamics. Finally, dataset anomalies, such as divergent topological behavior in code datasets compared to natural language, warrant further investigation.
Summary updated