torch.manual_seed是否包含torch.cuda.manual_seed_all的运算?如果是,我们可以使用torch.manual_seed来设置种子,否则我们应该同时调用这两个函数。
torch.manual_seed
torch.cuda.manual_seed_all
kfgdxczn1#
是的,torch.manual_seed()确实包含CUDA:您可以使用torch.manual_seed()为所有设备(包括CPU和CUDA)植入RNG:
torch.manual_seed()
sycxhyv72#
请参阅Pytorch lightning's seed_everything:
seed_everything
random.seed(seed) np.random.seed(seed) torch.manual_seed(seed) torch.cuda.manual_seed_all(seed)
让我相信这些都是而且只是所需的种子。
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) ...
3条答案
按热度按时间kfgdxczn1#
是的,
torch.manual_seed()
确实包含CUDA:您可以使用
torch.manual_seed()
为所有设备(包括CPU和CUDA)植入RNG:sycxhyv72#
请参阅Pytorch lightning's
seed_everything
:让我相信这些都是而且只是所需的种子。
eqfvzcg83#
是的,
torch.manual_seed
在内部调用torch.cuda.manual_seed_all
。除@iacob的答案外,还可以在PyTorch源代码中找到其他证据