确定性计算

https://chenglu.me/blogs/deterministic-algorithms

Pasted image 20240821103633.png

export HCCL_DETERMINISTIC=True

def seed_all(seed=1234, mode=False):
	random.seed(seed)
	os.environ['PYTHONHASHSEED'] = str(seed)
	np.random.seed(seed)
	torch.manual_seed(seed)
	torch.use_deterministic_algorithms(mode)
	torch_npu.npu.manual_seed_all(seed)
	torch_npu.npu.manual_seed(seed)
	
seed_all(mode=True)