kerops 0.0.4__py3-none-any.whl
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.
- kerops/__init__.py +0 -0
- kerops/__version__.py +1 -0
- kerops/utils.py +102 -0
- kerops-0.0.4.dist-info/LICENSE +21 -0
- kerops-0.0.4.dist-info/METADATA +70 -0
- kerops-0.0.4.dist-info/RECORD +8 -0
- kerops-0.0.4.dist-info/WHEEL +5 -0
- kerops-0.0.4.dist-info/top_level.txt +1 -0
kerops/__init__.py
ADDED
|
File without changes
|
kerops/__version__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '0.0.4'
|
kerops/utils.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
from torch.nn import functional as F
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@torch.no_grad
|
|
6
|
+
def allclose_two_stage(
|
|
7
|
+
input,
|
|
8
|
+
other,
|
|
9
|
+
rtol_strict=1e-4,
|
|
10
|
+
atol_strict=1e-4,
|
|
11
|
+
percentile_strict=0.99,
|
|
12
|
+
rtol_narrow=1e-3,
|
|
13
|
+
atol_narrow=1e-3,
|
|
14
|
+
debug_info=None,
|
|
15
|
+
precision=None,
|
|
16
|
+
):
|
|
17
|
+
if isinstance(debug_info, str):
|
|
18
|
+
if debug_info == 'print':
|
|
19
|
+
debug_info = print
|
|
20
|
+
else:
|
|
21
|
+
raise ValueError(f'Unknown debug_info mode - {debug_info}')
|
|
22
|
+
elif debug_info is None:
|
|
23
|
+
debug_info = lambda x: None
|
|
24
|
+
|
|
25
|
+
assert input.shape == other.shape
|
|
26
|
+
assert input.dtype == other.dtype
|
|
27
|
+
assert input.device == other.device
|
|
28
|
+
|
|
29
|
+
if precision is None:
|
|
30
|
+
precision = input.dtype
|
|
31
|
+
|
|
32
|
+
input = input.reshape(-1)
|
|
33
|
+
other = other.reshape(-1)
|
|
34
|
+
|
|
35
|
+
strict_map = torch.abs(input.to(precision) - other.to(precision)) < atol_strict + rtol_strict * torch.abs(
|
|
36
|
+
other.to(precision)
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
size = input.numel()
|
|
40
|
+
num_true = strict_map.sum().item()
|
|
41
|
+
|
|
42
|
+
ratio = num_true / size
|
|
43
|
+
more_less = '>=' if ratio >= percentile_strict else '<'
|
|
44
|
+
debug_info(f'strict stage - {size=}, {num_true=}, {ratio=} {more_less} percentile_strict')
|
|
45
|
+
|
|
46
|
+
if ratio >= percentile_strict:
|
|
47
|
+
debug_info('Strict threshold has been passed')
|
|
48
|
+
else:
|
|
49
|
+
debug_info('Strict threshold has not been passed')
|
|
50
|
+
|
|
51
|
+
if size == num_true:
|
|
52
|
+
debug_info('Strict threshold has been passed completely, propose decreasing rtol_strict and atol_strict')
|
|
53
|
+
return True
|
|
54
|
+
|
|
55
|
+
if num_true / size > percentile_strict:
|
|
56
|
+
indices = torch.nonzero(~strict_map)
|
|
57
|
+
|
|
58
|
+
input = input[indices].to(precision)
|
|
59
|
+
other = other[indices].to(precision)
|
|
60
|
+
|
|
61
|
+
narrow_map = torch.abs(input - other) < atol_narrow + rtol_narrow * torch.abs(other)
|
|
62
|
+
|
|
63
|
+
if narrow_map.all():
|
|
64
|
+
debug_info('Soft threshold has been passed')
|
|
65
|
+
return True
|
|
66
|
+
else:
|
|
67
|
+
debug_info('Soft threshold has not been passed')
|
|
68
|
+
|
|
69
|
+
return False
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def weight_grad_similarity(input, other, rtol_cos=1e-4, atol_cos=1e-4, rtol_len=1e-3, atol_len=1e-3, debug_info=None):
|
|
73
|
+
if isinstance(debug_info, str):
|
|
74
|
+
if debug_info == 'print':
|
|
75
|
+
debug_info = print
|
|
76
|
+
else:
|
|
77
|
+
raise ValueError(f'Unknown debug_info mode - {debug_info}')
|
|
78
|
+
elif debug_info is None:
|
|
79
|
+
debug_info = lambda x: None
|
|
80
|
+
|
|
81
|
+
assert input.shape == other.shape
|
|
82
|
+
assert input.dtype == other.dtype
|
|
83
|
+
assert input.device == other.device
|
|
84
|
+
|
|
85
|
+
input_flat = input.reshape(-1)
|
|
86
|
+
other_flat = other.reshape(-1)
|
|
87
|
+
|
|
88
|
+
cos_sim = F.cosine_similarity(input_flat, other_flat, dim=0)
|
|
89
|
+
|
|
90
|
+
if not torch.allclose(torch.ones_like(cos_sim), cos_sim, rtol=rtol_cos, atol=atol_cos):
|
|
91
|
+
debug_info(f'Direction test failed - {cos_sim}')
|
|
92
|
+
return False
|
|
93
|
+
|
|
94
|
+
magnitudes_close = torch.allclose(torch.norm(input_flat), torch.norm(other_flat), rtol=rtol_len, atol=atol_len)
|
|
95
|
+
|
|
96
|
+
if not magnitudes_close:
|
|
97
|
+
debug_info(f'Magnitude test failed - {torch.norm(input_flat)=}, {torch.norm(other_flat)=}')
|
|
98
|
+
return False
|
|
99
|
+
|
|
100
|
+
debug_info('All stages passed')
|
|
101
|
+
|
|
102
|
+
return True
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 NeuroML
|
|
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.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: kerops
|
|
3
|
+
Version: 0.0.4
|
|
4
|
+
Summary: Efficient gpu algorithms for 3D computer vision
|
|
5
|
+
Author-email: AnihilatorGun <nikitaushakov.nu35@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 NeuroML
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/neuro-ml/kerops
|
|
29
|
+
Project-URL: Issues, https://github.com/neuro-ml/kerops/issues
|
|
30
|
+
Project-URL: Source, https://github.com/neuro-ml/kerops
|
|
31
|
+
Keywords: computer vision,fast,gpu,triton
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
37
|
+
Requires-Python: >=3.10
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Requires-Dist: triton==3.1.0
|
|
41
|
+
Requires-Dist: torch
|
|
42
|
+
|
|
43
|
+
# Kerops
|
|
44
|
+
Fast algorithms for GPU
|
|
45
|
+
|
|
46
|
+
# Install
|
|
47
|
+
*pip is not available right now*
|
|
48
|
+
```shell
|
|
49
|
+
pip install kerops
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
# How fast is it?
|
|
53
|
+
Time comparison (ms) for NVidia RTX 3090. Input is an array of size (1, channels, 350, 350, 128); float16; <b>channels_last_3d</b>. Compared to usual 3d convolution from torch (kernel_size=3, padding=1, stride=1, bias=False, in_channels=channels, out_channels=channels). Slowdown compared to copying is shown in parentheses.
|
|
54
|
+
|
|
55
|
+
| channels |torch.clone| kerops.ops.DWConv |torch.nn.Conv3d(C->C)|
|
|
56
|
+
|:--------------------:|:---------:|:--------------------:|:-------------------:|
|
|
57
|
+
| 8 | 0.61 | 0.79 (x1.30) | 2.45 (x4.00) |
|
|
58
|
+
| 16 | 1.21 | 1.41 (x1.17) | 4.48 (x3.70) |
|
|
59
|
+
| 32 | 2.40 | 2.99 (x1.25) | 15.3 (x6.38) |
|
|
60
|
+
| 64 | 4.78 | 6.29 (x1.32) | 52.0 (x10.89) |
|
|
61
|
+
| 128 | 9.55 | 12.8 (x1.34) | 195.0 (x20.44) |
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
| channels |torch.clone|kerops.ops.DWConvWGRAD|torch.nn.Conv3d(C->C)|
|
|
65
|
+
|:--------------------:|:---------:|:--------------------:|:-------------------:|
|
|
66
|
+
| 8 | 0.61 | 2.55 (x4.18) | 7.14 (x11.70) |
|
|
67
|
+
| 16 | 1.21 | 3.01 (x2.49) | 12.1 (x10.00) |
|
|
68
|
+
| 32 | 2.40 | 4.80 (x2.00) | 24.6 (x10.25) |
|
|
69
|
+
| 64 | 4.78 | 8.72 (x1.82) | 71.3 (x14.91) |
|
|
70
|
+
| 128 | 9.55 | 17.9 (x1.87) | 245.0 (x25.65) |
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
kerops/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
kerops/__version__.py,sha256=-Wqu9UyJphp-2_EahEsqQvkcE0VBhm1-N7D6e5rANdY,22
|
|
3
|
+
kerops/utils.py,sha256=5u7Os7-Yg4SWVcrGuH6oTG3X2mYtzWf26mta3sUf2eU,3076
|
|
4
|
+
kerops-0.0.4.dist-info/LICENSE,sha256=LonCPuR3Jnmbl8yz0wHOwPq6cGcarL7CJlbEid0UQuk,1064
|
|
5
|
+
kerops-0.0.4.dist-info/METADATA,sha256=AYA07G2lwXLHMDTrGZZqgmBnVngfHS32JtSIJwLA9uo,3615
|
|
6
|
+
kerops-0.0.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
7
|
+
kerops-0.0.4.dist-info/top_level.txt,sha256=YHTrKyF2MwnFx_q2d0elPJdtc3mm__FKoMzb_vWZb7E,7
|
|
8
|
+
kerops-0.0.4.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kerops
|