nshtrainer 0.1.0__py3-none-any.whl → 0.1.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.
- nshtrainer/__init__.py +0 -16
- nshtrainer/callbacks/__init__.py +3 -2
- nshtrainer/callbacks/base.py +3 -4
- nshtrainer/lr_scheduler/__init__.py +3 -2
- nshtrainer/lr_scheduler/_base.py +3 -6
- nshtrainer/lr_scheduler/linear_warmup_cosine.py +5 -5
- nshtrainer/lr_scheduler/reduce_lr_on_plateau.py +5 -4
- nshtrainer/model/__init__.py +0 -4
- nshtrainer/model/base.py +9 -71
- nshtrainer/model/config.py +39 -141
- nshtrainer/nn/nonlinearity.py +3 -4
- nshtrainer/optimizer.py +3 -7
- nshtrainer/runner.py +15 -5
- nshtrainer/trainer/signal_connector.py +22 -11
- nshtrainer/trainer/trainer.py +1 -1
- nshtrainer/typecheck.py +1 -0
- {nshtrainer-0.1.0.dist-info → nshtrainer-0.1.1.dist-info}/METADATA +13 -2
- {nshtrainer-0.1.0.dist-info → nshtrainer-0.1.1.dist-info}/RECORD +19 -27
- nshtrainer/_submit/print_environment_info.py +0 -31
- nshtrainer/_submit/session/_output.py +0 -12
- nshtrainer/_submit/session/_script.py +0 -109
- nshtrainer/_submit/session/lsf.py +0 -467
- nshtrainer/_submit/session/slurm.py +0 -573
- nshtrainer/_submit/session/unified.py +0 -350
- nshtrainer/config.py +0 -289
- nshtrainer/util/singleton.py +0 -89
- {nshtrainer-0.1.0.dist-info → nshtrainer-0.1.1.dist-info}/WHEEL +0 -0
nshtrainer/util/singleton.py
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
from logging import getLogger
|
|
2
|
-
from typing import Any
|
|
3
|
-
|
|
4
|
-
from typing_extensions import Self, TypeVar, override
|
|
5
|
-
|
|
6
|
-
log = getLogger(__name__)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class Singleton:
|
|
10
|
-
singleton_key = "_singleton_instance"
|
|
11
|
-
|
|
12
|
-
@classmethod
|
|
13
|
-
def get(cls) -> Self | None:
|
|
14
|
-
return getattr(cls, cls.singleton_key, None)
|
|
15
|
-
|
|
16
|
-
@classmethod
|
|
17
|
-
def set(cls, instance: Self) -> None:
|
|
18
|
-
if cls.get() is not None:
|
|
19
|
-
log.warning(f"{cls.__qualname__} instance is already set")
|
|
20
|
-
|
|
21
|
-
setattr(cls, cls.singleton_key, instance)
|
|
22
|
-
|
|
23
|
-
@classmethod
|
|
24
|
-
def reset(cls) -> None:
|
|
25
|
-
if cls.get() is not None:
|
|
26
|
-
delattr(cls, cls.singleton_key)
|
|
27
|
-
|
|
28
|
-
@classmethod
|
|
29
|
-
def register(cls, instance: Self) -> None:
|
|
30
|
-
cls.set(instance)
|
|
31
|
-
|
|
32
|
-
def register_self(self):
|
|
33
|
-
self.register(self)
|
|
34
|
-
|
|
35
|
-
@classmethod
|
|
36
|
-
def instance(cls) -> Self:
|
|
37
|
-
instance = cls.get()
|
|
38
|
-
if instance is None:
|
|
39
|
-
raise RuntimeError(f"{cls.__qualname__} instance is not set")
|
|
40
|
-
|
|
41
|
-
return instance
|
|
42
|
-
|
|
43
|
-
@override
|
|
44
|
-
def __init_subclass__(cls, *args, **kwargs) -> None:
|
|
45
|
-
super().__init_subclass__(*args, **kwargs)
|
|
46
|
-
|
|
47
|
-
cls.reset()
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
T = TypeVar("T", infer_variance=True)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
class Registry:
|
|
54
|
-
_registry: dict[type, Any] = {}
|
|
55
|
-
|
|
56
|
-
@staticmethod
|
|
57
|
-
def register(cls_: type[T], instance: T):
|
|
58
|
-
if not isinstance(instance, cls_):
|
|
59
|
-
raise ValueError(f"{instance} is not an instance of {cls_.__qualname__}")
|
|
60
|
-
|
|
61
|
-
if cls_ in Registry._registry:
|
|
62
|
-
raise ValueError(f"{cls_.__qualname__} is already registered")
|
|
63
|
-
|
|
64
|
-
Registry._registry[cls_] = instance
|
|
65
|
-
|
|
66
|
-
@staticmethod
|
|
67
|
-
def try_get(cls_: type[T]) -> T | None:
|
|
68
|
-
return Registry._registry.get(cls_)
|
|
69
|
-
|
|
70
|
-
@staticmethod
|
|
71
|
-
def get(cls_: type[T]) -> T:
|
|
72
|
-
instance = Registry.try_get(cls_)
|
|
73
|
-
if instance is None:
|
|
74
|
-
raise ValueError(f"{cls_.__qualname__} is not registered")
|
|
75
|
-
|
|
76
|
-
return instance
|
|
77
|
-
|
|
78
|
-
@staticmethod
|
|
79
|
-
def instance(cls_: type[T]) -> T:
|
|
80
|
-
return Registry.get(cls_)
|
|
81
|
-
|
|
82
|
-
@staticmethod
|
|
83
|
-
def reset(cls_: type[T]):
|
|
84
|
-
if cls_ in Registry._registry:
|
|
85
|
-
del Registry._registry[cls_]
|
|
86
|
-
|
|
87
|
-
@staticmethod
|
|
88
|
-
def reset_all():
|
|
89
|
-
Registry._registry.clear()
|
|
File without changes
|