Skip to content

deblais and remblais

In 1781, Gaspard Monge asked how to move a pile of earth, the déblais, into a hole of the same volume, the remblais, at the lowest cost. The two words name the two ends of the same transport, and two twin libraries:

deblais (this project) remblais
Problem exact optimal transport entropic optimal transport: Sinkhorn divergences, and kernel norms (MMD), Hausdorff divergences
Algorithm network simplex, multiscale, domain decomposition Sinkhorn iterations with \(\varepsilon\)-scaling, multiscale
Result an optimal vertex: sparse plan, exact cost, dual certificate a smooth loss, with a blur parameter that trades accuracy for speed
Runs on CPUs (OpenMP) NVIDIA, AMD and Intel GPUs, several GPUs or nodes, and CPUs
Cost functions powers of the distance \(\lvert x - y \rvert^p\), squared Euclidean by default any cost or kernel formula
Data point clouds, dimension \(1 \le d \le 8\) point clouds in any dimension, images and volumes
Interface C++17 headers; Python for NumPy and PyTorch Python for PyTorch, drop-in replacement of GeomLoss
Unbalanced transport no yes

Which one?

Use deblais when you need the transport plan itself, or the true Wasserstein distance:

  • an assignment or a matching between two sets of points, with a proof of optimality;
  • a reference value to validate an approximate solver;
  • a sparse plan to interpolate between two measures (displacement interpolation), or a transport map without blur;
  • exact integer flows.

Use remblais when you need a loss to minimize, many times, on a GPU:

  • training a model with a geometric loss, where a smooth, positive definite divergence behaves better than a raw transport cost;
  • millions of points per evaluation, in single precision;
  • costs other than the squared distance, unbalanced measures, images and volumes, high dimension.

The two meet when the blur of the Sinkhorn divergence goes to zero: with \(\varepsilon = \mathrm{blur}^p\), the divergence \(S_\varepsilon(\alpha, \beta)\) converges to the transport cost that deblais computes, \(\tfrac12 W_2^2(\alpha, \beta)\) in the convention of remblais.

Together

Both libraries take PyTorch tensors, and can share a process (and its OpenMP runtime, see Getting started). A typical use is to check, on a sample, how far an entropic loss is from the exact transport cost:

import torch
import deblais
import remblais

x, y = torch.rand(50_000, 3), torch.rand(50_000, 3)

exact = deblais.wasserstein2(x, y)                       # W2^2, squared distances

loss = remblais.SamplesLoss("sinkhorn", p=2, blur=0.01)  # cost |x - y|^2 / 2
entropic = 2 * loss(x, y)

print(float(exact), float(entropic))

Note

remblais follows the convention of GeomLoss: with p=2 its cost is \(\tfrac12 |x - y|^2\), half the cost of deblais. The factor 2 above accounts for it.