Loss Landscape Analysis library version 1.3: embedding distribution analysis metrics

Nikita GabdullinarXiv 2026

TL;DR

Two neural networks can have nearly identical, "textbook-good" loss landscapes—flat, smooth, and seemingly primed to generalize—yet one scores 82% on new data while the other crashes to 56%. This paper introduces four embedding-distribution metrics in the Loss Landscape Analysis (LLA 1.3) PyTorch library that peek inside the model's latent space, revealing when train and test class clusters drift apart and diagnosing whether a failing model actually has a great encoder paired with a misaligned classification head.

What Problem Does This Paper Address?

For years, researchers have judged a neural network's ability to generalize by studying the geometry of its loss landscape—checking for flat minima and well-behaved Hessian eigenvalues. The Loss Landscape Analysis (LLA) library was built to automate exactly that.

But geometry doesn't tell the whole story. The author highlights a striking mystery: two ViT-S models trained on ImageNet-1K show almost identical, favorable loss landscapes and Hessian metrics, and their training accuracies differ by only 5%. Yet when evaluated on ImageNetV2 (a domain-shifted test set), their accuracies diverge by a massive 26% (82% vs. 56%). When the geometry looks fine, where does the generalization gap come from? The answer lies in how class embeddings are arranged in the latent space—and how they shift when the data changes.

Methods

To complement LLA's existing geometric tools (viz_lla and viz_esd), version 1.3 adds four embedding-distribution metrics:

  • Procrustes Analysis (orthogonal_procrustes): Finds the optimal rotation to align two distributions (e.g., train and test class means), then measures how different they remain using the normalized Procrustes residual ($P_{res}$, lower is better) and mean cosine similarity ($P_{cos}$, higher is better).
  • Mean Centroid Distance (compute_mcd): Measures cluster compactness—the average Euclidean or cosine distance between individual embeddings and their class mean. Smaller values mean tighter, cleaner clusters.
  • Inter Class Separation (compute_ics): Compares the arrangement of class means between two distributions by taking the Frobenius distance between their Gram matrices.
  • Inductive Margins (compute_inductive_margins): Computes each sample's margin $\delta_i$ (its cosine similarity to the correct class mean minus its maximum similarity to any wrong class mean). This yields the mean margin $\bar{\delta}$ and the fraction of positive margins $\rho$ (which equals Nearest Class Mean classifier accuracy).

Datasets

All experiments use ViT-S models evaluated under domain shift (different, but class-wise compatible, datasets for training and testing):

  • CINIC-10 $\to$ CIFAR-10: Models trained on 70,000 CINIC-10 images (with CIFAR-10 images removed) and tested on 10,000 CIFAR-10 test images.
  • ImageNet-1K $\to$ ImageNetV2: Two models pretrained on ImageNet-1K and tested on 10,000 ImageNetV2 images.

Key Insights and Ideas

  • Distribution divergence tracks the generalization gap: In the CINIC-10 $\to$ CIFAR-10 run, train and test embeddings start out nearly identical at initialization. As the model overfits, the generalization gap widens, and $ICS$ and $P_{res}$ spike while $P_{cos}$ drops. Later in training, as test accuracy slowly climbs in a "grokking"-like phase, the train and test distributions realign.
  • A bad score doesn't always mean a bad encoder: In the ImageNetV2 experiment, both models achieve remarkably high test-test $\rho$ (0.94 and 0.96). This means even the "failing" second model actually separates test classes into clean, distinct clusters! Its 56% accuracy isn't a feature-extraction failure—its classification head simply expects those clusters to sit in their training positions, which have shifted.
  • Equidistant guessing: The second model's train-test $\bar{\delta}$ is 0.01 ($\approx 0$), meaning test embeddings land roughly equidistant between at least two training class means, forcing the classifier to guess between semantically similar classes.

Key Results

  • CINIC-10 $\to$ CIFAR-10: At epoch 99, train accuracy hits 0.99 while test accuracy lags at 0.64 (a 0.35 gap), accompanied by $ICS = 0.58$, $P_{res} = 0.36$, and $P_{cos} = 0.93$. By epoch 999, test accuracy rises to 0.74 (shrinking the gap to 0.26), and alignment improves ($ICS = 0.56$, $P_{res} = 0.33$, $P_{cos} = 0.95$).
Figure 1: Change in train and test accuracies of ViT-S during training on Cinic-10 and testing on Cifar-10.
  • ImageNet-1K $\to$ ImageNetV2: The first model reaches 82% test accuracy (6% gap, $ICS = 0.29$, $P_{res} = 0.37$, $P_{cos} = 0.93$). The second model drops to 56% test accuracy (27% gap, $ICS = 0.46$, $P_{res} = 0.57$, $P_{cos} = 0.84$).
  • Frozen-Encoder Verification: To prove the second model's encoder was well-trained, the author froze it, replaced the classification head with a single fully-connected layer, and trained it on ImageNetV2 for 50 epochs—achieving 95% accuracy.
Figure 2: Finetuning a single classification layer on iv2 using frozen encoder of the second model (with the original classification head removed).

Limitations and Future Work

  • No peeking at test data: While retraining the classification head on ImageNetV2 proved the encoder's quality, training on test data is prohibited in practice. The open challenge is how to leverage these insights to improve the original model without test-set access.
  • Better margin losses: Because the failing model struggles with equidistant, semantically similar classes, the author suggests using loss functions that explicitly optimize inter-class margins (such as ArcFace) to push similar clusters further apart.
  • Idealized references: The default target in compute_ics is an Equiangular Tight Frame (ETF), which assumes all classes are equally separated—an idealization that rarely holds in real-world datasets where some classes are naturally more similar than others.

Summary updated

BibTeX
@misc{gabdullin2026loss,
  author = {Nikita Gabdullin},
  title = {{Loss Landscape Analysis library version 1.3: embedding distribution analysis metrics}},
  year = {2026},
  eprint = {2612.03570},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2612.03570},
}
Figure