facebookresearch/xformers

How to set random seeds fixed

开放

#618 创建于 2023年1月3日

 (17 条评论) (1 个反应) (0 位负责人)Python (473 个派生)batch import
good first issue

仓库指标

星标
 (6,903 个星标)
PR 合并指标
 (平均合并 3天 6小时) (30 天内合并 1 个 PR)

描述

❓ Questions and Help

Different results occur when I run the same code twice. And the set_seed func run before all.

def set_seed(seed):
    random.seed(seed)  # Python random module.
    np.random.seed(seed)  # Numpy module.
    set_seed(seed)
    os.environ['PYTHONHASHSEED'] = str(seed)
    torch.random.manual_seed(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)  # if you are using multi-GPU.
    torch.backends.cudnn.benchmark = cudnn_benchmark
    torch.backends.cudnn.deterministic = cudnn_deterministic

贡献者指南