blazefl.reproducibility.RandomStateSnapshot#

class blazefl.reproducibility.RandomStateSnapshot(environ: str, python: tuple[Any, ...], numpy: tuple[str, ndarray[tuple[Any, ...], dtype[uint32]], int, int, float], torch_cpu: Tensor, torch_cuda: Tensor | None)[source]#

Bases: object

A snapshot of the global random state for major libraries.

This class provides a mechanism to capture the exact state of the global random number generators and later restore it. This is useful for scenarios that require resuming a process from a specific point in time with the identical sequence of random numbers.

environ#

The value of the PYTHONHASHSEED environment variable.

Type:

str

python#

The internal state of Python’s random module.

Type:

tuple[Any, …]

numpy#

The internal state of NumPy’s legacy random number generator.

Type:

tuple[str, numpy.ndarray[tuple[Any, …], numpy.dtype[numpy.uint32]], int, int, float]

torch_cpu#

The RNG state of the PyTorch CPU generator.

Type:

torch.Tensor

torch_cuda#

The RNG state of the PyTorch CUDA generator, if available.

Type:

torch.Tensor | None

__init__(environ: str, python: tuple[Any, ...], numpy: tuple[str, ndarray[tuple[Any, ...], dtype[uint32]], int, int, float], torch_cpu: Tensor, torch_cuda: Tensor | None) None#

Methods

__init__(environ, python, numpy, torch_cpu, ...)

capture()

Captures the current global random state.

restore(snapshot)

Restores the global random state from a snapshot object.

Attributes

classmethod capture() RandomStateSnapshot[source]#

Captures the current global random state.

Returns:

A RandomStateSnapshot instance containing the captured states.

environ: str#
numpy: tuple[str, ndarray[tuple[Any, ...], dtype[uint32]], int, int, float]#
python: tuple[Any, ...]#
static restore(snapshot: RandomStateSnapshot) None[source]#

Restores the global random state from a snapshot object.

Parameters:

snapshot – The RandomStateSnapshot to restore from.

torch_cpu: Tensor#
torch_cuda: Tensor | None#