From 0a66f7ced1e5c5b131fcb5bd1afc43a60e58f7fe Mon Sep 17 00:00:00 2001 From: Carlos Mocholi Date: Thu, 11 Nov 2021 04:26:44 +0100 Subject: [PATCH 1/3] Fix `to_torchscript()` causing false positive deprecation warnings --- pytorch_lightning/core/lightning.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py index 7867211badb35..908b653736c98 100644 --- a/pytorch_lightning/core/lightning.py +++ b/pytorch_lightning/core/lightning.py @@ -115,6 +115,8 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self._param_requires_grad_state = {} self._metric_attributes: Optional[Dict[int, str]] = None self._should_prevent_trainer_and_dataloaders_deepcopy: bool = False + # TODO: remove after the 1.6 release + self._running_torchscript = False self._register_sharded_tensor_state_dict_hooks_if_available() @@ -1908,6 +1910,8 @@ def to_torchscript( """ mode = self.training + self._running_torchscript = True + if method == "script": torchscript_module = torch.jit.script(self.eval(), **kwargs) elif method == "trace": @@ -1942,11 +1946,12 @@ def model_size(self) -> float: Note: This property will not return correct value for Deepspeed (stage 3) and fully-sharded training. """ - rank_zero_deprecation( - "The `LightningModule.model_size` property was deprecated in v1.5 and will be removed in v1.7." - " Please use the `pytorch_lightning.utilities.memory.get_model_size_mb`.", - stacklevel=5, - ) + if not self._running_torchscript: # remove with the deprecation removal + rank_zero_deprecation( + "The `LightningModule.model_size` property was deprecated in v1.5 and will be removed in v1.7." + " Please use the `pytorch_lightning.utilities.memory.get_model_size_mb`.", + stacklevel=5, + ) return get_model_size_mb(self) def add_to_queue(self, queue: torch.multiprocessing.SimpleQueue) -> None: From c05975936e22c72543b90c1e8dd89428f94ce0d1 Mon Sep 17 00:00:00 2001 From: Carlos Mocholi Date: Thu, 11 Nov 2021 04:29:14 +0100 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0082201aa1cf9..ec56aa27d8ef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,7 +121,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed `CombinedLoader` and `max_size_cycle` didn't receive a `DistributedSampler` ([#10374](https://github.com/PyTorchLightning/pytorch-lightning/issues/10374)) -- +- Fixed `to_torchscript()` causing false positive deprecation warnings ([#10470](https://github.com/PyTorchLightning/pytorch-lightning/issues/10470)) + - From f75e5fbc5c89c54afed69b8a2ef4887d8f97bc0d Mon Sep 17 00:00:00 2001 From: Carlos Mocholi Date: Thu, 11 Nov 2021 04:34:43 +0100 Subject: [PATCH 3/3] Reset at end --- pytorch_lightning/core/lightning.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py index 908b653736c98..c65bf770da063 100644 --- a/pytorch_lightning/core/lightning.py +++ b/pytorch_lightning/core/lightning.py @@ -1937,6 +1937,8 @@ def to_torchscript( with fs.open(file_path, "wb") as f: torch.jit.save(torchscript_module, f) + self._running_torchscript = False + return torchscript_module @property