Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set `torch.backends.cudnn.benchmark = True` or not?

Tags:

python

pytorch

I am using pytorch and I wonder if I should use torch.backends.cudnn.benchmark = True. I find on google that I should use it when computation graph does not change. What is computation graph in pytorch?

like image 950
Jing Gu Avatar asked Nov 20 '19 19:11

Jing Gu


People also ask

What does torch backends cuDNN benchmark do?

It enables benchmark mode in cudnn. benchmark mode is good whenever your input sizes for your network do not vary. This way, cudnn will look for the optimal set of algorithms for that particular configuration (which takes some time). This usually leads to faster runtime.

Does PyTorch use cuDNN?

If you are using the PyTorch binaries, they come with cuda and cuDNN built in.

How do I disable cuDNN?

The cuDNN library is not mandatory, but required for full keypoint detection accuracy. In case your graphics card is not compatible with cuDNN, you can disable it by unchecking USE_CUDNN in CMake.

What is cuDNN deterministic?

cudnn. 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.


1 Answers

If your model does not change and your input sizes remain the same - then you may benefit from setting torch.backends.cudnn.benchmark = True.
However, if your model changes: for instance, if you have layers that are only "activated" when certain conditions are met, or you have layers inside a loop that can be iterated a different number of times, then setting torch.backends.cudnn.benchmark = True might stall your execution.

like image 113
Shai Avatar answered Sep 27 '22 15:09

Shai