mirror of
https://github.com/RYDE-WORK/lnp_ml.git
synced 2026-09-18 14:23:20 +08:00
19 lines
509 B
Python
19 lines
509 B
Python
"""全局随机种子工具。"""
|
||
|
||
import random
|
||
|
||
import numpy as np
|
||
import torch
|
||
|
||
|
||
def set_global_seed(seed: int) -> None:
|
||
"""固定 random / numpy / torch 种子,提升可复现性。
|
||
|
||
不开启 cudnn deterministic,以免显著拖慢训练;如需严格复现可自行追加:
|
||
torch.backends.cudnn.deterministic = True
|
||
torch.backends.cudnn.benchmark = False
|
||
"""
|
||
random.seed(seed)
|
||
np.random.seed(seed)
|
||
torch.manual_seed(seed)
|
||
torch.cuda.manual_seed_all(seed) |