delu.random.get_state#
- delu.random.get_state()[source]#
Aggregate global random states from
random
,numpy
andtorch
.The function is useful for creating checkpoints and allows resuming activities dependent on global random states (e.g. data streams) in a reproducible manner. Also, see the note below. The result of this function can be passed to
set_state
.See also
Example:
# Resuming from a checkpoint: checkpoint_path = ... if checkpoint_path.exists(): checkpoint = torch.load(checkpoint_path) delu.random.set_state(checkpoint['random_state']) ... # Training: for batch in batches: ... if step % checkpoint_frequency == 0: torch.save( { 'model': ..., 'optimizer': ..., 'random_state': delu.random.get_state(), }, checkpoint_path, )