Inferensys

Glossary

Sinkhorn-Knopp Algorithm

An iterative normalization procedure that transforms a non-negative square matrix into a doubly stochastic matrix, used in online clustering to enforce equipartition constraints and prevent trivial solutions.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
Optimal Transport Normalization

What is Sinkhorn-Knopp Algorithm?

The Sinkhorn-Knopp algorithm is an iterative matrix scaling procedure that transforms a non-negative square matrix into a doubly stochastic matrix, enforcing equipartition constraints in online clustering to prevent trivial solutions.

The Sinkhorn-Knopp algorithm is an iterative normalization procedure that converts a non-negative matrix into a doubly stochastic matrix—one where all rows and columns sum to one. It achieves this by alternately normalizing rows and columns until convergence, solving an entropy-regularized optimal transport problem efficiently without expensive linear programming.

In self-supervised learning frameworks like SwAV, the algorithm enforces equipartition constraints on cluster assignments, ensuring that samples within a batch are distributed evenly across all clusters. This prevents the degenerate solution where all representations collapse into a single cluster, enabling meaningful unsupervised feature learning without requiring explicit negative pairs.

Optimal Transport & Equipartition

Key Features of the Sinkhorn-Knopp Algorithm

The Sinkhorn-Knopp algorithm is an iterative matrix scaling procedure that transforms any square matrix with strictly positive entries into a doubly stochastic matrix. In self-supervised learning, it enforces an equipartition constraint on cluster assignments, ensuring every cluster receives an equal share of the batch to prevent degenerate solutions.

01

Doubly Stochastic Normalization

The algorithm iteratively normalizes the rows and columns of a non-negative square matrix K until it converges to a doubly stochastic matrix. Given an initial matrix, it alternates between:

  • Row normalization: Scaling each row to sum to 1
  • Column normalization: Scaling each column to sum to 1 This process is guaranteed to converge for any matrix with total support, producing a unique doubly stochastic matrix of the form D₁ K D₂ where D₁ and D₂ are diagonal scaling matrices.
02

Entropic Regularization via Sinkhorn Distance

When combined with an entropic penalty, the Sinkhorn-Knopp algorithm computes a smooth approximation of the Wasserstein distance in optimal transport. The entropy term -εH(P) is added to the transport cost, making the optimization strictly convex and solvable via iterative matrix scaling. The parameter ε controls the trade-off:

  • Small ε: Approximates exact optimal transport (sparse couplings)
  • Large ε: Produces smoother, more diffuse couplings This differentiable formulation enables end-to-end training with gradient backpropagation through the transport plan.
03

Online Clustering in SwAV

In the SwAV (Swapping Assignments between Views) framework, the Sinkhorn-Knopp algorithm operates on the predicted code matrix Q to enforce equipartition. The algorithm solves:

  • Constraint: Each of K prototypes must be assigned to approximately B/K samples in a batch of size B
  • Output: A soft assignment matrix where columns sum to uniform marginal distributions This prevents the trivial solution where all samples collapse to a single prototype, forcing the model to learn diverse, discriminative visual features without requiring explicit negative pairs.
04

Fast GPU Implementation

The iterative row-column normalization can be efficiently implemented on GPU hardware using matrix operations. A typical implementation converges in 3-5 iterations for the online clustering use case, as exact convergence is unnecessary for representation learning. The algorithm's computational complexity is O(K × B × iterations) where K is the number of prototypes and B is the batch size. Key optimizations include:

  • In-place normalization operations to minimize memory allocation
  • Fused CUDA kernels for the alternating scaling steps
  • Early stopping when the marginal constraint violation falls below a threshold
05

Relationship to Optimal Transport

The Sinkhorn-Knopp algorithm solves the entropy-regularized optimal transport problem, which seeks the most efficient coupling between two probability distributions subject to a cost matrix. In the self-supervised context:

  • Source distribution: Uniform distribution over batch samples
  • Target distribution: Uniform distribution over prototypes
  • Cost matrix: Negative cosine similarities between sample embeddings and prototype vectors The resulting transport plan assigns samples to prototypes while respecting the equipartition constraint, making it a principled alternative to hard cluster assignment methods like K-means.
06

Convergence Guarantees

The Sinkhorn-Knopp theorem proves that for any strictly positive square matrix, the iterative row-column normalization procedure converges linearly to a unique doubly stochastic matrix. Key theoretical properties:

  • Linear convergence rate: Error decreases geometrically with each iteration
  • Global convergence: Guaranteed from any initial positive matrix
  • Uniqueness: The resulting doubly stochastic matrix is unique up to the scaling factors In practice, a small regularization constant λ is added to prevent division by zero when the code matrix contains near-zero entries, ensuring numerical stability throughout training.
SINKHORN-KNOPP ALGORITHM

Frequently Asked Questions

Clear, technically precise answers to common questions about the Sinkhorn-Knopp algorithm and its critical role in preventing representation collapse during self-supervised learning for medical imaging.

The Sinkhorn-Knopp algorithm is an iterative matrix normalization procedure that transforms a non-negative square matrix into a doubly stochastic matrix—one where every row and column sums to exactly 1. It achieves this by alternating between scaling rows to sum to one and scaling columns to sum to one, converging to a unique solution under mild conditions. In the context of self-supervised learning, the algorithm takes a matrix of raw similarity scores between image features and cluster prototypes and normalizes it to produce a soft assignment matrix Q that satisfies an equipartition constraint, ensuring each cluster receives an equal share of the batch. This prevents the degenerate solution where all samples collapse into a single cluster, a critical safeguard in methods like SwAV and DINO.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.