Move DP warning suppression to the DataParallel Plugin (#7421)

This commit is contained in:
ananthsub 2021-05-07 14:02:44 -07:00 committed by GitHub
parent fecce50355
commit f9e050c5e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 29 deletions

View File

@ -19,6 +19,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Changed `clip_grad_norm` to use `torch.nn.utils.clip_grad_norm_` ([#7025](https://github.com/PyTorchLightning/pytorch-lightning/pull/7025))
- Moved `ignore_scalar_return_in_dp` warning suppression to the DataParallelPlugin class ([#7421](https://github.com/PyTorchLightning/pytorch-lightning/pull/7421/))
### Deprecated

View File

@ -38,5 +38,3 @@ Alumni
- Jeff Ling (`jeffling <https://github.com/jeffling>`_)
- Teddy Koker (`teddykoker <https://github.com/teddykoker>`_)
- Nate Raw (`nateraw <https://github.com/nateraw>`_)

View File

@ -26,6 +26,15 @@ from pytorch_lightning.utilities import rank_zero_warn
from pytorch_lightning.utilities.apply_func import apply_to_collection
def _ignore_scalar_return_in_dp():
# Users get confused by this warning so we silence it
warnings.filterwarnings(
'ignore',
message='Was asked to gather along dimension 0, but all input tensors were scalars;'
' will instead unsqueeze and return a vector.'
)
class LightningDataParallel(DataParallel):
def __init__(self, module: LightningModule, *args, **kwargs):
@ -70,6 +79,7 @@ class LightningParallelModule(_LightningModuleWrapperBase):
def __init__(self, pl_module: LightningModule):
super().__init__(pl_module)
_ignore_scalar_return_in_dp()
def forward(self, *inputs, **kwargs):
self.update_replica_device_attributes(inputs)

View File

@ -1,27 +0,0 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings
def ignore_scalar_return_in_dp():
# Users get confused by this warning so we silence it
warnings.filterwarnings(
'ignore',
message='Was asked to gather along dimension 0, but all input tensors were scalars;'
' will instead unsqueeze and return a vector.'
)
ignore_scalar_return_in_dp()