Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/lightning/fabric/loggers/tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ def log_metrics(self, metrics: Mapping[str, float], step: Optional[int] = None)
else:
try:
self.experiment.add_scalar(k, v, step)
# TODO(fabric): specify the possible exception
except Exception as ex:
except (NotImplementedError, ValueError) as ex:
raise ValueError(
f"\n you tried to log {v} which is currently not supported. Try a dict or a scalar/tensor."
) from ex
Expand Down
13 changes: 13 additions & 0 deletions tests/tests_pytorch/loggers/test_tensorboard.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.
import os
import re
from argparse import Namespace
from unittest import mock
from unittest.mock import Mock
Expand Down Expand Up @@ -157,6 +158,18 @@ def test_tensorboard_log_metrics(tmp_path, step_idx):
logger.log_metrics(metrics, step_idx)


@pytest.mark.parametrize("value", [[1], "x", None])
def test_tensorboard_log_metrics_exception_message(tmp_path, value):
logger = TensorBoardLogger(tmp_path)
with pytest.raises(
ValueError,
match=re.escape(
f"you tried to log {value} which is currently not supported. Try a dict or a scalar/tensor.",
),
):
logger.log_metrics(metrics={"metric": value})


def test_tensorboard_log_hyperparams(tmp_path):
logger = TensorBoardLogger(tmp_path)
hparams = {
Expand Down
Loading