blazefl.utils.RandomState#

class blazefl.utils.RandomState(random: tuple, environ: str, numpy: dict, torch_seed: int, torch_rng_state: Tensor, cuda: CUDARandomState | None)[source]#

Bases: object

A dataclass representing the random state for Python, NumPy, and PyTorch.

random#

The state of Python’s random module.

Type:

tuple

environ#

The PYTHONHASHSEED environment variable.

Type:

str

numpy#

The state of NumPy’s RNG.

Type:

dict

torch_seed#

The initial seed for PyTorch.

Type:

int

torch_rng_state#

The RNG state for PyTorch.

Type:

torch.Tensor

cuda#

The CUDA-specific random state, if available.

Type:

CUDARandomState | None

__init__(random: tuple, environ: str, numpy: dict, torch_seed: int, torch_rng_state: Tensor, cuda: CUDARandomState | None) None#

Methods

__init__(random, environ, numpy, torch_seed, ...)

get_random_state(device)

Capture the current random state.

set_random_state(random_state)

Restore the random state from a RandomState object.

Attributes

cuda: CUDARandomState | None#
environ: str#
classmethod get_random_state(device: str) RandomState[source]#

Capture the current random state.

Parameters:

device (str) – The device type (‘cpu’ or ‘cuda’).

Returns:

The captured random state.

Return type:

RandomState

numpy: dict#
random: tuple#
static set_random_state(random_state: RandomState) None[source]#

Restore the random state from a RandomState object.

Parameters:

random_state (RandomState) – The random state to restore.

Returns:

None

torch_rng_state: Tensor#
torch_seed: int#