Skip to content

Commit

Permalink
Fix model summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Mocholí authored and Carlos Mocholí committed Mar 25, 2022
1 parent 692429d commit 5e612aa
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pytorch_lightning/utilities/model_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utilities related to model weights summary."""
import contextlib
import logging
from collections import OrderedDict
from typing import Any, Dict, List, Optional, Tuple, Union
Expand Down Expand Up @@ -263,8 +264,8 @@ def _forward_example_input(self) -> None:
mode = model.training
model.eval()

assert trainer is not None
with torch.no_grad(), trainer.precision_plugin.forward_context():
forward_context = contextlib.nullcontext() if trainer is None else trainer.precision_plugin.forward_context()
with torch.no_grad(), forward_context:
# let the model hooks collect the input- and output shapes
if isinstance(input_, (list, tuple)):
model(*input_)
Expand Down

0 comments on commit 5e612aa

Please sign in to comment.