The documentation states:
Deterministic mode can have a performance impact, depending on your model.
My question is, what is meant by performance here. Processing speed or model quality (i.e. minimal loss)? In other words, when setting manual seeds and making the model perform in a deterministic way, does that cause longer training time until minimal loss is found, or is that minimal loss worse than when the model is non-deterministic?
For completeness' sake, I manually make the model deterministic by setting all of these properties:
def set_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
np.random.seed(seed)
random.seed(seed)
os.environ['PYTHONHASHSEED'] = str(seed)
deterministic = True is set. The latter setting controls only this behavior, unlike torch. use_deterministic_algorithms() which will make other PyTorch operations behave deterministically, too.
seed ()[source] Sets the seed for generating random numbers to a non-deterministic random number. Returns a 64 bit number used to seed the RNG.
DataLoader is not deterministic - vision - PyTorch Forums.
Reproducibility Completely reproducible results are not guaranteed across PyTorch releases, individual commits, or different platforms. Furthermore, results may not be reproducible between CPU and GPU executions, even when using identical seeds.
These benchmarks serve as a standard from which to start new projects or debug current implementations. But pre-trained models are already reproducible… right? In PyTorch, yes.
Furthermore, results may not be reproducible between CPU and GPU executions, even when using identical seeds. However, there are some steps you can take to limit the number of sources of nondeterministic behavior for a specific platform, device, and PyTorch release.
We also should notice: deterministic=True in trainer. However, if you only plan to set a random seed for python, numpy, pytorch. and you do not use pytorch lightning to train mode. seed_everything () is indeed.
Performance refers to the run time; CuDNN has several ways of implementations, when cudnn.deterministic
is set to true, you're telling CuDNN that you only need the deterministic implementations (or what we believe they are). In a nutshell, when you are doing this, you should expect the same results on the CPU or the GPU on the same system when feeding the same inputs. Why would it affect the performance? CuDNN uses heuristics for the choice of the implementation. So, it actually depends on your model how CuDNN will behave; choosing it to be deterministic may affect the runtime because their could have been, let's say, faster way of choosing them at the same point of running.
Concerning your snippet, I do the exact seeding, it has been working good (in terms of reproducibility) for 100+ DL experiments.
"performance" in this context refer to run-time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With