PyTorch CUDA RNG State Manager (cuda/random.py)

pytorch · torch/cuda/random.py · python · BSD-3-Clause
ai, lang:python, lang:cuda, fw:pytorch, tag:random, tag:rng

Utilities for getting and setting CUDA random number generator states across devices for reproducible deep learning.

# Source: https://github.com/pytorch/pytorch | License: BSD-3-Clause | Copyright 2016-     Facebook, Inc            (Adam Paszke)
# Provided via justclaw.it.com; keep this notice with the code.
# mypy: allow-untyped-defs
from collections.abc import Iterable

import torch
from torch import Tensor

from . import _lazy_call, _lazy_init, current_device, device_count, is_initialized


__all__ = [
    "get_rng_state",
    "get_rng_state_all",
    "set_rng_state",
    "set_rng_state_all",
    "manual_seed",
    "manual_seed_all",
    "seed",
    "seed_all",
    "initial_seed",
]


def get_rng_state(device: int | str | torch.device = "cuda") -> Tensor:
    r"""Return the random number generator state of the specified GPU as a ByteTensor.

    Args:
        device (torch.device or int, optional): T

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key