torch.random#
创建于: 2019 年 8 月 7 日 | 最后更新于: 2025 年 6 月 18 日
- torch.random.fork_rng(devices=None, enabled=True, _caller='fork_rng', _devices_kw='devices', device_type='cuda')[源码]#
Forked RNG,这样当你返回时,RNG 会重置为之前的状态。
- 参数
devices (可迭代的设备 ID) – for which to fork the RNG. CPU RNG state is always forked. By default,
fork_rng()
operates on all devices, but will emit a warning if your machine has a lot of devices, since this function will run very slowly in that case. If you explicitly specify devices, this warning will be suppressedenabled (bool) – if
False
, the RNG is not forked. This is a convenience argument for easily disabling the context manager without having to delete it and unindent your Python code under it.device_type (str) – device type str, default is cuda. As for supported device, see details in accelerator
- 返回类型
- torch.random.get_rng_state()[源码]#
将随机数生成器状态作为torch.ByteTensor返回。
注意
返回的状态仅用于 CPU 上的默认生成器。
另请参阅:
torch.random.fork_rng()
。- 返回类型
- torch.random.set_rng_state(new_state)[源码]#
设置随机数生成器状态。
注意
此函数仅适用于 CPU。对于 CUDA,请使用
torch.manual_seed()
,它适用于 CPU 和 CUDA。- 参数
new_state (torch.ByteTensor) – 所需的状态