arXiv:2609.00748cs.CLSep 2026

Manuscript Offprint

arXiv:2609.00748

Measuring Optimal Transport in Transformer Depth

Alexandre Quemy

Abstract

A transformer carries each token's state from layer to layer, and the whole vocabulary carried together forms a cloud that moves with depth. We ask whether a trained network moves this cloud the way optimal transport would: at the cheapest cost, and along the map that pairs each token with its optimal destination. We measure both on Pythia-160m and Pythia-410m, with an exact assignment between consecutive layer clouds, a measured sampling floor, calibration on couplings known to be optimal, and a split of the cost into the common shift of the cloud and the token-specific moves. At the last layer, both models move their tokens where the optimal-transport map sends them, at the optimal cost for Pythia-410m and slightly above it for Pythia-160m. At the first layer they do not. In between, single layers can be judged on cost at only two of ten transitions, and blocks of several layers move the cloud at close to the optimal cost. The agreement at the last layer is much weaker at initialisation (0.64 against 0.86) and grows with training.

1 Introduction

A transformer with LL layers turns each token vector x(0)x^{(0)} into x(1),…x(L)x^{(1)}, \ldots x^{(L)}. At layer 0 the state is the embedding of the current token, so there are as many distinct points as the vocabulary cardinality. From layer 1 on, states depend on context, so there are as many points as token occurrences. Taken together, the states of a corpus form a cloud μℓ\mu_\ell at layer ℓ\ell. The network moves the first cloud onto the second with a specific pairing, token ii goes from xi(ℓ)x_i^{(\ell)} to xi(ℓ+1)x_i^{(\ell+1)}.

Optimal transport asks what the cheapest way to move μℓ\mu_\ell onto μℓ+1\mu_{\ell+1} would be if the pairing were free, paying squared distance per point:

W22(μℓ,μℓ+1)=min⁡πE(x,y)∼π∥x−y∥2.(1)W_{2}^{2}(\mu_{\ell},\mu_{\ell+1})=\min_{\pi}\mathbb{E}_{(x,y)\sim\pi}\|x-y\|^{2}. \tag{1}

For this cost, the optimal pairing is unique and is the gradient of a convex function, y=∇φ(x)y=\nabla \varphi(x) [Brenier, 1991].

In this paper, we ask whether the network's own pairing is that particular one. To do so, we study the transport efficiency of Pythia-160m and Python 410M, layer per layer, over a sample of token positions obtained on a subset of WikiText-103 and Piles datasets. A following question we study is whether the move of token ii from layer ℓ\ell to ℓ+1\ell+1 matches the optimal-transport displacement ∇φℓ(xi)−xi\nabla \varphi_\ell(x_i) - x_i.

There are several practical interests in answering these questions. If a layer follows that map, its action on all tokens is summarised by a single convex potential, so the layer can be replaced by a (possibly) cheap optimal-transport surrogate for analysis [Makkuva et al., 2020, Korotin et al., 2023], and the methods that merge models [Singh and Jaggi, 2020] or align their representations [Alvarez-Melis and Jaakkola, 2018] with optimal transport can be applied with the guarantee that the network's own map is of the same kind. In addition, the distance to the cheapest move is a label-free measure of wasted motion [Finlay et al., 2020, Kan et al., 2025], usable to compare layers and models, and the agreement with the optimal map across training checkpoints [Biderman et al., 2023] shows when and where a layer's function forms.

Preprint.

We make three contributions. The first is the question itself. To our knowledge, this is the first empirical test of whether the layer-to-layer map of a trained transformer acts as optimal transport between its own consecutive layer clouds, using the coupling the network defines, both in cost and in the pairing it induces. The second is a measurement protocol for optimal transport between layer transitions: the sampling error is measured and subtracted, the readings are calibrated on couplings known to be optimal, the common shift of the cloud is separated from the token-specific moves, and a lower bound that needs no calibration is provided. The third is the result: on Pythia-160m and Pythia-410m, the last layer moves its tokens along the optimal-transport map, this agreement appears with training, and the cost of the network's moves is optimal wherever it can be measured, with one exception at the exit of the smaller model.

The rest of the paper is organized as follows. Section 2 discusses related work. Section 3 studies the cost of the network's moves and Section 4 their agreement with the optimal-transport map. We conclude in Section 5.

References (26)