nshtrainer 1.0.0b40__py3-none-any.whl → 1.0.0b41__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/nn/__init__.py CHANGED
@@ -4,6 +4,7 @@ from .mlp import MLP as MLP
4
4
  from .mlp import MLPConfig as MLPConfig
5
5
  from .mlp import MLPConfigDict as MLPConfigDict
6
6
  from .mlp import ResidualSequential as ResidualSequential
7
+ from .mlp import custom_seed_context as custom_seed_context
7
8
  from .module_dict import TypedModuleDict as TypedModuleDict
8
9
  from .module_list import TypedModuleList as TypedModuleList
9
10
  from .nonlinearity import ELUNonlinearityConfig as ELUNonlinearityConfig
nshtrainer/nn/mlp.py CHANGED
@@ -99,6 +99,18 @@ class MLPConfig(C.Config):
99
99
  )
100
100
 
101
101
 
102
+ @contextlib.contextmanager
103
+ def custom_seed_context(seed: int | None):
104
+ with contextlib.ExitStack() as stack:
105
+ if seed is not None:
106
+ stack.enter_context(
107
+ torch.random.fork_rng(devices=range(torch.cuda.device_count()))
108
+ )
109
+ torch.manual_seed(seed)
110
+
111
+ yield
112
+
113
+
102
114
  def MLP(
103
115
  dims: Sequence[int],
104
116
  activation: NonlinearityConfigBase
@@ -140,13 +152,7 @@ def MLP(
140
152
  nn.Sequential: The constructed MLP.
141
153
  """
142
154
 
143
- with contextlib.ExitStack() as stack:
144
- if seed is not None:
145
- stack.enter_context(
146
- torch.random.fork_rng(devices=range(torch.cuda.device_count()))
147
- )
148
- torch.manual_seed(seed)
149
-
155
+ with custom_seed_context(seed):
150
156
  if activation is None:
151
157
  activation = nonlinearity
152
158
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nshtrainer
3
- Version: 1.0.0b40
3
+ Version: 1.0.0b41
4
4
  Summary:
5
5
  Author: Nima Shoghi
6
6
  Author-email: nimashoghi@gmail.com
@@ -117,8 +117,8 @@ nshtrainer/model/base.py,sha256=JL3AmH17GQjQIoMrZl3O0vUI7dj5ZsO5iEJgoLPyzHw,1035
117
117
  nshtrainer/model/mixins/callback.py,sha256=0LPgve4VszHbLipid4mpI1qnnmdGS2spivs0dXLvqHw,3154
118
118
  nshtrainer/model/mixins/debug.py,sha256=1LX9KzeFX9JDPs_a6YCdYDZXLhEk_5rBO2aCqlfBy7w,2087
119
119
  nshtrainer/model/mixins/logger.py,sha256=27H99FuLaxc6_dDLG2pid4E_5E0-eLGnc2Ifpt0HYIM,6066
120
- nshtrainer/nn/__init__.py,sha256=7KCs-GDOynCXAIdwkgAQacc0p3FHLEION50UtrvgAOc,1463
121
- nshtrainer/nn/mlp.py,sha256=OatI_pzAqa2awKfvMY4CnznO-LltLT8NHQPJKSNn8IM,6979
120
+ nshtrainer/nn/__init__.py,sha256=0FgeoaLYtRiSLT8fdPigLD8t-d8DKR8IQDw16JA9lT4,1523
121
+ nshtrainer/nn/mlp.py,sha256=_a8rJJniSCvM08gyQGO-5MUoO18U9_FSGGn3tZL2_U4,7101
122
122
  nshtrainer/nn/module_dict.py,sha256=9plb8aQUx5TUEPhX5jI9u8LrpTeKe7jZAHi8iIqcN8w,2365
123
123
  nshtrainer/nn/module_list.py,sha256=UB43pcwD_3nUke_DyLQt-iXKhWdKM6Zjm84lRC1hPYA,1755
124
124
  nshtrainer/nn/nonlinearity.py,sha256=xmaL4QCRvCxqmaGIOwetJeKK-6IK4m2OV7D3SjxSwJQ,6322
@@ -153,6 +153,6 @@ nshtrainer/util/seed.py,sha256=diMV8iwBKN7Xxt5pELmui-gyqyT80_CZzomrWhNss0k,316
153
153
  nshtrainer/util/slurm.py,sha256=HflkP5iI_r4UHMyPjw9R4dD5AHsJUpcfJw5PLvGYBRM,1603
154
154
  nshtrainer/util/typed.py,sha256=Xt5fUU6zwLKSTLUdenovnKK0N8qUq89Kddz2_XeykVQ,164
155
155
  nshtrainer/util/typing_utils.py,sha256=MjY-CUX9R5Tzat-BlFnQjwl1PQ_W2yZQoXhkYHlJ_VA,442
156
- nshtrainer-1.0.0b40.dist-info/METADATA,sha256=m_MxoWKJnesp95-EClArQl90vTm____cgqMdNJ6n-Ng,988
157
- nshtrainer-1.0.0b40.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
158
- nshtrainer-1.0.0b40.dist-info/RECORD,,
156
+ nshtrainer-1.0.0b41.dist-info/METADATA,sha256=DL9HgN6RP8X8v0sCdTr2IjRSwIBY96NZXe15m5V4y4c,988
157
+ nshtrainer-1.0.0b41.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
158
+ nshtrainer-1.0.0b41.dist-info/RECORD,,