A fast, GPU-parallel, PyTorch-compatible optimal transport solver.
Project description
This is the official repository for the MDOT-TruncatedNewton (or MDOT-TNT) algorithm [1] for solving the entropic-regularized optimal transport (OT) problem. In addition to being GPU-friendly, the algorithm is stable under weak regularization and can therefore find highly precise approximations of the un-regularized problem's solution quickly.
The current implementation is based on PyTorch and is compatible with both CPU and GPU. PyTorch is the only dependency.
For installation: First, install PyTorch following the instructions at https://pytorch.org/get-started/locally/ to select the version that matches your system's configuration.
pip3 install mdot_tnt
Quickstart guide:
import mdot_tnt
import torch as th
device = 'cuda' if th.cuda.is_available() else 'cpu'
N, M, dim = 100, 200, 128
# Sample row and column marginals from Dirichlet distributions
r = th.distributions.Dirichlet(th.ones(N)).sample()
c = th.distributions.Dirichlet(th.ones(M)).sample()
# Cost matrix from pairwise Euclidean distances squared given random points in R^100
x = th.distributions.MultivariateNormal(th.zeros(dim), th.eye(dim)).sample((N,))
y = th.distributions.MultivariateNormal(th.zeros(dim), th.eye(dim)).sample((M,))
C = th.cdist(x, y, p=2) ** 2
C /= C.max() # Normalize cost matrix to meet convention.
# Use double precision for numerical stability in high precision regime.
r, c, C = r.double().to(device), c.double().to(device), C.double().to(device)
# Solve OT problem. Increase (decrease) gamma_f for higher (lower) precision.
# Default is gamma_f=2**10. Expect error of order logn / gamma_f at worst, and possibly lower.
cost = mdot_tnt.solve_OT(r, c, C, gamma_f=2**10)
# To return a feasible transport plan, use the following:
transport_plan = mdot_tnt.solve_OT(r, c, C, gamma_f=2**12, return_plan=True)
# In both cases, the default rounding onto the feasible set can be disabled by setting `round=False`.
The code is released under a custom non-commerical use license. If you use our work in your research, please consider citing:
@inproceedings{
kemertas2025a,
title={A Truncated Newton Method for Optimal Transport},
author={Mete Kemertas and Amir-massoud Farahmand and Allan Douglas Jepson},
booktitle={The Thirteenth International Conference on Learning Representations},
year={2025},
url={https://openreview.net/forum?id=gWrWUaCbMa}
}
For inquiries, email: kemertas [at] cs [dot] toronto [dot] edu
[1] Mete Kemertas, Amir-massoud Farahmand, Allan Douglas Jepson. "A Truncated Newton Method for Optimal Transport." The Thirteenth International Conference on Learning Representations (ICLR), 2025. https://openreview.net/forum?id=gWrWUaCbMa
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdot_tnt-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mdot_tnt-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1891eb6483bb27b75fe97c5a5b970036dcaf1684dffffa3bb1e2e97f05dafc4f
|
|
| MD5 |
645f0d86a7ac9d82ca675c8c91d186df
|
|
| BLAKE2b-256 |
7416de335ff631508abbe2c84389a6ab30b989aac18564eaf538214d8736fbcb
|