remblais 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- remblais-1.0.1/LICENSE-APACHE +202 -0
- remblais-1.0.1/LICENSE-MIT +21 -0
- remblais-1.0.1/PKG-INFO +131 -0
- remblais-1.0.1/README.md +96 -0
- remblais-1.0.1/THIRD_PARTY.md +51 -0
- remblais-1.0.1/pyproject.toml +47 -0
- remblais-1.0.1/remblais/__init__.py +17 -0
- remblais-1.0.1/remblais/_arguments.py +156 -0
- remblais-1.0.1/remblais/_backends/__init__.py +92 -0
- remblais-1.0.1/remblais/_backends/common.py +48 -0
- remblais-1.0.1/remblais/_backends/keops.py +26 -0
- remblais-1.0.1/remblais/_backends/numpy.py +114 -0
- remblais-1.0.1/remblais/_backends/torch.py +134 -0
- remblais-1.0.1/remblais/_cache.py +92 -0
- remblais-1.0.1/remblais/_input_validation/__init__.py +19 -0
- remblais-1.0.1/remblais/_input_validation/converters.py +48 -0
- remblais-1.0.1/remblais/_input_validation/typechecking.py +26 -0
- remblais-1.0.1/remblais/_kp.py +243 -0
- remblais-1.0.1/remblais/_typing.py +161 -0
- remblais-1.0.1/remblais/clustering.py +141 -0
- remblais-1.0.1/remblais/costs.py +266 -0
- remblais-1.0.1/remblais/hausdorff.py +58 -0
- remblais-1.0.1/remblais/kernel_samples.py +181 -0
- remblais-1.0.1/remblais/lazy.py +382 -0
- remblais-1.0.1/remblais/ot/__init__.py +28 -0
- remblais-1.0.1/remblais/ot/_abstract_solvers/__init__.py +5 -0
- remblais-1.0.1/remblais/ot/_abstract_solvers/annealing.py +227 -0
- remblais-1.0.1/remblais/ot/_abstract_solvers/sinkhorn_barycenters.py +316 -0
- remblais-1.0.1/remblais/ot/_abstract_solvers/sinkhorn_ot.py +449 -0
- remblais-1.0.1/remblais/ot/_abstract_solvers/unbalanced_ot.py +194 -0
- remblais-1.0.1/remblais/ot/_implementations/__init__.py +2 -0
- remblais-1.0.1/remblais/ot/_implementations/grid.py +17 -0
- remblais-1.0.1/remblais/ot/_implementations/matrix.py +715 -0
- remblais-1.0.1/remblais/ot/_implementations/sample.py +650 -0
- remblais-1.0.1/remblais/ot/_ot_result.py +456 -0
- remblais-1.0.1/remblais/samples_loss.py +254 -0
- remblais-1.0.1/remblais/sinkhorn_divergence.py +182 -0
- remblais-1.0.1/remblais/sinkhorn_images.py +191 -0
- remblais-1.0.1/remblais/sinkhorn_samples.py +384 -0
- remblais-1.0.1/remblais/utils.py +40 -0
- remblais-1.0.1/remblais/wasserstein_barycenter_images.py +70 -0
- remblais-1.0.1/remblais.egg-info/PKG-INFO +131 -0
- remblais-1.0.1/remblais.egg-info/SOURCES.txt +50 -0
- remblais-1.0.1/remblais.egg-info/dependency_links.txt +1 -0
- remblais-1.0.1/remblais.egg-info/requires.txt +10 -0
- remblais-1.0.1/remblais.egg-info/top_level.txt +1 -0
- remblais-1.0.1/setup.cfg +4 -0
- remblais-1.0.1/tests/test_clustering.py +75 -0
- remblais-1.0.1/tests/test_docs_examples.py +49 -0
- remblais-1.0.1/tests/test_images.py +130 -0
- remblais-1.0.1/tests/test_lazy.py +83 -0
- remblais-1.0.1/tests/test_samples_loss.py +477 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jean-Baptiste Keck
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
remblais-1.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: remblais
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Sinkhorn divergences, kernel MMD and optimal transport on NVIDIA, AMD and Intel GPUs (CUDA, HIP, SYCL): a drop-in GeomLoss replacement built on kernox
|
|
5
|
+
Author: Jean-Baptiste Keck
|
|
6
|
+
License-Expression: MIT OR Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/keckj/remblais
|
|
8
|
+
Project-URL: Documentation, https://keckj.github.io/remblais/
|
|
9
|
+
Project-URL: Source, https://github.com/keckj/remblais
|
|
10
|
+
Project-URL: Issues, https://github.com/keckj/remblais/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/keckj/remblais/releases
|
|
12
|
+
Project-URL: kernox, https://github.com/keckj/kernox
|
|
13
|
+
Keywords: optimal transport,sinkhorn,wasserstein,mmd,geomloss,gpu,cuda,rocm,sycl,pytorch
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
19
|
+
Classifier: Environment :: GPU :: NVIDIA CUDA
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE-MIT
|
|
23
|
+
License-File: LICENSE-APACHE
|
|
24
|
+
License-File: THIRD_PARTY.md
|
|
25
|
+
Requires-Dist: numpy
|
|
26
|
+
Requires-Dist: scipy
|
|
27
|
+
Requires-Dist: torch
|
|
28
|
+
Requires-Dist: kernox>=1.0.1
|
|
29
|
+
Provides-Extra: test
|
|
30
|
+
Requires-Dist: pytest; extra == "test"
|
|
31
|
+
Requires-Dist: pytest-check; extra == "test"
|
|
32
|
+
Requires-Dist: hypothesis; extra == "test"
|
|
33
|
+
Requires-Dist: geomloss==0.3.1; extra == "test"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# remblais
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<img src="https://raw.githubusercontent.com/keckj/remblais/v1.0.1/docs/images/remblais-banner.png" alt="remblais logo" width="560">
|
|
40
|
+
</p>
|
|
41
|
+
|
|
42
|
+
remblais computes geometric losses between measures on NVIDIA (CUDA), AMD
|
|
43
|
+
(ROCm/HIP) and Intel (SYCL) GPUs: Sinkhorn divergences (entropic optimal
|
|
44
|
+
transport), kernel norms (MMD) and Hausdorff divergences between point clouds,
|
|
45
|
+
images and volumes. It is a drop-in
|
|
46
|
+
replacement for [GeomLoss](https://www.kernel-operations.io/geomloss/) 0.3.1,
|
|
47
|
+
built on [kernox](https://github.com/keckj/kernox) instead of PyKeOps: write
|
|
48
|
+
`import remblais as geomloss` and your code runs unchanged.
|
|
49
|
+
|
|
50
|
+
- Documentation: <https://keckj.github.io/remblais/>
|
|
51
|
+
- Getting started: <https://keckj.github.io/remblais/getting-started/>
|
|
52
|
+
|
|
53
|
+
## Why remblais
|
|
54
|
+
|
|
55
|
+
- **Same API as GeomLoss.** `SamplesLoss`, `sinkhorn_divergence`,
|
|
56
|
+
`ImagesBarycenter` and the `ot` module have the GeomLoss 0.3.1 signatures,
|
|
57
|
+
calling conventions and output shapes. With `backend="tensorized"`, values
|
|
58
|
+
and gradients match GeomLoss bit for bit, apart from the documented fixes.
|
|
59
|
+
- **Faster.** Every softmin is one fused kernox reduction, compiled once and
|
|
60
|
+
reused for all values of ε; the debiased Sinkhorn loop fuses its four
|
|
61
|
+
softmins into two reductions per iteration.
|
|
62
|
+
- **NVIDIA, AMD and Intel GPUs.** The `online` and `multiscale` backends,
|
|
63
|
+
which GeomLoss runs through PyKeOps on NVIDIA GPUs only, run here on CUDA,
|
|
64
|
+
ROCm/HIP and SYCL through kernox. remblais's own test suite runs on NVIDIA
|
|
65
|
+
and Intel GPUs; on AMD GPUs it relies on kernox's tested HIP backend.
|
|
66
|
+
- **Fixes, not surprises.** A few GeomLoss bugs are fixed (the gradient of
|
|
67
|
+
unbalanced transport, `"hausdorff"` without a kernel, ...). Every
|
|
68
|
+
difference is listed in [Coming from GeomLoss](https://keckj.github.io/remblais/geomloss/).
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
remblais needs Python 3.10 or later, PyTorch and kernox. Install PyTorch for
|
|
73
|
+
your platform, then kernox with the extra that matches your GPU, then remblais,
|
|
74
|
+
both from PyPI. For an NVIDIA GPU:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
pip install torch --index-url https://download.pytorch.org/whl/cu126
|
|
78
|
+
pip install "kernox[cuda]"
|
|
79
|
+
pip install remblais
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
For AMD and Intel GPUs, install PyTorch from the `rocm` or `xpu` index and
|
|
83
|
+
kernox with the `rocm` or `xpu` extra; the details are in the
|
|
84
|
+
[kernox installation guide](https://keckj.github.io/kernox/getting-started/)
|
|
85
|
+
and in [Getting started](https://keckj.github.io/remblais/getting-started/).
|
|
86
|
+
|
|
87
|
+
## Performance
|
|
88
|
+
|
|
89
|
+
The goal of remblais is to be **at least as fast as GeomLoss** wherever
|
|
90
|
+
GeomLoss runs. In the cases measured so far, it is already faster.
|
|
91
|
+
|
|
92
|
+
Sinkhorn divergence, p = 2, FP32, forward and backward passes, on an RTX 2080
|
|
93
|
+
Ti; remblais with `fast_math`, its default setting, against GeomLoss 0.3.1 in
|
|
94
|
+
its best configuration (each PyKeOps kernel compiled alone in a fresh
|
|
95
|
+
process). Time ratios remblais / GeomLoss, lower than 1 when remblais is
|
|
96
|
+
faster:
|
|
97
|
+
|
|
98
|
+
| Case | N = 10⁴ | N = 10⁵ | N = 10⁶ |
|
|
99
|
+
| --- | --- | --- | --- |
|
|
100
|
+
| multiscale, D = 2 | ×0.45 | ×0.40 | ×0.79 |
|
|
101
|
+
| multiscale, D = 3 | ×0.26 | ×0.92 | ×0.96 |
|
|
102
|
+
| online, D = 2 | ×0.33 | ×0.84 | ×0.89 |
|
|
103
|
+
| online, D = 3 | ×0.31 | ×0.85 | ×0.90 |
|
|
104
|
+
| online, D = 64 | ×0.45 | ×0.54 | not measured |
|
|
105
|
+
|
|
106
|
+
For small clouds (N = 10³ to 3·10⁴), the online backend runs at ×0.31 to
|
|
107
|
+
×0.61 of the GeomLoss time in D = 2 and 3, and at ×0.17 to ×0.45 in D = 64.
|
|
108
|
+
|
|
109
|
+
These figures cover only the cases listed; they are not a general claim of
|
|
110
|
+
superiority over GeomLoss on every workload or card. The full tables and the
|
|
111
|
+
protocol are on the [Performance](https://keckj.github.io/remblais/performance/) page.
|
|
112
|
+
|
|
113
|
+
## About the name and logo
|
|
114
|
+
|
|
115
|
+
In 1781, Gaspard Monge asked how to move a pile of earth, the *déblais*, into
|
|
116
|
+
a hole of the same volume, the *remblais*, at the lowest cost: the founding
|
|
117
|
+
problem of optimal transport. remblais is where the mass ends up. The logo
|
|
118
|
+
shows the ox of symox and kernox, harnessed this time to a scraper, carrying
|
|
119
|
+
the déblais to the remblais: Monge's optimal transport.
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
At your option, [MIT](https://github.com/keckj/remblais/blob/v1.0.1/LICENSE-MIT) or [Apache-2.0](https://github.com/keckj/remblais/blob/v1.0.1/LICENSE-APACHE). Code
|
|
124
|
+
derived from GeomLoss stays under the MIT license of GeomLoss; its provenance
|
|
125
|
+
and notice are in [`THIRD_PARTY.md`](https://github.com/keckj/remblais/blob/v1.0.1/THIRD_PARTY.md).
|
|
126
|
+
|
|
127
|
+
## Related projects
|
|
128
|
+
|
|
129
|
+
- GeomLoss, the original library: <https://github.com/jeanfeydy/geomloss>
|
|
130
|
+
- kernox, fused GPU reductions: <https://github.com/keckj/kernox>
|
|
131
|
+
- symox, symbolic engine and code generation: <https://github.com/keckj/symox>
|
remblais-1.0.1/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# remblais
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/keckj/remblais/v1.0.1/docs/images/remblais-banner.png" alt="remblais logo" width="560">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
remblais computes geometric losses between measures on NVIDIA (CUDA), AMD
|
|
8
|
+
(ROCm/HIP) and Intel (SYCL) GPUs: Sinkhorn divergences (entropic optimal
|
|
9
|
+
transport), kernel norms (MMD) and Hausdorff divergences between point clouds,
|
|
10
|
+
images and volumes. It is a drop-in
|
|
11
|
+
replacement for [GeomLoss](https://www.kernel-operations.io/geomloss/) 0.3.1,
|
|
12
|
+
built on [kernox](https://github.com/keckj/kernox) instead of PyKeOps: write
|
|
13
|
+
`import remblais as geomloss` and your code runs unchanged.
|
|
14
|
+
|
|
15
|
+
- Documentation: <https://keckj.github.io/remblais/>
|
|
16
|
+
- Getting started: <https://keckj.github.io/remblais/getting-started/>
|
|
17
|
+
|
|
18
|
+
## Why remblais
|
|
19
|
+
|
|
20
|
+
- **Same API as GeomLoss.** `SamplesLoss`, `sinkhorn_divergence`,
|
|
21
|
+
`ImagesBarycenter` and the `ot` module have the GeomLoss 0.3.1 signatures,
|
|
22
|
+
calling conventions and output shapes. With `backend="tensorized"`, values
|
|
23
|
+
and gradients match GeomLoss bit for bit, apart from the documented fixes.
|
|
24
|
+
- **Faster.** Every softmin is one fused kernox reduction, compiled once and
|
|
25
|
+
reused for all values of ε; the debiased Sinkhorn loop fuses its four
|
|
26
|
+
softmins into two reductions per iteration.
|
|
27
|
+
- **NVIDIA, AMD and Intel GPUs.** The `online` and `multiscale` backends,
|
|
28
|
+
which GeomLoss runs through PyKeOps on NVIDIA GPUs only, run here on CUDA,
|
|
29
|
+
ROCm/HIP and SYCL through kernox. remblais's own test suite runs on NVIDIA
|
|
30
|
+
and Intel GPUs; on AMD GPUs it relies on kernox's tested HIP backend.
|
|
31
|
+
- **Fixes, not surprises.** A few GeomLoss bugs are fixed (the gradient of
|
|
32
|
+
unbalanced transport, `"hausdorff"` without a kernel, ...). Every
|
|
33
|
+
difference is listed in [Coming from GeomLoss](https://keckj.github.io/remblais/geomloss/).
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
remblais needs Python 3.10 or later, PyTorch and kernox. Install PyTorch for
|
|
38
|
+
your platform, then kernox with the extra that matches your GPU, then remblais,
|
|
39
|
+
both from PyPI. For an NVIDIA GPU:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pip install torch --index-url https://download.pytorch.org/whl/cu126
|
|
43
|
+
pip install "kernox[cuda]"
|
|
44
|
+
pip install remblais
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
For AMD and Intel GPUs, install PyTorch from the `rocm` or `xpu` index and
|
|
48
|
+
kernox with the `rocm` or `xpu` extra; the details are in the
|
|
49
|
+
[kernox installation guide](https://keckj.github.io/kernox/getting-started/)
|
|
50
|
+
and in [Getting started](https://keckj.github.io/remblais/getting-started/).
|
|
51
|
+
|
|
52
|
+
## Performance
|
|
53
|
+
|
|
54
|
+
The goal of remblais is to be **at least as fast as GeomLoss** wherever
|
|
55
|
+
GeomLoss runs. In the cases measured so far, it is already faster.
|
|
56
|
+
|
|
57
|
+
Sinkhorn divergence, p = 2, FP32, forward and backward passes, on an RTX 2080
|
|
58
|
+
Ti; remblais with `fast_math`, its default setting, against GeomLoss 0.3.1 in
|
|
59
|
+
its best configuration (each PyKeOps kernel compiled alone in a fresh
|
|
60
|
+
process). Time ratios remblais / GeomLoss, lower than 1 when remblais is
|
|
61
|
+
faster:
|
|
62
|
+
|
|
63
|
+
| Case | N = 10⁴ | N = 10⁵ | N = 10⁶ |
|
|
64
|
+
| --- | --- | --- | --- |
|
|
65
|
+
| multiscale, D = 2 | ×0.45 | ×0.40 | ×0.79 |
|
|
66
|
+
| multiscale, D = 3 | ×0.26 | ×0.92 | ×0.96 |
|
|
67
|
+
| online, D = 2 | ×0.33 | ×0.84 | ×0.89 |
|
|
68
|
+
| online, D = 3 | ×0.31 | ×0.85 | ×0.90 |
|
|
69
|
+
| online, D = 64 | ×0.45 | ×0.54 | not measured |
|
|
70
|
+
|
|
71
|
+
For small clouds (N = 10³ to 3·10⁴), the online backend runs at ×0.31 to
|
|
72
|
+
×0.61 of the GeomLoss time in D = 2 and 3, and at ×0.17 to ×0.45 in D = 64.
|
|
73
|
+
|
|
74
|
+
These figures cover only the cases listed; they are not a general claim of
|
|
75
|
+
superiority over GeomLoss on every workload or card. The full tables and the
|
|
76
|
+
protocol are on the [Performance](https://keckj.github.io/remblais/performance/) page.
|
|
77
|
+
|
|
78
|
+
## About the name and logo
|
|
79
|
+
|
|
80
|
+
In 1781, Gaspard Monge asked how to move a pile of earth, the *déblais*, into
|
|
81
|
+
a hole of the same volume, the *remblais*, at the lowest cost: the founding
|
|
82
|
+
problem of optimal transport. remblais is where the mass ends up. The logo
|
|
83
|
+
shows the ox of symox and kernox, harnessed this time to a scraper, carrying
|
|
84
|
+
the déblais to the remblais: Monge's optimal transport.
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
At your option, [MIT](https://github.com/keckj/remblais/blob/v1.0.1/LICENSE-MIT) or [Apache-2.0](https://github.com/keckj/remblais/blob/v1.0.1/LICENSE-APACHE). Code
|
|
89
|
+
derived from GeomLoss stays under the MIT license of GeomLoss; its provenance
|
|
90
|
+
and notice are in [`THIRD_PARTY.md`](https://github.com/keckj/remblais/blob/v1.0.1/THIRD_PARTY.md).
|
|
91
|
+
|
|
92
|
+
## Related projects
|
|
93
|
+
|
|
94
|
+
- GeomLoss, the original library: <https://github.com/jeanfeydy/geomloss>
|
|
95
|
+
- kernox, fused GPU reductions: <https://github.com/keckj/kernox>
|
|
96
|
+
- symox, symbolic engine and code generation: <https://github.com/keckj/symox>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Third-party code and algorithms
|
|
2
|
+
|
|
3
|
+
remblais is dual-licensed under MIT or Apache-2.0, at your option
|
|
4
|
+
([`LICENSE-MIT`](LICENSE-MIT), [`LICENSE-APACHE`](LICENSE-APACHE)). Part of
|
|
5
|
+
its code is derived from GeomLoss, which is released under the MIT license:
|
|
6
|
+
that code remains under the MIT license, with the notice below. The table
|
|
7
|
+
lists the code and algorithms taken from third-party projects; the files
|
|
8
|
+
copied from GeomLoss start with an attribution header.
|
|
9
|
+
|
|
10
|
+
| remblais file | Source | Revision | License | Nature |
|
|
11
|
+
| --- | --- | --- | --- | --- |
|
|
12
|
+
| `remblais/samples_loss.py` | GeomLoss `src/geomloss/_legacy/samples_loss.py` (jeanfeydy/geomloss) | v0.3.1 (tag `6a29db8`, identical to the PyPI package) | MIT | `SamplesLoss` interface (signature, calling conventions, shape checks and error messages, `backend="auto"` selection rule) taken and adapted |
|
|
13
|
+
| `remblais/sinkhorn_divergence.py` | GeomLoss `src/geomloss/_legacy/sinkhorn_divergence.py` | v0.3.1 | MIT | symmetric Sinkhorn loop, ε-scaling, debiased and unbalanced formulas, taken and adapted (grad state restored, unbalanced gradient fixed) |
|
|
14
|
+
| `remblais/sinkhorn_samples.py` | GeomLoss `src/geomloss/_legacy/sinkhorn_samples.py` | v0.3.1 | MIT | tensorized / online / multiscale backends (truncation, extrapolation); softmins rewritten on kernox |
|
|
15
|
+
| `remblais/kernel_samples.py` | GeomLoss `src/geomloss/_legacy/kernel_samples.py` | v0.3.1 | MIT | kernel norms, `DoubleGrad`, truncated multiscale; products rewritten on kernox |
|
|
16
|
+
| `remblais/utils.py` | GeomLoss `src/geomloss/_legacy/utils.py` | v0.3.1 | MIT | `scal`, dense distances, diameter |
|
|
17
|
+
| `remblais/clustering.py` | PyKeOps `pykeops/torch/cluster/{grid_cluster,matrix}.py` (getkeops/keops) | `ef72bc907df78cd18bff866d3dc7cb6375f11a4d` | MIT | semantics of `grid_cluster`, `cluster_ranges_centroids`, `sort_clusters`, `from_matrix`; rewritten in Torch (no line copied) |
|
|
18
|
+
| `remblais/ot/**`, `remblais/_backends/*` (except `keops.py`, rewritten on `remblais.lazy`), `remblais/_input_validation/*`, `remblais/_arguments.py`, `remblais/_typing.py`, `remblais/_cache.py` | GeomLoss `src/geomloss/` (same paths) | v0.3.1 | MIT | copied with an attribution header; the `barycenter*` and `solve_grid` skeletons replaced by explicit `NotImplementedError`s, grid softmins redirected to `remblais.sinkhorn_images` |
|
|
19
|
+
| `tests/ot/**` | GeomLoss `tests/` (`check_ot_result.py`, `generators/`, `test_ot_solve_matrix.py`, `test_ot_solve_sample.py`) | v0.3.1 | MIT | copied, `geomloss` replaced by `remblais` in the imports |
|
|
20
|
+
| `remblais/sinkhorn_images.py`, `remblais/wasserstein_barycenter_images.py` | GeomLoss `src/geomloss/_legacy/{sinkhorn_images,wasserstein_barycenter_images,utils}.py` | v0.3.1 | MIT | algorithms taken; softmin and C-transform rewritten on kernox |
|
|
21
|
+
| `tests/test_samples_loss.py` | GeomLoss (reference behavior, run from the PyPI package `geomloss==0.3.1`) | 0.3.1 | MIT | no line copied |
|
|
22
|
+
|
|
23
|
+
## GeomLoss notice
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
MIT License
|
|
27
|
+
|
|
28
|
+
Copyright (c) 2019 Jean Feydy
|
|
29
|
+
|
|
30
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
31
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
32
|
+
in the Software without restriction, including without limitation the rights
|
|
33
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
34
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
35
|
+
furnished to do so, subject to the following conditions:
|
|
36
|
+
|
|
37
|
+
The above copyright notice and this permission notice shall be included in all
|
|
38
|
+
copies or substantial portions of the Software.
|
|
39
|
+
|
|
40
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
41
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
42
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
43
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
44
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
45
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
46
|
+
SOFTWARE.
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The KeOps license (MIT) is in its repository
|
|
50
|
+
(<https://github.com/getkeops/keops>, `licence.txt`); see also the
|
|
51
|
+
`THIRD_PARTY.md` file of kernox (<https://github.com/keckj/kernox>).
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"] # PEP 639: SPDX license expression, license-files
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "remblais"
|
|
7
|
+
dynamic = ["version"] # remblais.__version__
|
|
8
|
+
description = "Sinkhorn divergences, kernel MMD and optimal transport on NVIDIA, AMD and Intel GPUs (CUDA, HIP, SYCL): a drop-in GeomLoss replacement built on kernox"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT OR Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE-MIT", "LICENSE-APACHE", "THIRD_PARTY.md"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Jean-Baptiste Keck" }]
|
|
14
|
+
keywords = ["optimal transport", "sinkhorn", "wasserstein", "mmd", "geomloss", "gpu", "cuda", "rocm", "sycl", "pytorch"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
21
|
+
"Environment :: GPU :: NVIDIA CUDA",
|
|
22
|
+
]
|
|
23
|
+
# kernox: the plain package is enough for the CPU reference path; install it
|
|
24
|
+
# with the extra of your GPU (kernox[cuda], kernox[rocm], kernox[xpu]) for speed.
|
|
25
|
+
# torch: installed from the platform-specific index (CUDA, ROCm, XPU), as for kernox.
|
|
26
|
+
dependencies = ["numpy", "scipy", "torch", "kernox>=1.0.1"]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
# geomloss 0.3.1 is the reference implementation the tests compare against.
|
|
30
|
+
test = ["pytest", "pytest-check", "hypothesis", "geomloss==0.3.1"]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/keckj/remblais"
|
|
34
|
+
Documentation = "https://keckj.github.io/remblais/"
|
|
35
|
+
Source = "https://github.com/keckj/remblais"
|
|
36
|
+
Issues = "https://github.com/keckj/remblais/issues"
|
|
37
|
+
Changelog = "https://github.com/keckj/remblais/releases"
|
|
38
|
+
kernox = "https://github.com/keckj/kernox"
|
|
39
|
+
|
|
40
|
+
[tool.setuptools.dynamic]
|
|
41
|
+
version = { attr = "remblais.__version__" }
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
include = ["remblais*"]
|
|
45
|
+
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""remblais: a GeomLoss clone built on kernox (fused GPU reductions).
|
|
2
|
+
|
|
3
|
+
remblais is a drop-in replacement for GeomLoss 0.3.1: replace
|
|
4
|
+
``from geomloss import SamplesLoss`` with ``from remblais import SamplesLoss``,
|
|
5
|
+
or ``import remblais as geomloss``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "1.0.1"
|
|
9
|
+
GEOMLOSS_VERSION = "0.3.1" # reference version for parity
|
|
10
|
+
|
|
11
|
+
from .costs import Cost, keops_string_cost # noqa: E402
|
|
12
|
+
from .kernel_samples import Kernel # noqa: E402
|
|
13
|
+
from .samples_loss import SamplesLoss # noqa: E402
|
|
14
|
+
from .sinkhorn_images import sinkhorn_divergence # noqa: E402
|
|
15
|
+
from .wasserstein_barycenter_images import ImagesBarycenter # noqa: E402
|
|
16
|
+
|
|
17
|
+
__all__ = ["SamplesLoss", "ImagesBarycenter", "sinkhorn_divergence", "Cost", "Kernel", "keops_string_cost"]
|