nshtrainer 0.11.11__py3-none-any.whl → 0.11.12__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.
@@ -137,7 +137,11 @@ def _link_checkpoint_metadata(checkpoint_path: Path, linked_checkpoint_path: Pat
137
137
  linked_path = linked_checkpoint_path.with_suffix(METADATA_PATH_SUFFIX)
138
138
  try:
139
139
  try:
140
- linked_path.symlink_to(path)
140
+ # linked_path.symlink_to(path)
141
+ # We should store the path as a relative path
142
+ # to the metadata file to avoid issues with
143
+ # moving the checkpoint directory
144
+ linked_path.symlink_to(path.relative_to(linked_path.parent))
141
145
  except OSError:
142
146
  # on Windows, special permissions are required to create symbolic links as a regular user
143
147
  # fall back to copying the file
@@ -12,22 +12,25 @@ def _link_checkpoint(
12
12
  linkpath: str | Path | os.PathLike,
13
13
  *,
14
14
  metadata: bool,
15
+ remove_existing: bool = True,
15
16
  ):
16
17
  if not isinstance(filepath, Path):
17
18
  filepath = Path(filepath)
18
19
  if not isinstance(linkpath, Path):
19
20
  linkpath = Path(linkpath)
20
21
 
21
- if linkpath.exists():
22
- if linkpath.is_symlink() or linkpath.is_file():
23
- linkpath.unlink()
24
- elif linkpath.is_dir():
25
- shutil.rmtree(linkpath)
26
- _remove_checkpoint_metadata(linkpath)
22
+ if remove_existing:
23
+ if linkpath.exists():
24
+ if linkpath.is_symlink() or linkpath.is_file():
25
+ linkpath.unlink()
26
+ elif linkpath.is_dir():
27
+ shutil.rmtree(linkpath)
28
+
29
+ if metadata:
30
+ _remove_checkpoint_metadata(linkpath)
27
31
 
28
32
  try:
29
- target_path = filepath.relative_to(linkpath.parent)
30
- linkpath.symlink_to(target_path)
33
+ linkpath.symlink_to(filepath.relative_to(linkpath.parent))
31
34
  except OSError:
32
35
  # on Windows, special permissions are required to create symbolic links as a regular user
33
36
  # fall back to copying the file
@@ -3,7 +3,6 @@ import logging
3
3
  import os
4
4
  import string
5
5
  import time
6
- import warnings
7
6
  from abc import ABC, abstractmethod
8
7
  from collections.abc import Iterable, Sequence
9
8
  from datetime import timedelta
@@ -50,10 +49,6 @@ from ..util._environment_info import EnvironmentConfig
50
49
  log = logging.getLogger(__name__)
51
50
 
52
51
 
53
- class IdSeedWarning(Warning):
54
- pass
55
-
56
-
57
52
  class BaseProfilerConfig(C.Config, ABC):
58
53
  dirpath: str | Path | None = None
59
54
  """
@@ -1478,35 +1473,12 @@ class BaseConfig(C.Config):
1478
1473
  _rng: ClassVar[np.random.Generator | None] = None
1479
1474
 
1480
1475
  @staticmethod
1481
- def generate_id(
1482
- *,
1483
- length: int = 8,
1484
- ignore_rng: bool = False,
1485
- ) -> str:
1476
+ def generate_id(*, length: int = 8) -> str:
1486
1477
  """
1487
1478
  Generate a random ID of specified length.
1488
1479
 
1489
- Args:
1490
- length (int): The length of the generated ID. Default is 8.
1491
- ignore_rng (bool): If True, ignore the global random number generator and use a new one. Default is False.
1492
-
1493
- Returns:
1494
- str: The generated random ID.
1495
-
1496
- Raises:
1497
- IdSeedWarning: If the global random number generator is None and ignore_rng is False.
1498
-
1499
- Notes:
1500
- - The generated IDs will not be reproducible if the global random number generator is None and ignore_rng is False.
1501
- - To ensure reproducibility, call BaseConfig.set_seed(...) before generating any IDs.
1502
1480
  """
1503
- rng = BaseConfig._rng if not ignore_rng else np.random.default_rng()
1504
- if rng is None:
1505
- warnings.warn(
1506
- "BaseConfig._rng is None. The generated IDs will not be reproducible. "
1507
- + "To fix this, call BaseConfig.set_seed(...) before generating any IDs.",
1508
- category=IdSeedWarning,
1509
- )
1481
+ if (rng := BaseConfig._rng) is None:
1510
1482
  rng = np.random.default_rng()
1511
1483
 
1512
1484
  alphabet = list(string.ascii_lowercase + string.digits)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nshtrainer
3
- Version: 0.11.11
3
+ Version: 0.11.12
4
4
  Summary:
5
5
  Author: Nima Shoghi
6
6
  Author-email: nimashoghi@gmail.com
@@ -1,7 +1,7 @@
1
1
  nshtrainer/__init__.py,sha256=39loiLLXbaGiozEsAn8mPHopxaPsek8JsgR9DD2gxtY,583
2
2
  nshtrainer/_checkpoint/loader.py,sha256=DSaNR8194kWon4O1svslNsCcN_8vlyLbF0LNCPfUpzI,13789
3
- nshtrainer/_checkpoint/metadata.py,sha256=n2PMGdA3Jn3BuoyDXVCF9dUnNjuuru5CL9jqMD-X4Vk,4918
4
- nshtrainer/_checkpoint/saver.py,sha256=TuSAP39DOOVvSnSukQ9RitMV60JnDg6L27fMRc2uVJc,1358
3
+ nshtrainer/_checkpoint/metadata.py,sha256=onmetLp5eKbA86abq1PTkwAOO7bWj7Pa1EGUjl2TEjQ,5153
4
+ nshtrainer/_checkpoint/saver.py,sha256=DkbCH0YeOJ71m32vAARiQdGBf0hvwwdoAV8LOFGy-0Y,1428
5
5
  nshtrainer/_experimental/__init__.py,sha256=2tQIcrWT8U8no_AeBTYnozaTmxN40kuAJdGQ4b-PoWM,120
6
6
  nshtrainer/_experimental/flops/__init__.py,sha256=edo9Ez3LlrnxkNRX9W6YBhPkRPKYGLpkpnl5gx7sEX8,1550
7
7
  nshtrainer/_experimental/flops/flop_counter.py,sha256=-sL0Fy6poXa__hyzUMdZScjPULp4coQELQpPU6p6dXU,25736
@@ -54,7 +54,7 @@ nshtrainer/metrics/__init__.py,sha256=ObLIELGguIEcUpRsUkqh1ltrvZii6vglTpJGrPvoy0
54
54
  nshtrainer/metrics/_config.py,sha256=jgRBfDAQLFTW7AiUY7CRtdfts6CR6keeuqm0FFMWCzQ,1288
55
55
  nshtrainer/model/__init__.py,sha256=RlGW5a46DZcqK6cYICYxDaKpZIEj-8zLxoMrl432tno,1429
56
56
  nshtrainer/model/base.py,sha256=AXRfEsFAT0Ln7zjYVPU5NgtHS_c8FZM-M4pyLamO7OA,17516
57
- nshtrainer/model/config.py,sha256=F-doUiqPVw4yepT6FRqhflEiiMEWr_PuFC6lKzFWktA,53809
57
+ nshtrainer/model/config.py,sha256=3qSaXNjpKnxF60LbfpONsVhjtrteLEdHkjb5KAhAnIk,52757
58
58
  nshtrainer/model/modules/callback.py,sha256=K0-cyEtBcQhI7Q2e-AGTE8T-GghUPY9DYmneU6ULV6g,6401
59
59
  nshtrainer/model/modules/debug.py,sha256=Yy7XEdPou9BkCsD5hJchwJGmCVGrfUru5g9VjPM4uAw,1120
60
60
  nshtrainer/model/modules/distributed.py,sha256=ABpR9d-3uBS_fivfy_WYW-dExW6vp5BPaoPQnOudHng,1725
@@ -82,6 +82,6 @@ nshtrainer/util/seed.py,sha256=Or2wMPsnQxfnZ2xfBiyMcHFIUt3tGTNeMMyOEanCkqs,280
82
82
  nshtrainer/util/slurm.py,sha256=rofIU26z3SdL79SF45tNez6juou1cyDLz07oXEZb9Hg,1566
83
83
  nshtrainer/util/typed.py,sha256=NGuDkDzFlc1fAoaXjOFZVbmj0mRFjsQi1E_hPa7Bn5U,128
84
84
  nshtrainer/util/typing_utils.py,sha256=8ptjSSLZxlmy4FY6lzzkoGoF5fGNClo8-B_c0XHQaNU,385
85
- nshtrainer-0.11.11.dist-info/METADATA,sha256=GaYo1g6duhsnTuAEE1OVxBUJLI1kTfpPDzH7qNiKDUM,861
86
- nshtrainer-0.11.11.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
87
- nshtrainer-0.11.11.dist-info/RECORD,,
85
+ nshtrainer-0.11.12.dist-info/METADATA,sha256=Lthmwj2EpbkCNWlDg2n7z4zS197Pn5Kt1aUMayB70oo,861
86
+ nshtrainer-0.11.12.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
87
+ nshtrainer-0.11.12.dist-info/RECORD,,