Utilities
Minnt framework also provides a few utilities for startup initialization, parameter initialization override, and the current version.
minnt.global_keras_initializers
global_keras_initializers(
parameter_initialization: bool = True,
batchnorm_momentum_override: float | None = 0.01,
norm_layer_epsilon_override: float | None = 0.001,
) -> None
Change default PyTorch initializers to Keras defaults.
The following initializers are used:
Linear
,Conv1d
,Conv2d
,Conv3d
,ConvTranspose1d
,ConvTranspose2d
,ConvTranspose3d
,Bilinear
: Xavier uniform for weights, zeros for biases.Embedding
,EmbeddingBag
: Uniform [-0.05, 0.05] for weights.RNN
,RNNCell
,LSTM
,LSTMCell
,GRU
,GRUCell
: Xavier uniform for input weights, orthogonal for recurrent weights, zeros for biases (with LSTM forget gate bias set to 1).
Furthermore, for batch normalization layers, the default momentum value is changed from 0.1 to the Keras default of 0.01 (or any other value specified).
Finally, for batch normalization, layer normalization, and group normalization layers, the default epsilon value is changed from 1e-5 to the Keras default of 1e-3 (or any other value specified).
Parameters:
-
parameter_initialization
(bool
, default:True
) –If True, override the default PyTorch initializers with Keras defaults.
-
batchnorm_momentum_override
(float | None
, default:0.01
) –If not None, override the default value of batch normalization momentum from 0.1 to this value.
-
norm_layer_epsilon_override
(float | None
, default:0.001
) –If not None, override the default value of epsilon for batch normalization, layer normalization, and group normalization layers from 1e-5 to this value.
Source code in minnt/initializers_override.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
minnt.startup
startup(
seed: int | None = None,
threads: int | None = None,
*,
forkserver_instead_of_fork: bool = True,
allow_tf32: bool = True,
expandable_segments: bool | None = True
) -> None
Initialize the environment.
- Set the random seed if given.
- Set the number of threads if given.
- Use
forkserver
instead offork
multiprocessing start method unless disallowed. - Allow using TF32 for matrix multiplication unless disallowed.
- Enable expandable segments in the CUDA memory allocator unless disallowed.
Parameters:
-
seed
(int | None
, default:None
) –If not
None
, set the Python, Numpy, and PyTorch random seeds to this value. -
threads
(int | None
, default:None
) –If not
None
of 0, set the number of threads to this value. Otherwise, use as many threads as cores. -
forkserver_instead_of_fork
(bool
, default:True
) –If
True
, useforkserver
instead offork
as the default start multiprocessing method. This will be the default one in Python 3.14. -
allow_tf32
(bool
, default:True
) –If
False
, disable TF32 for matrix multiplication even when available. -
expandable_segments
(bool | None
, default:True
) –If
True
, enable expandable segments in the CUDA memory allocator; ifFalse
, disable them; ifNone
, do not change the current setting.
Environment variables: The following environment variables can be used to override the method parameters:
MINNT_START_METHOD
: If set tofork
orforkserver
, uses the specified method as the multiprocessing start method.MINNT_ALLOW_TF32
: If set to0
or1
, overrides theallow_tf32
parameter.MINTT_EXPANDABLE_SEGMENTS
: If set to0
or1
, overrides theexpandable_segments
parameter.
Source code in minnt/startup.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
minnt.__version__
module-attribute
__version__ = '0.0.4-alpha'