Skip to content

Commit

Permalink
Deprecate LightningModule.summarize() in favor of pl.utilities.model_…
Browse files Browse the repository at this point in the history
…summary.summarize() (#8513)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Adrian Wälchli <[email protected]>
Co-authored-by: ananthsub <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
  • Loading branch information
5 people authored Aug 3, 2021
1 parent 08fba96 commit f90849c
Show file tree
Hide file tree
Showing 12 changed files with 602 additions and 515 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Deprecated

- Deprecated `LightningModule.summarize()` in favor of `pytorch_lightning.utilities.model_summary.summarize()`


- Deprecated `LightningModule.model_size` ([#8343](https://github.com/PyTorchLightning/pytorch-lightning/pull/8343))


Expand Down
29 changes: 11 additions & 18 deletions pytorch_lightning/core/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

from pytorch_lightning.core.grads import GradInformation
from pytorch_lightning.core.hooks import CheckpointHooks, DataHooks, ModelHooks
from pytorch_lightning.core.memory import ModelSummary
from pytorch_lightning.core.mixins import DeviceDtypeModuleMixin, HyperparametersMixin
from pytorch_lightning.core.optimizer import LightningOptimizer
from pytorch_lightning.core.saving import ModelIO
Expand All @@ -44,6 +43,7 @@
from pytorch_lightning.utilities.distributed import distributed_available, sync_ddp
from pytorch_lightning.utilities.exceptions import MisconfigurationException
from pytorch_lightning.utilities.memory import get_model_size_mb
from pytorch_lightning.utilities.model_summary import ModelSummary, summarize
from pytorch_lightning.utilities.parsing import collect_init_args
from pytorch_lightning.utilities.signature_utils import is_param_in_hook_signature
from pytorch_lightning.utilities.types import _METRIC_COLLECTION, EPOCH_OUTPUT, STEP_OUTPUT
Expand Down Expand Up @@ -1715,6 +1715,10 @@ def summarize(self, mode: Optional[str] = "top", max_depth: Optional[int] = None
"""
Summarize this LightningModule.
.. deprecated:: v1.5
This method was deprecated in v1.5 in favor of `pytorch_lightning.utilities.model_summary.summarize`
and will be removed in v1.7.
Args:
mode: Can be either ``'top'`` (summarize only direct submodules) or ``'full'`` (summarize all layers).
Expand All @@ -1727,24 +1731,13 @@ def summarize(self, mode: Optional[str] = "top", max_depth: Optional[int] = None
Return:
The model summary object
"""
model_summary = None

# temporary mapping from mode to max_depth
if max_depth is None:
if mode in ModelSummary.MODES:
max_depth = ModelSummary.MODES[mode]
rank_zero_deprecation(
f"Argument `mode` in `LightningModule.summarize` is deprecated in v1.4"
f" and will be removed in v1.6. Use `max_depth={max_depth}` to replicate `mode={mode}` behavior."
)
model_summary = ModelSummary(self, max_depth=max_depth)
elif mode is not None:
raise MisconfigurationException(f"`mode` can be None, {', '.join(ModelSummary.MODES)}, got {mode}")
else:
model_summary = ModelSummary(self, max_depth=max_depth)
warning_cache.deprecation(
"The `LightningModule.summarize` method is deprecated in v1.5 and will be removed in v1.7. "
"Use `pytorch_lightning.utilities.model_summary.summarize` instead.",
stacklevel=6,
)

log.info("\n" + str(model_summary))
return model_summary
return summarize(self, mode, max_depth)

def freeze(self) -> None:
r"""
Expand Down
Loading

0 comments on commit f90849c

Please sign in to comment.