nshutils 0.31.0__py3-none-any.whl → 0.31.1__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.
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import contextlib
4
4
  import fnmatch
5
+ import os
5
6
  import tempfile
6
7
  import weakref
7
8
  from collections.abc import Callable, Mapping
@@ -266,7 +267,11 @@ class ActSaveProvider:
266
267
 
267
268
  if save_dir is None:
268
269
  save_dir = Path(tempfile.gettempdir()) / f"actsave-{uuid7str()}"
269
- log.critical(f"No save_dir specified, using {save_dir=}")
270
+ log.warning(
271
+ f"ActSave: Using temporary directory {save_dir} for activations."
272
+ )
273
+ else:
274
+ log.info(f"ActSave enabled. Saving to {save_dir}")
270
275
  self._saver = _Saver(save_dir, lambda: self._prefixes)
271
276
 
272
277
  def disable(self):
@@ -307,6 +312,18 @@ class ActSaveProvider:
307
312
  self._prefixes = []
308
313
  self._disable_count = 0
309
314
 
315
+ # Check for environment variable `ACTSAVE` to automatically enable saving.
316
+ # If set to "1" or "true" (case-insensitive), activations are saved to a temporary directory.
317
+ # If set to a path, activations are saved to that path.
318
+ if env_var := os.environ.get("ACTSAVE"):
319
+ log.info(
320
+ f"`ACTSAVE={env_var}` detected, attempting to auto-enable activation saving."
321
+ )
322
+ if env_var.lower() in ("1", "true"):
323
+ self.enable()
324
+ else:
325
+ self.enable(Path(env_var))
326
+
310
327
  @contextlib.contextmanager
311
328
  def disabled(self, condition: bool | Callable[[], bool] = True):
312
329
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nshutils
3
- Version: 0.31.0
3
+ Version: 0.31.1
4
4
  Summary:
5
5
  Author: Nima Shoghi
6
6
  Author-email: nimashoghi@gmail.com
@@ -2,7 +2,7 @@ nshutils/__init__.py,sha256=AFx1d5k34MyJ2kCHQL5vrZB8GDp2nYUaIUEjszSa25I,477
2
2
  nshutils/__init__.pyi,sha256=R4TIk--jAgVyTibdgezJQTMce3HpMCNakAJeaDqA6bc,676
3
3
  nshutils/actsave/__init__.py,sha256=hAVsog9d1g3_rQN1TRslrl6sK1PhCGbjy8PPUAmJI58,203
4
4
  nshutils/actsave/_loader.py,sha256=btLSQdErpTmK6VyG8PxJrJNsztzyavSF71n4Ec3_49E,7619
5
- nshutils/actsave/_saver.py,sha256=IS9TVP8WUizoj5fHrQ6hodtjidT__LDRwz5aoWHupVo,12013
5
+ nshutils/actsave/_saver.py,sha256=_qkX0NZYvy31hdlyfhneac4kUNS_44XjOG0ZtKpdqrg,12720
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
@@ -16,6 +16,6 @@ nshutils/lovely/torch_.py,sha256=J1pDJY1zzEANqa6EaJpG1pc_SYgM8YWOo1TjWdVeiA0,294
16
16
  nshutils/lovely/utils.py,sha256=2ksT5YGVViFuWc8jSkwVCsABripJmyVJdEDDH7aab70,10459
17
17
  nshutils/snoop.py,sha256=7d7_Q5sJmINL1J29wcnxEvpV95zvZYNoVn5frCq-rww,7393
18
18
  nshutils/typecheck.py,sha256=Gi7xtfilN_UwZ1FTFqBVKDhcQzBEDonVxIv3bUj-uXY,5582
19
- nshutils-0.31.0.dist-info/METADATA,sha256=jfKUJjGuT8R6E09S_MVkV0-_GQilY4J50FxPE9KsowA,4406
20
- nshutils-0.31.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
21
- nshutils-0.31.0.dist-info/RECORD,,
19
+ nshutils-0.31.1.dist-info/METADATA,sha256=pW-XE-rF3TPtok9VPan8cG6IlaEjlX55NBL4SKaNOHQ,4406
20
+ nshutils-0.31.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
21
+ nshutils-0.31.1.dist-info/RECORD,,