分布式信号量(Redis)

阅读 12

2023-12-27

在PyTorch中设置随机数生成器的种子值的方法

CPU:可以使用torch.manual_seed()函数

GPU:需要额外设置torch.cuda.manual_seed()来设置GPU上的随机数生成器种子值。

import torch

# 设置随机种子
torch.manual_seed(0)

if torch.cuda.is_available():
    torch.cuda.manual_seed(0)

这样设置种子值后,无论是CPU还是GPU上的随机数生成器都将产生相同的随机数序列。

精彩评论(0)

0 0 举报