Skip to content

Commit fabb364

Browse files
Remove deprecated mode argument from ModelSummary (#10449)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 847e240 commit fabb364

File tree

5 files changed

+9
-87
lines changed

5 files changed

+9
-87
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
113113
- Removed deprecated `utilities.distributed.rank_zero_{warn/deprecation}` ([#10451](https://github.com/PyTorchLightning/pytorch-lightning/pull/10451))
114114

115115

116+
- Removed deprecated `mode` argument from `ModelSummary` class ([#10449](https://github.com/PyTorchLightning/pytorch-lightning/pull/10449))
117+
118+
116119
- Removed deprecated `Trainer.train_loop` property in favor of `Trainer.fit_loop` ([#10482](https://github.com/PyTorchLightning/pytorch-lightning/pull/10482))
117120

118121

pytorch_lightning/core/lightning.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,19 +1689,14 @@ def tbptt_split_batch(self, batch, split_size):
16891689

16901690
return splits
16911691

1692-
def summarize(self, mode: Optional[str] = "top", max_depth: Optional[int] = None) -> Optional[ModelSummary]:
1692+
def summarize(self, max_depth: int = 1) -> ModelSummary:
16931693
"""Summarize this LightningModule.
16941694
16951695
.. deprecated:: v1.5
16961696
This method was deprecated in v1.5 in favor of `pytorch_lightning.utilities.model_summary.summarize`
16971697
and will be removed in v1.7.
16981698
16991699
Args:
1700-
mode: Can be either ``'top'`` (summarize only direct submodules) or ``'full'`` (summarize all layers).
1701-
1702-
.. deprecated:: v1.4
1703-
This parameter was deprecated in v1.4 in favor of `max_depth` and will be removed in v1.6.
1704-
17051700
max_depth: The maximum depth of layer nesting that the summary will include. A value of 0 turns the
17061701
layer summary off. Default: 1.
17071702
@@ -1714,7 +1709,7 @@ def summarize(self, mode: Optional[str] = "top", max_depth: Optional[int] = None
17141709
stacklevel=6,
17151710
)
17161711

1717-
return summarize(self, mode, max_depth)
1712+
return summarize(self, max_depth)
17181713

17191714
def freeze(self) -> None:
17201715
r"""

pytorch_lightning/utilities/model_summary.py

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
from torch.utils.hooks import RemovableHandle
2424

2525
import pytorch_lightning as pl
26-
from pytorch_lightning.utilities import AMPType, DeviceType, ModelSummaryMode, rank_zero_deprecation
27-
from pytorch_lightning.utilities.exceptions import MisconfigurationException
26+
from pytorch_lightning.utilities import AMPType, DeviceType
2827
from pytorch_lightning.utilities.imports import _TORCH_GREATER_EQUAL_1_8
2928
from pytorch_lightning.utilities.warnings import WarningCache
3029

@@ -130,13 +129,6 @@ class ModelSummary:
130129
131130
Args:
132131
model: The model to summarize (also referred to as the root module).
133-
mode: Can be one of
134-
135-
- `top` (default): only the top-level modules will be recorded (the children of the root module)
136-
- `full`: summarizes all layers and their submodules in the root module
137-
138-
.. deprecated:: v1.4
139-
This parameter was deprecated in v1.4 in favor of `max_depth` and will be removed in v1.6.
140132
141133
max_depth: Maximum depth of modules to show. Use -1 to show all modules or 0 to show no
142134
summary. Defaults to 1.
@@ -186,22 +178,9 @@ class ModelSummary:
186178
0.530 Total estimated model params size (MB)
187179
"""
188180

189-
def __init__(self, model: "pl.LightningModule", mode: Optional[str] = None, max_depth: Optional[int] = 1) -> None:
181+
def __init__(self, model: "pl.LightningModule", max_depth: int = 1) -> None:
190182
self._model = model
191183

192-
# temporary mapping from mode to max_depth
193-
if max_depth is None or mode is not None:
194-
if mode in ModelSummaryMode.supported_types():
195-
max_depth = ModelSummaryMode.get_max_depth(mode)
196-
rank_zero_deprecation(
197-
"Argument `mode` in `ModelSummary` is deprecated in v1.4"
198-
f" and will be removed in v1.6. Use `max_depth={max_depth}` to replicate `mode={mode}` behaviour."
199-
)
200-
else:
201-
raise MisconfigurationException(
202-
f"`mode` can be {', '.join(ModelSummaryMode.supported_types())}, got {mode}."
203-
)
204-
205184
if not isinstance(max_depth, int) or max_depth < -1:
206185
raise ValueError(f"`max_depth` can be -1, 0 or > 0, got {max_depth}.")
207186

@@ -436,40 +415,16 @@ def _is_lazy_weight_tensor(p: Tensor) -> bool:
436415
return False
437416

438417

439-
def summarize(
440-
lightning_module: "pl.LightningModule", mode: Optional[str] = None, max_depth: Optional[int] = None
441-
) -> ModelSummary:
418+
def summarize(lightning_module: "pl.LightningModule", max_depth: int = 1) -> ModelSummary:
442419
"""Summarize the LightningModule specified by `lightning_module`.
443420
444421
Args:
445422
lightning_module: `LightningModule` to summarize.
446-
mode: Can be either ``'top'`` (summarize only direct submodules) or ``'full'`` (summarize all layers).
447-
448-
.. deprecated:: v1.4
449-
This parameter was deprecated in v1.4 in favor of `max_depth` and will be removed in v1.6.
450423
451424
max_depth: The maximum depth of layer nesting that the summary will include. A value of 0 turns the
452425
layer summary off. Default: 1.
453426
454427
Return:
455428
The model summary object
456429
"""
457-
458-
# temporary mapping from mode to max_depth
459-
if max_depth is None:
460-
if mode is None:
461-
model_summary = ModelSummary(lightning_module, max_depth=1)
462-
elif mode in ModelSummaryMode.supported_types():
463-
max_depth = ModelSummaryMode.get_max_depth(mode)
464-
rank_zero_deprecation(
465-
"Argument `mode` in `LightningModule.summarize` is deprecated in v1.4"
466-
f" and will be removed in v1.6. Use `max_depth={max_depth}` to replicate `mode={mode}` behavior."
467-
)
468-
model_summary = ModelSummary(lightning_module, max_depth=max_depth)
469-
else:
470-
raise MisconfigurationException(
471-
f"`mode` can be None, {', '.join(ModelSummaryMode.supported_types())}, got {mode}"
472-
)
473-
else:
474-
model_summary = ModelSummary(lightning_module, max_depth=max_depth)
475-
return model_summary
430+
return ModelSummary(lightning_module, max_depth=max_depth)

tests/deprecated_api/test_remove_1-6.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from pytorch_lightning import Trainer
2020
from pytorch_lightning.utilities.model_helpers import is_overridden
21-
from pytorch_lightning.utilities.model_summary import ModelSummary
2221
from tests.helpers import BoringModel
2322

2423

@@ -69,15 +68,6 @@ def test_v1_6_0_is_overridden_model():
6968
assert not is_overridden("foo", model=model)
7069

7170

72-
def test_v1_6_0_deprecated_model_summary_mode(tmpdir):
73-
model = BoringModel()
74-
with pytest.deprecated_call(match="Argument `mode` in `ModelSummary` is deprecated in v1.4"):
75-
ModelSummary(model, mode="top")
76-
77-
with pytest.deprecated_call(match="Argument `mode` in `LightningModule.summarize` is deprecated in v1.4"):
78-
model.summarize(mode="top")
79-
80-
8171
def test_v1_6_0_deprecated_disable_validation():
8272
trainer = Trainer()
8373
with pytest.deprecated_call(match="disable_validation` is deprecated in v1.4"):

tests/utilities/test_model_summary.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,11 @@ def test_invalid_weights_summmary():
143143
"""Test that invalid value for weights_summary raises an error."""
144144
model = LightningModule()
145145

146-
with pytest.raises(MisconfigurationException, match="`mode` can be None, .* got temp"):
147-
summarize(model, mode="temp")
148-
149146
with pytest.raises(
150147
MisconfigurationException, match="`weights_summary` can be None, .* got temp"
151148
), pytest.deprecated_call(match="weights_summary=temp)` is deprecated"):
152149
Trainer(weights_summary="temp")
153150

154-
with pytest.raises(MisconfigurationException, match="mode` can be .* got temp"):
155-
ModelSummary(model, mode="temp")
156-
157151
with pytest.raises(ValueError, match="max_depth` can be .* got temp"):
158152
ModelSummary(model, max_depth="temp")
159153

@@ -334,21 +328,6 @@ def test_lazy_model_summary():
334328
assert summary.trainable_parameters == 7
335329

336330

337-
def test_max_depth_equals_mode_interface():
338-
"""Test summarize(model, full/top) interface mapping matches max_depth."""
339-
model = DeepNestedModel()
340-
341-
with pytest.deprecated_call(match="mode` in `LightningModule.summarize` is deprecated"):
342-
summary_top = summarize(model, mode="top")
343-
summary_0 = summarize(model, max_depth=1)
344-
assert str(summary_top) == str(summary_0)
345-
346-
with pytest.deprecated_call(match="mode` in `LightningModule.summarize` is deprecated"):
347-
summary_full = summarize(model, mode="full")
348-
summary_minus1 = summarize(model, max_depth=-1)
349-
assert str(summary_full) == str(summary_minus1)
350-
351-
352331
@pytest.mark.parametrize("max_depth", [-1, 0, 1, 3, 999])
353332
def test_max_depth_param(max_depth):
354333
"""Test that only the modules up to the desired depth are shown."""

0 commit comments

Comments
 (0)