Skip to content

Commit

Permalink
LightningModule.log_dict: fix type hints for MetricCollection (#18646)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjstewart authored Sep 27, 2023
1 parent c631726 commit f8e6fa4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/lightning/pytorch/core/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def log(

def log_dict(
self,
dictionary: Mapping[str, _METRIC],
dictionary: Union[Mapping[str, _METRIC], MetricCollection],
prog_bar: bool = False,
logger: Optional[bool] = None,
on_step: Optional[bool] = None,
Expand Down Expand Up @@ -594,7 +594,9 @@ def log_dict(
)
return None

def _log_dict_through_fabric(self, dictionary: Mapping[str, Any], logger: Optional[bool] = None) -> None:
def _log_dict_through_fabric(
self, dictionary: Union[Mapping[str, _METRIC], MetricCollection], logger: Optional[bool] = None
) -> None:
if logger is False:
# Passing `logger=False` with Fabric does not make much sense because there is no other destination to
# log to, but we support it in case the original code was written for Trainer use
Expand All @@ -606,7 +608,7 @@ def _log_dict_through_fabric(self, dictionary: Mapping[str, Any], logger: Option
apply_to_collection(value, object, self.__check_allowed, name, value, wrong_dtype=(numbers.Number, Tensor))

assert self._fabric is not None
self._fabric.log_dict(metrics=dictionary)
self._fabric.log_dict(metrics=dictionary) # type: ignore[arg-type]

@staticmethod
def __check_not_nested(value: dict, name: str) -> None:
Expand Down

0 comments on commit f8e6fa4

Please sign in to comment.