composer.utils.reproducibility#
Helper utilities for configuring deterministic training to ensure reproducibility.
Note
For deterministic model initialization, seed_all()
and/or
configure_deterministic_mode()
should be
invoked before creating and initializing a model, before creating the Trainer
.
For example:
>>> import torch.nn
>>> from composer.utils import reproducibility
>>> reproducibility.configure_deterministic_mode()
>>> reproducibility.seed_all(42)
>>> model = MyModel()
>>> def init_weights(m):
... if isinstance(m, torch.nn.Linear):
... torch.nn.init.xavier_uniform(m.weight)
>>> # model will now be deterministically initialized, since the seed is set.
>>> init_weights(model)
>>> trainer = Trainer(model=model, seed=42)
Note that the seed must also be passed to the Trainer, otherwise the Trainer
would generate a random seed based on the timestamp (see get_random_seed()
).
- composer.utils.reproducibility.MAX_SEED#
The maximum allowed seed, which is \(2^{32} - 1\).
- Type
Functions
Configure PyTorch deterministic mode. |
|
Get a randomly created seed to use for seeding rng objects. |
|
The state of the RNG objects. |
|
Restore the RNG state. |
|
Seed all rng objects. |