Skip to content

Commit ee8ed4f

Browse files
committed
update documentation
1 parent 5e7bfbc commit ee8ed4f

File tree

7 files changed

+53
-17
lines changed

7 files changed

+53
-17
lines changed

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This open source Python library provide several solvers for optimization problem
1414
It provides the following solvers:
1515

1616
* OT Network Flow solver for the linear program/ Earth Movers Distance [1].
17-
* Entropic regularization OT solver with Sinkhorn Knopp Algorithm [2] and stabilized version [9][10] with optional GPU implementation (requires cudamat).
17+
* Entropic regularization OT solver with Sinkhorn Knopp Algorithm [2] and stabilized version [9][10] with optional GPU implementation (requires cupy).
1818
* Smooth optimal transport solvers (dual and semi-dual) for KL and squared L2 regularizations [17].
1919
* Non regularized Wasserstein barycenters [16] with LP solver (only small scale).
2020
* Bregman projections for Wasserstein barycenter [3] and unmixing [4].
@@ -83,12 +83,8 @@ Some sub-modules require additional dependences which are discussed below
8383
```
8484
pip install pymanopt autograd
8585
```
86-
* **ot.gpu** (GPU accelerated OT) depends on cudamat that have to be installed with:
87-
```
88-
git clone https://github.com/cudamat/cudamat.git
89-
cd cudamat
90-
python setup.py install --user # for user install (no root)
91-
```
86+
* **ot.gpu** (GPU accelerated OT) depends on cupy that have to be installed following instructions on [this page](https://docs-cupy.chainer.org/en/stable/install.html).
87+
9288

9389
obviously you need CUDA installed and a compatible GPU.
9490

docs/source/all.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ ot.da
4848

4949
.. automodule:: ot.da
5050
:members:
51+
52+
ot.gpu
53+
--------
54+
55+
.. automodule:: ot.gpu
56+
:members:
5157

5258
ot.dr
5359
--------

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Mock(MagicMock):
3131
@classmethod
3232
def __getattr__(cls, name):
3333
return MagicMock()
34-
MOCK_MODULES = ['ot.lp.emd_wrap','autograd','pymanopt','cudamat','autograd.numpy','pymanopt.manifolds','pymanopt.solvers']
34+
MOCK_MODULES = ['ot.lp.emd_wrap','autograd','pymanopt','cupy','autograd.numpy','pymanopt.manifolds','pymanopt.solvers']
3535
# 'autograd.numpy','pymanopt.manifolds','pymanopt.solvers',
3636
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
3737
# !!!!

ot/gpu/__init__.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
# -*- coding: utf-8 -*-
2+
"""
3+
4+
5+
This module implement GPU ilmplementation for several OT solvers and utility
6+
functions. The GPU backend in handled by `cupy
7+
<https://cupy.chainer.org/>`_.
8+
9+
By default, the functions in this module accept and return numpy arrays
10+
in order to proide drop-in replacement for the other POT function but
11+
the transfer between CPU en GPU comes with a significant overhead.
12+
13+
In order to get the best erformances, we recommend to given only cupy
14+
arrays to the functions and desactivate the conversion to numpy of the
15+
result of the function with parameter ``to_numpy=False``.
16+
17+
18+
19+
20+
"""
221

322
from . import bregman
423
from . import da
524
from .bregman import sinkhorn
25+
from .da
626

727
from . import utils
828
from .utils import dist, to_gpu, to_np
@@ -13,4 +33,4 @@
1333
#
1434
# License: MIT License
1535

16-
__all__ = ["utils", "dist", "sinkhorn"]
36+
__all__ = ["utils", "dist", "sinkhorn", 'bregman', 'da', 'to_gpu', 'to_np']

ot/gpu/bregman.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
def sinkhorn_knopp(a, b, M, reg, numItermax=1000, stopThr=1e-9,
1717
verbose=False, log=False, to_numpy=True, **kwargs):
1818
"""
19-
Solve the entropic regularization optimal transport problem and return the OT matrix
19+
Solve the entropic regularization optimal transport on GPU
20+
21+
If the input matrix are in numpy format, they will be uploaded to the
22+
GPU first which can incur significant time overhead.
2023
2124
The function solves the following optimization problem:
2225
@@ -56,6 +59,8 @@ def sinkhorn_knopp(a, b, M, reg, numItermax=1000, stopThr=1e-9,
5659
Print information along iterations
5760
log : bool, optional
5861
record log if True
62+
to_numpy : boolean, optional (default True)
63+
If true convert back the GPU array result to numpy format.
5964
6065
6166
Returns

ot/gpu/da.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ def sinkhorn_lpl1_mm(a, labels_a, b, M, reg, eta=0.1, numItermax=10,
2222
log=False, to_numpy=True):
2323
"""
2424
Solve the entropic regularization optimal transport problem with nonconvex
25-
group lasso regularization
25+
group lasso regularization on GPU
26+
27+
If the input matrix are in numpy format, they will be uploaded to the
28+
GPU first which can incur significant time overhead.
29+
2630
2731
The function solves the following optimization problem:
2832
@@ -74,6 +78,8 @@ def sinkhorn_lpl1_mm(a, labels_a, b, M, reg, eta=0.1, numItermax=10,
7478
Print information along iterations
7579
log : bool, optional
7680
record log if True
81+
to_numpy : boolean, optional (default True)
82+
If true convert back the GPU array result to numpy format.
7783
7884
7985
Returns

ot/gpu/utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@
1616
def euclidean_distances(a, b, squared=False, to_numpy=True):
1717
"""
1818
Compute the pairwise euclidean distance between matrices a and b.
19-
Parameters
19+
20+
If the input matrix are in numpy format, they will be uploaded to the
21+
GPU first which can incur significant time overhead.
22+
23+
Parameters
2024
----------
2125
a : np.ndarray (n, f)
2226
first matrix
2327
b : np.ndarray (m, f)
2428
second matrix
25-
gpu : boolean, optional (default False)
26-
if True and the module cupy is available, the computation is done
27-
on the GPU and the type of the matrix returned is cupy.ndarray.
28-
Otherwise, compute on the CPU and returns np.ndarray.
29+
to_numpy : boolean, optional (default True)
30+
If true convert back the GPU array result to numpy format.
2931
squared : boolean, optional (default False)
3032
if True, return squared euclidean distance matrix
31-
Returns
33+
34+
Returns
3235
-------
3336
c : (n x m) np.ndarray or cupy.ndarray
3437
pairwise euclidean distance distance matrix

0 commit comments

Comments
 (0)