summaryrefslogtreecommitdiff
path: root/debian/patches/0001-Remove-benchmarks-to-prevent-installation-in-wrong-p.patch
blob: 28ae7d504f5caecf8b2f69100bd3acf68f271205 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
From: Gard Spreemann <gspr@nonempty.org>
Date: Fri, 31 Dec 2021 10:46:27 +0100
Subject: Remove benchmarks to prevent installation in wrong path

---
 benchmarks/__init__.py       |   5 ---
 benchmarks/benchmark.py      | 105 -------------------------------------------
 benchmarks/emd.py            |  40 -----------------
 benchmarks/sinkhorn_knopp.py |  42 -----------------
 4 files changed, 192 deletions(-)
 delete mode 100644 benchmarks/__init__.py
 delete mode 100644 benchmarks/benchmark.py
 delete mode 100644 benchmarks/emd.py
 delete mode 100644 benchmarks/sinkhorn_knopp.py

diff --git a/benchmarks/__init__.py b/benchmarks/__init__.py
deleted file mode 100644
index 37f5e56..0000000
--- a/benchmarks/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-from . import benchmark
-from . import sinkhorn_knopp
-from . import emd
-
-__all__= ["benchmark", "sinkhorn_knopp", "emd"]
diff --git a/benchmarks/benchmark.py b/benchmarks/benchmark.py
deleted file mode 100644
index 7973c6b..0000000
--- a/benchmarks/benchmark.py
+++ /dev/null
@@ -1,105 +0,0 @@
-# /usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from ot.backend import get_backend_list, jax, tf
-import gc
-
-
-def setup_backends():
-    if jax:
-        from jax.config import config
-        config.update("jax_enable_x64", True)
-
-    if tf:
-        from tensorflow.python.ops.numpy_ops import np_config
-        np_config.enable_numpy_behavior()
-
-
-def exec_bench(setup, tested_function, param_list, n_runs, warmup_runs):
-    backend_list = get_backend_list()
-    for i, nx in enumerate(backend_list):
-        if nx.__name__ == "tf" and i < len(backend_list) - 1:
-            # Tensorflow should be the last one to be benchmarked because
-            # as far as I'm aware, there is no way to force it to release
-            # GPU memory. Hence, if any other backend is benchmarked after
-            # Tensorflow and requires the usage of a GPU, it will not have the
-            # full memory available and you may have a GPU Out Of Memory error
-            # even though your GPU can technically hold your tensors in memory.
-            backend_list.pop(i)
-            backend_list.append(nx)
-            break
-
-    inputs = [setup(param) for param in param_list]
-    results = dict()
-    for nx in backend_list:
-        for i in range(len(param_list)):
-            print(nx, param_list[i])
-            args = inputs[i]
-            results_nx = nx._bench(
-                tested_function,
-                *args,
-                n_runs=n_runs,
-                warmup_runs=warmup_runs
-            )
-            gc.collect()
-            results_nx_with_param_in_key = dict()
-            for key in results_nx:
-                new_key = (param_list[i], *key)
-                results_nx_with_param_in_key[new_key] = results_nx[key]
-            results.update(results_nx_with_param_in_key)
-    return results
-
-
-def convert_to_html_table(results, param_name, main_title=None, comments=None):
-    string = "<table>\n"
-    keys = list(results.keys())
-    params, names, devices, bitsizes = zip(*keys)
-
-    devices_names = sorted(list(set(zip(devices, names))))
-    params = sorted(list(set(params)))
-    bitsizes = sorted(list(set(bitsizes)))
-    length = len(devices_names) + 1
-    cpus_cols = list(devices).count("CPU") / len(bitsizes) / len(params)
-    gpus_cols = list(devices).count("GPU") / len(bitsizes) / len(params)
-    assert cpus_cols + gpus_cols == len(devices_names)
-
-    if main_title is not None:
-        string += f'<tr><th align="center" colspan="{length}">{str(main_title)}</th></tr>\n'
-
-    for i, bitsize in enumerate(bitsizes):
-
-        if i != 0:
-            string += f'<tr><td colspan="{length}">&nbsp;</td></tr>\n'
-
-        # make bitsize header
-        text = f"{bitsize} bits"
-        if comments is not None:
-            text += " - "
-            if isinstance(comments, (tuple, list)) and len(comments) == len(bitsizes):
-                text += str(comments[i])
-            else:
-                text += str(comments)
-        string += f'<tr><th align="center">Bitsize</th>'
-        string += f'<th align="center" colspan="{length - 1}">{text}</th></tr>\n'
-
-        # make device header
-        string += f'<tr><th align="center">Device</th>'
-        string += f'<th align="center" colspan="{cpus_cols}">CPU</th>'
-        string += f'<th align="center" colspan="{gpus_cols}">GPU</th></tr>\n'
-
-        # make param_name / backend header
-        string += f'<tr><th align="center">{param_name}</th>'
-        for device, name in devices_names:
-            string += f'<th align="center">{name}</th>'
-        string += "</tr>\n"
-
-        # make results rows
-        for param in params:
-            string += f'<tr><td align="center">{param}</td>'
-            for device, name in devices_names:
-                key = (param, name, device, bitsize)
-                string += f'<td align="center">{results[key]:.4f}</td>'
-            string += "</tr>\n"
-
-    string += "</table>"
-    return string
diff --git a/benchmarks/emd.py b/benchmarks/emd.py
deleted file mode 100644
index 9f64863..0000000
--- a/benchmarks/emd.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# /usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-import numpy as np
-import ot
-from .benchmark import (
-    setup_backends,
-    exec_bench,
-    convert_to_html_table
-)
-
-
-def setup(n_samples):
-    rng = np.random.RandomState(789465132)
-    x = rng.randn(n_samples, 2)
-    y = rng.randn(n_samples, 2)
-
-    a = ot.utils.unif(n_samples)
-    M = ot.dist(x, y)
-    return a, M
-
-
-if __name__ == "__main__":
-    n_runs = 100
-    warmup_runs = 10
-    param_list = [50, 100, 500, 1000, 2000, 5000]
-
-    setup_backends()
-    results = exec_bench(
-        setup=setup,
-        tested_function=lambda a, M: ot.emd(a, a, M),
-        param_list=param_list,
-        n_runs=n_runs,
-        warmup_runs=warmup_runs
-    )
-    print(convert_to_html_table(
-        results, 
-        param_name="Sample size",
-        main_title=f"EMD - Averaged on {n_runs} runs"
-    ))
diff --git a/benchmarks/sinkhorn_knopp.py b/benchmarks/sinkhorn_knopp.py
deleted file mode 100644
index 3a1ef3f..0000000
--- a/benchmarks/sinkhorn_knopp.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# /usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-import numpy as np
-import ot
-from .benchmark import (
-    setup_backends,
-    exec_bench,
-    convert_to_html_table
-)
-
-
-def setup(n_samples):
-    rng = np.random.RandomState(123456789)
-    a = rng.rand(n_samples // 4, 100)
-    b = rng.rand(n_samples, 100)
-
-    wa = ot.unif(n_samples // 4)
-    wb = ot.unif(n_samples)
-
-    M = ot.dist(a.copy(), b.copy())
-    return wa, wb, M
-
-
-if __name__ == "__main__":
-    n_runs = 100
-    warmup_runs = 10
-    param_list = [50, 100, 500, 1000, 2000, 5000]
-
-    setup_backends()
-    results = exec_bench(
-        setup=setup,
-        tested_function=lambda *args: ot.bregman.sinkhorn(*args, reg=1, stopThr=1e-7),
-        param_list=param_list,
-        n_runs=n_runs,
-        warmup_runs=warmup_runs
-    )
-    print(convert_to_html_table(
-        results, 
-        param_name="Sample size",
-        main_title=f"Sinkhorn Knopp - Averaged on {n_runs} runs"
-    ))