-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Avoid changing current cudnn benchmark #12020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid changing current cudnn benchmark #12020
Conversation
|
This should likely wait until #11944 is merged, then be updated to ensure the same silent updating of |
Co-authored-by: Adrian Wälchli <[email protected]>
Co-authored-by: Adrian Wälchli <[email protected]>
| (None, False, True), | ||
| (None, False, None), | ||
| (None, True, False), | ||
| (None, None, None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now, somebody that creates Trainer() with no arguments, won't get cudnn.benchmark=True as it does in master?
I think having benchmark=True by default is best.
The proposal in this PR only works if we were able to know if the user had set benchmark manually before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The justification for this change is that Pytorch Lightning shouldn't break standard Pytorch functionality, but extend it. In general, PL offers value by establishing sensible default values so users don't need to think about them usually. However, in this case, we are silently setting a global variable, resulting in this behaviour:
import torch
from pytorch_lightning import Trainer
torch.backends.cudnn.benchmark = False
trainer = Trainer(gpus=1)
print(torch.backends.cudnn.benchmark)Output:
True
# When it should be False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that, but since there's no way for us to know whether the user previously set the value, we have 2 exclusive options:
- Have the better default for most people which may override an existing value (current master)
- Always respect the existing value but users have to remember to set this flag (this PR)
I personally prefer 1 as it establishes a "sensible default". We could request the torch folks to add an optional default so the options are not exclusive in the future.
ccing revierwers @awaelchli @ananthsub @krshrimali to see if they think differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that, but since there's no way for us to know whether the user previously set the value,
We can know, by making the default value for the argument None. A default Trainer() would result in taking the value from torch.backends.cudnn.benchmark which by default is True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
torch.backends.cudnn.benchmark which by default is True
Is it? locally:
$ python -c 'import torch; print(torch.backends.cudnn.benchmark)'
FalseCo-authored-by: Carlos Mocholí <[email protected]>
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If you need further help see our docs: https://pytorch-lightning.readthedocs.io/en/latest/generated/CONTRIBUTING.html#pull-request or ask the assistance of a core contributor here or on Slack. Thank you for your contributions. |
|
This pull request is going to be closed. Please feel free to reopen it create a new from the actual master. |
What does this PR do?
This is a small change that prevents PL from silently overriding
torch.backends.cudnn.benchmarkwhen constructing aTrainerobject.Fixes #12018
With this change, the behaviour can be described by:
For
torch.backends.cudnn.benchmarkto be changed byTraineronly when thebenchmarkarg is explicitly set.Trainer()torch.backends.cudnn.benchmarkis unchanged from current session valueTrainer(benchmark=None)torch.backends.cudnn.benchmarkis unchanged from current session valueTrainer(benchmark=True)torch.backends.cudnn.benchmarkset toTrueTrainer(benchmark=False)torch.backends.cudnn.benchmarkset toFalseDoes your PR introduce any breaking changes? If yes, please list them.
Before submitting
PR review
Anyone in the community is welcome to review the PR.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:
Did you have fun?
Make sure you had fun coding 🙃