Module openpack_torch.utils

Expand source code
from .random import reset_seed

__all__ = ["reset_seed"]

Sub-modules

openpack_torch.utils.random
openpack_torch.utils.test_helper

Functions

def reset_seed(seed: int = 0) ‑> None

Reset random seed (random, numpy, torch-cpu, torch-cuda) for reproducibility.

Args

seed : int
random seed. (Default: 1)

Returns

None

Expand source code
def reset_seed(seed: int = 0) -> None:
    """Reset random seed (random, numpy, torch-cpu, torch-cuda) for reproducibility.

    Args:
        seed (int): random seed. (Default: 1)
    Returns:
        None
    """
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed(seed)
    logger.info(
        "Reset Seeds: python={}, numpy={}, Pytorch (cpu={}, cuda={})".format(
            seed, seed, seed, seed
        )
    )