OpenNMT-py icon indicating copy to clipboard operation
OpenNMT-py copied to clipboard

set random seed for a multi-GPU model

Open Galaxy-Husky opened this issue 7 months ago • 1 comments

Hi, I have a question about how to set seed when using multi gpus.

The following code snippet uses torch.cuda.manul_seed funciton.

if is_cuda and seed > 0:
        # These ensure same initialization in multi gpu mode
        torch.cuda.manual_seed(seed)

But I found a warning in the document of torch.cuda.manual_seed, which says "If you are working with a multi-GPU model, this function is insufficient to get determinism. To seed all GPUs, use manual_seed_all()."

Would it be better to change torch.cuda.manual_seed(seed) to torch.cuda.manual_seed_all(seed) ?

Galaxy-Husky avatar Nov 15 '23 04:11 Galaxy-Husky

Thanks. Have you tried to run twice the same run? not getting the same results in multi gpus ?

vince62s avatar Nov 15 '23 14:11 vince62s