Subscribe
AI
6 min read

What Is the Sinkhorn Algorithm? The 1964 Fixed Point That Keeps AI Models Balanced

Matrix scaling from 1964 is deep learning's cheap answer to allocation problems with global constraints. It now runs inside MoE routers, attention normalizations, optimizers and watermarking, and here is why.

What Is the Sinkhorn Algorithm? The 1964 Fixed Point That Keeps AI Models Balanced

Deep inside a mixture-of-experts router, a slot attention module, and a self-supervised clustering loss runs the same tiny loop: normalize the rows of a matrix, then the columns, then the rows again, until both sum to one. The loop has a name, Sinkhorn balancing, and it dates to a short 1964 note in the Annals of Mathematical Statistics. It is one of the oldest algorithms that modern AI cannot seem to stop rediscovering. The reason is simple. Whenever a model must make many soft allocation decisions at once (which token to which expert, which image to which prototype, which slot to which object) and those decisions must fit together globally, Sinkhorn is the cheapest way to force them to.

The problem: greedy rows, broken columns

A language model's output layer ends in softmax. Each row of an attention or routing matrix is a probability distribution: this token spends 0.6 on expert A, 0.3 on expert B. Softmax guarantees the rows sum to 1, and nothing else. It says nothing about how much each expert receives in total. Left alone, routers collapse. A 2025 paper on Mixture-of-Experts routing catalogs the standard fixes, auxiliary balancing losses and extra trainable gating components, and warns that they "can introduce objective misalignment, increase model complexity, or incur substantial training overhead," with earlier Sinkhorn-based routers singled out for that overhead. The paper's answer is to stop working around the transport problem and solve it directly, with constraints added only where balancing actually matters.

Sinkhorn answers the column question by brute elegance. Take any square matrix with strictly positive entries. Richard Sinkhorn proved that you can multiply its rows and its columns by positive diagonal factors to land on a doubly stochastic matrix, one whose rows and columns all sum to 1. The scaling factors are unique up to one overall constant, and the fixed-point iteration that finds them, rescale rows, rescale columns, repeat, converges. Sinkhorn and Knopp extended the result to nonnegative matrices a few years later.

A stretched grid of orange cells and a compressed grid of teal slivers joined by arrows, depicting row and column rescaling

Three details make the algorithm attractive to deep learning. It costs one pass over the matrix per iteration, so a few dozen iterations on a 1000-by-1000 grid is trivial on a GPU. It is differentiable: alternating normalizations are just divisions, so gradients flow through the whole procedure. And the result has a clean interpretation, which is where the 1960s math meets modern neural networks.

A probability over permutations

The set of doubly stochastic matrices is what mathematicians call the Birkhoff polytope. By the Birkhoff-von Neumann theorem, any doubly stochastic matrix is a weighted average of permutation matrices. So a Sinkhorn output is not a fuzzy assignment. It is a relaxed permutation, a soft way of sorting or matching that survives backpropagation. This is why the algorithm keeps showing up wherever a model needs to rearrange things: it is the differentiable substitute for argsort.

The same operation also solves a classical statistics problem. Sinkhorn iteration turns out to be mathematically equivalent to iterative proportional fitting, the procedure survey statisticians Deming and Stephan used in 1940 to reconcile contingency tables against known margins. And there is an optimization reading: the scaled matrix is the information projection of the input onto the doubly stochastic set, in the Kullback-Leibler sense, as Chafai's survey note on Sinkhorn's theorem lays out. Sinkhorn balancing, therefore, is KL projection dressed as long division.

Optimal transport, made fast

The biggest amplifier was optimal transport. The classical task: move dirt from piles to holes at minimum cost, formally a linear program whose solvers choked once the two distributions exceeded a few hundred points. In 2013, Marco Cuturi's Sinkhorn Distances paper showed that adding an entropic smoothing term to the transport problem makes the optimum exactly a Sinkhorn scaling of the matrix exp(-cost/epsilon). The linear program becomes a matrix rescaling loop, orders of magnitude faster, and usable inside a neural network. The theoretical case for the trick was made in 2017: Altschuler, Niles-Weed and Rigollet proved that Sinkhorn iteration approximates optimal transport costs in near-linear time. The standard reference for the whole machinery is the open-access monograph Computational Optimal Transport by Peyré and Cuturi.

Orange mounds of different heights linked by crossing arcs to equal teal basins, depicting a transport plan

That single change, LP to scaling loop, is why you can compute a Wasserstein-style distance between two 50,000-token distributions in a training step. And the training step is where the loop now lives.

Where the loop runs in modern AI

Self-supervised vision. Facebook AI's SwAV (Caron et al., 2020) assigns images to learned prototypes such that no prototype hogs the batch. The paper says it explicitly: the soft assignment comes from "the Sinkhorn-Knopp algorithm," and it works well after only 3 iterations. Without the column constraint, clustering collapses onto one cluster, the standard failure mode of prototype-based methods.

Attention itself. Sparse Sinkhorn Attention (Tay et al., 2020) uses the algorithm to sort tokens before attending: a learned meta sorting network emits Sinkhorn-scaled permutations, and local attention windows over sorted tokens imitate global attention with far less memory. The paper's variants carry the name in plain sight, including "Causal Sinkhorn Balancing."

Slot attention. In slot-attention architectures, each slot reads from all objects, and attention is normalized row then column at every layer. As Zhang et al. put it in the ICML 2023 analysis, that sequence of operations "is also known as applying the Sinkhorn algorithm for a single step." A single normalization step, repeated across layers, is a slow march toward a doubly stochastic assignment.

Mixture-of-experts. The current frontier use. Nguyen Duc et al. (November 2025) derive gating scores directly from the transport map and show that even minimal Sinkhorn-based routing balances experts without auxiliary losses. Memory is the next frontier: MESH (August 2026) targets memory-efficient Sinkhorn optimization for MoE training, because the dense transport plan is the elephant in the room at vocabulary-scale sequence lengths.

Optimizers. Sinkhorn balancing has also reached the update rule itself. SinkGD (Scetbon et al., NeurIPS 2025) applies Sinkhorn-style row and column normalization to gradient matrices as a stateless alternative to Adam. By late 2026, frontier labs were shipping it: the DeepSeek-V4.1-Flash technical report states that it "optimize[s] the Engram embedding with momentum-based update followed by Sinkhorn balancing," citing SinkGD, and applies the same treatment to token embeddings and prediction heads. A 1964 matrix-scaling lemma is now a line in a frontier model's optimizer stack.

Watermarking. Even output-side systems use it. OpenAI's Textgrain watermarking paper runs Sinkhorn updates per block so that watermarked token distributions satisfy prescribed marginal constraints while honoring an entropy budget.

What it cannot do

The loop's virtue is its vice. Sinkhorn enforces the marginals you hand it, exactly. If a MoE truly needs uneven expert loads, a doubly stochastic router overrides that need; the 2025 SSR paper is partly a study of when strict transport constraints hurt. Convergence is guaranteed in the way practitioners want only for strictly positive matrices, and slows as entries crowd toward zero (Wikipedia's summary of the convergence literature), while the entropic smoothing that makes transport differentiable also biases solutions toward diffuse assignments. Practitioners trade epsilon, iteration count, and masking against those effects case by case, as the Peyre-Cuturi monograph catalogs.

The durable lesson is architectural. Deep learning constantly faces discrete global constraints, matchings, permutations, budgets, and every time it finds the same workaround: write the constraint as row-and-column sums, run Sinkhorn until both hold, and differentiate through the whole thing. Old math, quietly load-bearing.

Sources

AILLMeducational