pytorch torch.manual_seed是否包括torch.cuda.manual_seed_all的操作?

1yjd4xko  于 2022-11-09  发布在  其他
关注(0)|答案(3)|浏览(226)

torch.manual_seed是否包含torch.cuda.manual_seed_all的运算?
如果是,我们可以使用torch.manual_seed来设置种子,否则我们应该同时调用这两个函数。

kfgdxczn

kfgdxczn1#

是的,torch.manual_seed()确实包含CUDA:
您可以使用torch.manual_seed()为所有设备(包括CPU和CUDA)植入RNG:

sycxhyv7

sycxhyv72#

请参阅Pytorch lightning's seed_everything

random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)

让我相信这些都是而且只是所需的种子。

eqfvzcg8

eqfvzcg83#

是的,torch.manual_seed在内部调用torch.cuda.manual_seed_all
除@iacob的答案外,还可以在PyTorch源代码中找到其他证据

def manual_seed(seed) -> torch._C.Generator:
    ...

    if not torch.cuda._is_in_bad_fork():
        torch.cuda.manual_seed_all(seed)

    ...

相关问题