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) – 所需的狀態