Skip to content

set_random_seed

Random seed setup method.

It sets up the random seeds for the RPN model prior to model training and testing.

Specifically, this method will set up the random seeds and related configurations of multiple packages, including * numpy * random * torch * torch.cuda * torch.cudnn * torch.mps

Parameters:

Name Type Description Default
random_seed int

The random seed to be setup.

0

Returns:

Type Description
None

This method doesn't have any return values.

Source code in tinybig/util/utility.py
def set_random_seed(random_seed: int = 0):
    """
    Random seed setup method.

    It sets up the random seeds for the RPN model prior to model training and testing.

    Specifically, this method will set up the random seeds and related configurations of multiple packages,
    including
    * numpy
    * random
    * torch
    * torch.cuda
    * torch.cudnn
    * torch.mps

    Parameters
    ----------
    random_seed: int, default = 0
        The random seed to be setup.

    Returns
    -------
    None
        This method doesn't have any return values.
    """
    torch.manual_seed(random_seed)
    random.seed(random_seed)
    np.random.seed(random_seed)
    torch.cuda.manual_seed(random_seed)
    torch.cuda.manual_seed_all(random_seed)  # if using multi-GPU.
    torch.backends.cudnn.deterministic = True
    torch.backends.cudnn.benchmark = False
    if torch.backends.mps.is_available():
        torch.mps.manual_seed(random_seed)