def metrics(self) -> _METRICS:
        """This function returns either batch or epoch metrics."""
        on_step = self._first_loop_iter is not None
        assert self.trainer._results is not None
        return self.trainer._results.metrics(on_step)
This function returns either batch or epoch metrics.
src/lightning/pytorch/trainer/connectors/logger_connector/logger_connector.py