nshutils 0.6.1__py3-none-any.whl → 0.8.0__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.
- nshutils/__init__.py +2 -0
- nshutils/actsave/__init__.py +0 -2
- nshutils/actsave/_saver.py +14 -14
- {nshutils-0.6.1.dist-info → nshutils-0.8.0.dist-info}/METADATA +4 -4
- nshutils-0.8.0.dist-info/RECORD +11 -0
- nshutils-0.6.1.dist-info/RECORD +0 -11
- {nshutils-0.6.1.dist-info → nshutils-0.8.0.dist-info}/WHEEL +0 -0
nshutils/__init__.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
from . import actsave as actsave
|
2
2
|
from . import typecheck as typecheck
|
3
|
+
from .actsave import ActLoad as ActLoad
|
4
|
+
from .actsave import ActSave as ActSave
|
3
5
|
from .logging import init_python_logging as init_python_logging
|
4
6
|
from .logging import lovely as lovely
|
5
7
|
from .logging import pretty as pretty
|
nshutils/actsave/__init__.py
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
from ._loader import ActivationLoader as ActivationLoader
|
2
1
|
from ._loader import ActLoad as ActLoad
|
3
2
|
from ._saver import Activation as Activation
|
4
|
-
from ._saver import ActivationSaver as ActivationSaver
|
5
3
|
from ._saver import ActSave as ActSave
|
6
4
|
from ._saver import Transform as Transform
|
nshutils/actsave/_saver.py
CHANGED
@@ -15,24 +15,25 @@ from typing_extensions import Never, ParamSpec, TypeVar, override
|
|
15
15
|
|
16
16
|
from ..collections import apply_to_collection
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
if not TYPE_CHECKING:
|
19
|
+
try:
|
20
|
+
import torch # type: ignore
|
20
21
|
|
21
|
-
if not TYPE_CHECKING:
|
22
22
|
Tensor: TypeAlias = torch.Tensor
|
23
|
-
except ImportError:
|
24
|
-
|
23
|
+
except ImportError:
|
24
|
+
torch = None
|
25
25
|
|
26
|
-
if not TYPE_CHECKING:
|
27
26
|
Tensor: TypeAlias = Never
|
27
|
+
else:
|
28
|
+
import torch # type: ignore
|
29
|
+
|
30
|
+
Tensor: TypeAlias = torch.Tensor
|
28
31
|
|
29
|
-
if TYPE_CHECKING:
|
30
|
-
Tensor: TypeAlias = Never
|
31
32
|
|
32
33
|
log = getLogger(__name__)
|
33
34
|
|
34
35
|
Value: TypeAlias = int | float | complex | bool | str | np.ndarray | Tensor | None
|
35
|
-
ValueOrLambda = Value | Callable[..., Value]
|
36
|
+
ValueOrLambda: TypeAlias = Value | Callable[..., Value]
|
36
37
|
|
37
38
|
|
38
39
|
def _torch_is_scripting() -> bool:
|
@@ -52,11 +53,11 @@ def _to_numpy(activation: Value) -> np.ndarray:
|
|
52
53
|
elif isinstance(activation, np.ndarray):
|
53
54
|
return activation
|
54
55
|
elif isinstance(activation, Tensor):
|
55
|
-
|
56
|
-
if
|
56
|
+
activation_ = activation.detach()
|
57
|
+
if activation_.is_floating_point():
|
57
58
|
# NOTE: We need to convert to float32 because [b]float16 is not supported by numpy
|
58
|
-
|
59
|
-
return
|
59
|
+
activation_ = activation_.float()
|
60
|
+
return activation_.cpu().numpy()
|
60
61
|
else:
|
61
62
|
log.warning(f"Unrecognized activation type {type(activation)}")
|
62
63
|
|
@@ -357,4 +358,3 @@ class ActSaveProvider:
|
|
357
358
|
|
358
359
|
|
359
360
|
ActSave = ActSaveProvider()
|
360
|
-
ActivationSaver = ActSave
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: nshutils
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.8.0
|
4
4
|
Summary:
|
5
5
|
Author: Nima Shoghi
|
6
6
|
Author-email: nimashoghi@gmail.com
|
@@ -9,10 +9,10 @@ Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: Programming Language :: Python :: 3.10
|
10
10
|
Classifier: Programming Language :: Python :: 3.11
|
11
11
|
Classifier: Programming Language :: Python :: 3.12
|
12
|
-
Requires-Dist: beartype
|
13
|
-
Requires-Dist: jaxtyping
|
12
|
+
Requires-Dist: beartype
|
13
|
+
Requires-Dist: jaxtyping
|
14
14
|
Requires-Dist: numpy
|
15
|
-
Requires-Dist: pysnooper
|
15
|
+
Requires-Dist: pysnooper
|
16
16
|
Requires-Dist: typing-extensions
|
17
17
|
Description-Content-Type: text/markdown
|
18
18
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
nshutils/__init__.py,sha256=ZRdp3KcreswdrusXOGc8aEI07qfBCYQGJYC7NqZ5WPI,324
|
2
|
+
nshutils/actsave/__init__.py,sha256=6gJ49011Ad3kS8BejeZRPj7ZyVyIcmX-VKLEmYZyGM8,167
|
3
|
+
nshutils/actsave/_loader.py,sha256=fAhD32DrJa4onkYfcwc21YIeGEYzOSXCK_HVo9SZLgQ,4604
|
4
|
+
nshutils/actsave/_saver.py,sha256=M7PwFy6faefEDG9hbclbWUNGi1yX7ZjzshdFdmsrtyk,9890
|
5
|
+
nshutils/collections.py,sha256=EE_qLd-LrsX5lsyk9GSKh03Q8bhn9CHB3jiEeNj4uF4,5197
|
6
|
+
nshutils/logging.py,sha256=tL-6XvdvJEEr7bje9DSmUBpm6pnJS9XG_1fuw3U1eME,2573
|
7
|
+
nshutils/snoop.py,sha256=2RNlOcBFnCUyOsfGlbBb8FwSGq03hxfypMfqMA0No-A,7356
|
8
|
+
nshutils/typecheck.py,sha256=_KtfinRy9A0Dgq78kN5MGGrefvb6jn2tGY6svdLEBAs,4915
|
9
|
+
nshutils-0.8.0.dist-info/METADATA,sha256=X5yqqnQA1Pin9-1VvhClw3l7YggpoMAZVUtg3l77LGk,517
|
10
|
+
nshutils-0.8.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
11
|
+
nshutils-0.8.0.dist-info/RECORD,,
|
nshutils-0.6.1.dist-info/RECORD
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
nshutils/__init__.py,sha256=1hxTdQ-e1ym76tdrSAaYoU4Qq5IUt1DRShi7khn7vs8,244
|
2
|
-
nshutils/actsave/__init__.py,sha256=kafzChiViTeOY28GnwKD6yBJfiB7aSU8t1u5cZicdmc,280
|
3
|
-
nshutils/actsave/_loader.py,sha256=fAhD32DrJa4onkYfcwc21YIeGEYzOSXCK_HVo9SZLgQ,4604
|
4
|
-
nshutils/actsave/_saver.py,sha256=xpvnMi4dI8dFwu0tIpJVIp1S4J6FJT5fVYAUTWgvB7A,9885
|
5
|
-
nshutils/collections.py,sha256=EE_qLd-LrsX5lsyk9GSKh03Q8bhn9CHB3jiEeNj4uF4,5197
|
6
|
-
nshutils/logging.py,sha256=tL-6XvdvJEEr7bje9DSmUBpm6pnJS9XG_1fuw3U1eME,2573
|
7
|
-
nshutils/snoop.py,sha256=2RNlOcBFnCUyOsfGlbBb8FwSGq03hxfypMfqMA0No-A,7356
|
8
|
-
nshutils/typecheck.py,sha256=_KtfinRy9A0Dgq78kN5MGGrefvb6jn2tGY6svdLEBAs,4915
|
9
|
-
nshutils-0.6.1.dist-info/METADATA,sha256=N3aKMAQ04xiBd9NvEYlV848JIG5zWjIZgZC20F7IQm0,571
|
10
|
-
nshutils-0.6.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
11
|
-
nshutils-0.6.1.dist-info/RECORD,,
|
File without changes
|