nshtrainer 0.26.0__tar.gz → 0.26.1__tar.gz

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.
Files changed (92) hide show
  1. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/PKG-INFO +1 -1
  2. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/pyproject.toml +1 -1
  3. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/_checkpoint/metadata.py +2 -17
  4. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/_checkpoint/saver.py +2 -8
  5. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/util/path.py +34 -0
  6. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/README.md +0 -0
  7. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/__init__.py +0 -0
  8. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/_callback.py +0 -0
  9. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/_checkpoint/loader.py +0 -0
  10. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/_experimental/__init__.py +0 -0
  11. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/_hf_hub.py +0 -0
  12. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/__init__.py +0 -0
  13. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/_throughput_monitor_callback.py +0 -0
  14. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/actsave.py +0 -0
  15. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/base.py +0 -0
  16. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/checkpoint/__init__.py +0 -0
  17. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/checkpoint/_base.py +0 -0
  18. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/checkpoint/best_checkpoint.py +0 -0
  19. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/checkpoint/last_checkpoint.py +0 -0
  20. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/checkpoint/on_exception_checkpoint.py +0 -0
  21. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/early_stopping.py +0 -0
  22. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/ema.py +0 -0
  23. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/finite_checks.py +0 -0
  24. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/gradient_skipping.py +0 -0
  25. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/interval.py +0 -0
  26. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/log_epoch.py +0 -0
  27. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/norm_logging.py +0 -0
  28. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/print_table.py +0 -0
  29. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/throughput_monitor.py +0 -0
  30. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/timer.py +0 -0
  31. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/callbacks/wandb_watch.py +0 -0
  32. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/data/__init__.py +0 -0
  33. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/data/balanced_batch_sampler.py +0 -0
  34. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/data/transform.py +0 -0
  35. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/__init__.py +0 -0
  36. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/_experimental.py +0 -0
  37. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/actsave.py +0 -0
  38. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/callbacks.py +0 -0
  39. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/config.py +0 -0
  40. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/data.py +0 -0
  41. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/log.py +0 -0
  42. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/lr_scheduler.py +0 -0
  43. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/model.py +0 -0
  44. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/nn.py +0 -0
  45. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/optimizer.py +0 -0
  46. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/runner.py +0 -0
  47. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/snapshot.py +0 -0
  48. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/snoop.py +0 -0
  49. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/trainer.py +0 -0
  50. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/typecheck.py +0 -0
  51. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/ll/util.py +0 -0
  52. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/loggers/__init__.py +0 -0
  53. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/loggers/_base.py +0 -0
  54. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/loggers/csv.py +0 -0
  55. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/loggers/tensorboard.py +0 -0
  56. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/loggers/wandb.py +0 -0
  57. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/lr_scheduler/__init__.py +0 -0
  58. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/lr_scheduler/_base.py +0 -0
  59. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/lr_scheduler/linear_warmup_cosine.py +0 -0
  60. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/lr_scheduler/reduce_lr_on_plateau.py +0 -0
  61. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/metrics/__init__.py +0 -0
  62. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/metrics/_config.py +0 -0
  63. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/model/__init__.py +0 -0
  64. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/model/base.py +0 -0
  65. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/model/config.py +0 -0
  66. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/model/modules/callback.py +0 -0
  67. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/model/modules/debug.py +0 -0
  68. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/model/modules/distributed.py +0 -0
  69. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/model/modules/logger.py +0 -0
  70. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/model/modules/profiler.py +0 -0
  71. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/model/modules/rlp_sanity_checks.py +0 -0
  72. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/model/modules/shared_parameters.py +0 -0
  73. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/nn/__init__.py +0 -0
  74. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/nn/mlp.py +0 -0
  75. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/nn/module_dict.py +0 -0
  76. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/nn/module_list.py +0 -0
  77. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/nn/nonlinearity.py +0 -0
  78. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/optimizer.py +0 -0
  79. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/runner.py +0 -0
  80. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/scripts/find_packages.py +0 -0
  81. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/trainer/__init__.py +0 -0
  82. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/trainer/_runtime_callback.py +0 -0
  83. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/trainer/checkpoint_connector.py +0 -0
  84. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/trainer/signal_connector.py +0 -0
  85. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/trainer/trainer.py +0 -0
  86. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/util/_environment_info.py +0 -0
  87. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/util/_useful_types.py +0 -0
  88. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/util/environment.py +0 -0
  89. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/util/seed.py +0 -0
  90. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/util/slurm.py +0 -0
  91. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/util/typed.py +0 -0
  92. {nshtrainer-0.26.0 → nshtrainer-0.26.1}/src/nshtrainer/util/typing_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: nshtrainer
3
- Version: 0.26.0
3
+ Version: 0.26.1
4
4
  Summary:
5
5
  Author: Nima Shoghi
6
6
  Author-email: nimashoghi@gmail.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "nshtrainer"
3
- version = "0.26.0"
3
+ version = "0.26.1"
4
4
  description = ""
5
5
  authors = ["Nima Shoghi <nimashoghi@gmail.com>"]
6
6
  readme = "README.md"
@@ -1,7 +1,6 @@
1
1
  import copy
2
2
  import datetime
3
3
  import logging
4
- import shutil
5
4
  from collections.abc import Callable
6
5
  from pathlib import Path
7
6
  from typing import TYPE_CHECKING, Any, ClassVar, cast
@@ -11,7 +10,7 @@ import numpy as np
11
10
  import torch
12
11
 
13
12
  from ..util._environment_info import EnvironmentConfig
14
- from ..util.path import compute_file_checksum, get_relative_path
13
+ from ..util.path import compute_file_checksum, try_symlink_or_copy
15
14
 
16
15
  if TYPE_CHECKING:
17
16
  from ..model import BaseConfig, LightningModuleBase
@@ -142,21 +141,7 @@ def _link_checkpoint_metadata(checkpoint_path: Path, linked_checkpoint_path: Pat
142
141
  # Link the metadata files to the new checkpoint
143
142
  path = _metadata_path(checkpoint_path)
144
143
  linked_path = _metadata_path(linked_checkpoint_path)
145
- try:
146
- try:
147
- # linked_path.symlink_to(path)
148
- # We should store the path as a relative path
149
- # to the metadata file to avoid issues with
150
- # moving the checkpoint directory
151
- linked_path.symlink_to(get_relative_path(linked_path, path))
152
- except OSError:
153
- # on Windows, special permissions are required to create symbolic links as a regular user
154
- # fall back to copying the file
155
- shutil.copy(path, linked_path)
156
- except Exception:
157
- log.exception(f"Failed to link {path} to {linked_path}")
158
- else:
159
- log.debug(f"Linked {path} to {linked_path}")
144
+ try_symlink_or_copy(path, linked_path)
160
145
 
161
146
 
162
147
  def _sort_ckpts_by_metadata(
@@ -5,7 +5,7 @@ from pathlib import Path
5
5
 
6
6
  from lightning.pytorch import Trainer
7
7
 
8
- from ..util.path import get_relative_path
8
+ from ..util.path import try_symlink_or_copy
9
9
  from .metadata import _link_checkpoint_metadata, _remove_checkpoint_metadata
10
10
 
11
11
  log = logging.getLogger(__name__)
@@ -34,13 +34,7 @@ def _link_checkpoint(
34
34
  if metadata:
35
35
  _remove_checkpoint_metadata(linkpath)
36
36
 
37
- try:
38
- linkpath.symlink_to(get_relative_path(linkpath, filepath))
39
- except OSError:
40
- # on Windows, special permissions are required to create symbolic links as a regular user
41
- # fall back to copying the file
42
- shutil.copy(filepath, linkpath)
43
-
37
+ try_symlink_or_copy(filepath, linkpath)
44
38
  if metadata:
45
39
  _link_checkpoint_metadata(filepath, linkpath)
46
40
 
@@ -1,8 +1,13 @@
1
1
  import hashlib
2
+ import logging
2
3
  import os
4
+ import platform
5
+ import shutil
3
6
  from pathlib import Path
4
7
  from typing import TypeAlias
5
8
 
9
+ log = logging.getLogger(__name__)
10
+
6
11
  _Path: TypeAlias = str | Path | os.PathLike
7
12
 
8
13
 
@@ -68,3 +73,32 @@ def compute_file_checksum(file_path: Path) -> str:
68
73
  for byte_block in iter(lambda: f.read(4096), b""):
69
74
  sha256_hash.update(byte_block)
70
75
  return sha256_hash.hexdigest()
76
+
77
+
78
+ def try_symlink_or_copy(
79
+ file_path: Path,
80
+ link_path: Path,
81
+ target_is_directory: bool = False,
82
+ relative: bool = True,
83
+ ):
84
+ """
85
+ Symlinks on Unix, copies on Windows.
86
+ """
87
+
88
+ symlink_target = get_relative_path(link_path, file_path) if relative else file_path
89
+ try:
90
+ if platform.system() == "Windows":
91
+ if target_is_directory:
92
+ shutil.copytree(file_path, link_path)
93
+ else:
94
+ shutil.copy(file_path, link_path)
95
+ else:
96
+ link_path.symlink_to(
97
+ symlink_target, target_is_directory=target_is_directory
98
+ )
99
+ except Exception:
100
+ log.exception(f"Failed to create symlink or copy {file_path} to {link_path}")
101
+ return False
102
+ else:
103
+ log.debug(f"Created symlink or copied {file_path} to {link_path}")
104
+ return True
File without changes