Shuai He1, Guoheng Sun1, Haichao Zhang2, Yun Fu2, Ang Li1
1University of Maryland, College Park, 2Northeastern University
📄 Paper • 🌐 Project Page • 📦 Structure • ⚙️ Environment • 🔍 Scripts • 🧪 Metrics
Codebase for representation-hierarchy analysis of pruning in LLMs.
Figure 1: Overview. This repo studies pruning through a representation hierarchy (`h → z → p`) and compares dense vs dropped/pruned behaviors.
Pruning often preserves non-generative metrics while revealing much larger differences across representation spaces during generation. This repo studies that discrepancy through a representation hierarchy:
- Embedding space (
h): hidden states - Logit space (
z): pre-softmax outputs - Probability space (
p): post-softmax distributions
We provide analysis code for both inter-layer dropping (layer/block drop) and intra-layer sparsification (Wanda/SparseGPT), and paper-aligned scripts that quantify how pruning perturbs h → z → p across layers and decoding steps.
What You Can Run Here
- Inter-layer pruning (layer / block drop)
- Intra-layer pruning (Wanda / SparseGPT)
- Representation-level analysis in
droppedandprunedmodes
Install from requirements.txt (recommended, pinned versions):
pip install -r requirements.txtinter-layer/: layer/block dropping pipeline.intra-layer/: intra-layer sparsification (Wanda / SparseGPT).representation-analysis/: paper-aligned analysis scripts for representation hierarchy.
Figure 5: After pruning, generation can degrade qualitatively when probability-space shifts alter the autoregressive trajectory.
|
Attention |
MLP |
Figure 2: Representation hierarchy under pruning. Layerwise representation similarity trends differ across embedding/logit/probability spaces (left: Attention, right: MLP).
representation-analysis/transition_layerwise_compare.py
# Dropped model
python transition_layerwise_compare.py \
--analysis_mode dropped \
--model_name Qwen/Qwen2.5-7B-Instruct \
--dropped_root_path /path/to/dropped_results \
--target_layer attn \
--drop_n 8
# Pruned model
python transition_layerwise_compare.py \
--analysis_mode pruned \
--model_name /path/to/dense_model \
--pruned_model_name /path/to/pruned_modelPurpose:
- Compare attn/mlp sublayer transitions at the same layer and same context.
- Log transition metrics in embedding/logit/probability spaces. For example:
- Embedding/hidden space (
h): cosine similaritycos(h_dense, h_pruned), and the parallel/orthogonal decomposition ofΔh = h_pruned - h_densew.r.t.h_dense. - Logit space (
z): cosine similaritycos(z_dense, z_pruned), plus the parallel/orthogonal decomposition ofΔz = z_pruned - z_densew.r.t.z_dense. - Probability space (
p): cosine similaritycos(p_dense, p_pruned)wherep = softmax(z/T), andKL(p_pruned || p_dense)(reported asREAL_KLin logs). - Second-order estimates (paper-aligned):
KL_estimateand1-cos_estimatecomputed from weighted variance terms with the1/(2T^2)scaling.
- Embedding/hidden space (
Theorem 1 (Local Deviation Induced by Pruning)
For cosine similarity in any representation space, the deviation induced by pruning can be approximately characterized via a second-order Taylor expansion (see Appendix C.1 in the paper).
Theorem 2 (Sensitivity of Probability Space to Logit Perturbations)
To compare probability-space and logit-space deviations on the same footing, we rewrite probability-space deviation in terms of the logit variable
Theorem 3 (Distributional Shift under Pruning)
In probability space, KL divergence is a standard measure of distributional shift under pruning. Based on the derivation in Appendix B, the pruning-induced KL can be approximated in a closed form.
|
Angular Deviation
|
KL Divergence
|
Figure 6: Example layerwise signals. Cosine similarity and KL divergence can show different sensitivity across spaces at the same layer (illustrative Attention layer).
|
Top Tokens
|
Categorical Tokens
|
Figure 7: Subspace vs global behavior. Comparing answer-option subspaces with full-vocabulary behavior reveals why some non-generative scores remain stable.
representation-analysis/compare_mcq_subspace_metrics.py
# Dropped model
python compare_mcq_subspace_metrics.py \
--analysis_mode dropped \
--model_name Qwen/Qwen2.5-7B-Instruct \
--dropped_root_path /path/to/dropped_results \
--target_layer attn \
--drop_n 8
# Pruned model
python compare_mcq_subspace_metrics.py \
--analysis_mode pruned \
--model_name /path/to/dense_model \
--pruned_model_name /path/to/pruned_modelPurpose:
- Compare global vocabulary-space behavior vs answer-option subspace behavior.
- Mirrors the non-generative subspace robustness discussion in the paper.
|
Embedding and Logits
|
Probability Space
|
Figure 8: Step-wise representation comparison during autoregressive decoding. Embedding/logit similarity can remain high while probability-space similarity (vocabulary distribution) shows larger deviation.
representation-analysis/compare_generation_metrics.py
# Dropped model
python compare_generation_metrics.py \
--analysis_mode dropped \
--model_name Qwen/Qwen2.5-7B-Instruct \
--dropped_root_path /path/to/dropped_results \
--target_layer attn \
--drop_n 8
# Pruned model
python compare_generation_metrics.py \
--analysis_mode pruned \
--model_name /path/to/dense_model \
--pruned_model_name /path/to/pruned_modelPurpose:
- Compare dense vs target trajectories across decoding steps.
- Report cosine/KL and second-order estimates tied to the paper’s Section 6 formulas.
- Inter-layer layer/block dropping is adapted from LLM-Drop
- Intra-layer pruning builds on Wanda and SparseGPT
If this repository helps your research, please cite the corresponding paper:
BibTeX:
@misc{he2026demystifyingpruningworksrepresentation,
title={Demystifying When Pruning Works via Representation Hierarchies},
author={Shwai He and Guoheng Sun and Haichao Zhang and Yun Fu and Ang Li},
year={2026},
eprint={2603.24652},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2603.24652},
}- Shwai He:
shwaihe@umd.edu



