nshutils 0.20.0__py3-none-any.whl → 0.22.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.
@@ -9,7 +9,7 @@ from dataclasses import dataclass
9
9
  from functools import wraps
10
10
  from logging import getLogger
11
11
  from pathlib import Path
12
- from typing import TYPE_CHECKING, Generic, TypeAlias, cast, overload
12
+ from typing import TYPE_CHECKING, Generic, Literal, cast, overload
13
13
 
14
14
  import numpy as np
15
15
  from typing_extensions import Never, ParamSpec, TypeAliasType, TypeVar, override
@@ -22,15 +22,17 @@ if not TYPE_CHECKING:
22
22
  import torch # type: ignore
23
23
 
24
24
  Tensor = torch.Tensor
25
+ _torch_installed = True
25
26
  except ImportError:
26
27
  torch = None
28
+ _torch_installed = False
27
29
 
28
30
  Tensor = Never
29
31
  else:
30
32
  import torch # type: ignore
31
33
 
32
34
  Tensor = torch.Tensor
33
-
35
+ _torch_installed: Literal[True] = True
34
36
 
35
37
  log = getLogger(__name__)
36
38
 
@@ -41,7 +43,7 @@ ValueOrLambda = TypeAliasType("ValueOrLambda", Value | Callable[..., Value])
41
43
 
42
44
 
43
45
  def _torch_is_scripting() -> bool:
44
- if torch is None:
46
+ if _torch_installed:
45
47
  return False
46
48
 
47
49
  return torch.jit.is_scripting()
@@ -56,7 +58,7 @@ def _to_numpy(activation: Value) -> np.ndarray:
56
58
  return np.array(activation)
57
59
  elif isinstance(activation, np.ndarray):
58
60
  return activation
59
- elif isinstance(activation, Tensor):
61
+ elif _torch_installed and isinstance(activation, Tensor):
60
62
  activation_ = activation.detach()
61
63
  if activation_.is_floating_point():
62
64
  # NOTE: We need to convert to float32 because [b]float16 is not supported by numpy
nshutils/lovely/config.py CHANGED
@@ -1,15 +1,15 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from dataclasses import dataclass
3
4
  from typing import ClassVar
4
5
 
5
- import nshconfig as C
6
6
  from typing_extensions import Self
7
7
 
8
8
 
9
- class LovelyConfig(C.Config):
9
+ @dataclass
10
+ class LovelyConfig:
10
11
  """
11
12
  This class is used to manage the configuration of the Lovely library.
12
- It inherits from the Config class in the nshconfig module.
13
13
  """
14
14
 
15
15
  precision: int = 3
@@ -1,11 +1,12 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nshutils
3
- Version: 0.20.0
3
+ Version: 0.22.0
4
4
  Summary:
5
5
  Author: Nima Shoghi
6
6
  Author-email: nimashoghi@gmail.com
7
- Requires-Python: >=3.10,<4.0
7
+ Requires-Python: >=3.9,<4.0
8
8
  Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
9
10
  Classifier: Programming Language :: Python :: 3.10
10
11
  Classifier: Programming Language :: Python :: 3.11
11
12
  Classifier: Programming Language :: Python :: 3.12
@@ -16,14 +17,13 @@ Provides-Extra: snoop
16
17
  Requires-Dist: beartype
17
18
  Requires-Dist: jaxtyping
18
19
  Requires-Dist: lazy-loader
19
- Requires-Dist: nshconfig
20
20
  Requires-Dist: numpy
21
21
  Requires-Dist: pysnooper ; extra == "extra"
22
22
  Requires-Dist: pysnooper ; extra == "snoop"
23
23
  Requires-Dist: rich[jupyter] ; extra == "extra"
24
24
  Requires-Dist: rich[jupyter] ; extra == "pprint"
25
- Requires-Dist: treescope ; extra == "extra"
26
- Requires-Dist: treescope ; extra == "pprint"
25
+ Requires-Dist: treescope ; (python_version >= "3.10") and (extra == "extra")
26
+ Requires-Dist: treescope ; (python_version >= "3.10") and (extra == "pprint")
27
27
  Requires-Dist: typing-extensions
28
28
  Requires-Dist: uuid7
29
29
  Project-URL: Homepage, https://github.com/nimashoghi/nshutils
@@ -2,14 +2,14 @@ nshutils/__init__.py,sha256=AFx1d5k34MyJ2kCHQL5vrZB8GDp2nYUaIUEjszSa25I,477
2
2
  nshutils/__init__.pyi,sha256=ICbY2_XBAlXIVOGyK4PQpatmlUFHHc5-bqM4sfFZoAY,613
3
3
  nshutils/actsave/__init__.py,sha256=hAVsog9d1g3_rQN1TRslrl6sK1PhCGbjy8PPUAmJI58,203
4
4
  nshutils/actsave/_loader.py,sha256=mof3HezUNvLliz7macstX6ewXW05L0Mtv3zJyrbmImg,4640
5
- nshutils/actsave/_saver.py,sha256=pvhtkGALxZqjfVVKthTZYcwgx2PGOBmeLCCNwePSm6A,10312
5
+ nshutils/actsave/_saver.py,sha256=LulgC_B7oYtsGjW_I_pnSLrf1k9lmMvHqRxcmfqqrjU,10441
6
6
  nshutils/collections.py,sha256=QWGyANmo4Efq4XRNHDSTE9tRLStwEZHGwE0ATHR-Vqo,5233
7
7
  nshutils/display.py,sha256=Ge63yllx7gi-MKL3mKQeQ5doql_nj56-o5aoTVmusDg,1473
8
8
  nshutils/logging.py,sha256=78pv3-I_gmbKSf5_mYYBr6_H4GNBGErghAdhH9wfYIc,2205
9
9
  nshutils/lovely/__init__.py,sha256=gbWMNs7xfK1CiNdkHvfH0KcyaGjdZ8_WUBGfaEUDN4I,451
10
10
  nshutils/lovely/_base.py,sha256=c2XxNJlEdET2mP2gLzlYY1KHsEN4H9eDD_x8SptuBTA,4277
11
11
  nshutils/lovely/_monkey_patch_all.py,sha256=WZsC6Xp5-Z2GBd6xyZZEsD4C2xNyZy0YBfjZzAy3m8M,2028
12
- nshutils/lovely/config.py,sha256=jsUK_kfEvthL94qxpHxM-Xobdv67sWZpnH_ag4HLTNo,1274
12
+ nshutils/lovely/config.py,sha256=lVNMuU1oUvsYlGN0Sn-m6iOLbJIchVnWDpyHm09nWo8,1224
13
13
  nshutils/lovely/jax_.py,sha256=mPH-tSOzWE27ymupllBnO4O6avvJJxpF2a1-G4dN5Ow,2214
14
14
  nshutils/lovely/numpy_.py,sha256=iHA4BCJIW9IU6DXKEfYbh9RA2xyeXeL0tyHdEja89Sw,1866
15
15
  nshutils/lovely/torch_.py,sha256=3wnXLa-1xwuQVk1fM50mBqOVDv5wZHjfnBwzOnjcFjg,2638
@@ -17,6 +17,6 @@ nshutils/lovely/utils.py,sha256=2ksT5YGVViFuWc8jSkwVCsABripJmyVJdEDDH7aab70,1045
17
17
  nshutils/snoop.py,sha256=7d7_Q5sJmINL1J29wcnxEvpV95zvZYNoVn5frCq-rww,7393
18
18
  nshutils/typecheck.py,sha256=Gi7xtfilN_UwZ1FTFqBVKDhcQzBEDonVxIv3bUj-uXY,5582
19
19
  nshutils/util.py,sha256=tx-XiRbOrpafV3OkJDE5IVFtzn3kN7uSZ8FkMor0H5c,2845
20
- nshutils-0.20.0.dist-info/METADATA,sha256=ha4yqytCPH6u0S3PNQqGBuwCQg9fxuoegr2FN-4ThRo,4316
21
- nshutils-0.20.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
22
- nshutils-0.20.0.dist-info/RECORD,,
20
+ nshutils-0.22.0.dist-info/METADATA,sha256=_N5Hzlby5_zpzat8Dan7ws-ze4ln0On2AcSekA4Te4c,4406
21
+ nshutils-0.22.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
22
+ nshutils-0.22.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.2
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any