Menu

Reproducing a paper in Python: a random seed is only the first step
📰

Reproducing a paper in Python: a random seed is only the first step

DEV Community: pytorch·wanqiuxu·5 days ago
#MEMBOVQe
#devtopytorch#devto#dev#seed#random
Reading 0:00
15s threshold

You follow a machine learning or experimental paper, run the code, and the loss curve or the reported metric doesn't match. You move the same script to another machine, and the numbers move again. The first guess is almost always: I forgot to set a random seed. So you add torch.manual_seed(0) , and the problem is still there. A seed is necessary. It is usually the first link in the chain, not the whole chain.

A more accurate reading is this: the mismatch often isn't "you forgot the seed." There is more than one source of randomness, and more than one runtime environment. PyTorch's official documentation is blunt about it: completely reproducible results are not guaranteed across PyTorch releases, individual commits, or different platforms. Even with identical seeds, results may differ between CPU and GPU.

More than one generator

Start by taking "random" apart. A training script can easily be using several independent generators at once.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.