Unverified Commit f6da8b22 authored by Matthew Goldey's avatar Matthew Goldey Committed by GitHub
Browse files

check type before logging in trainer to ensure values are scalars (#4883)



* check type before logging to ensure it's a scalar

* log when Trainer attempts to add a non-scalar value using TensorboardX's writer.add_scalar so we know what kinds of fixes are appropriate

* black it

* rephrase log message to clarify attribute was dropped
Co-authored-by: default avatarJulien Chaumond <chaumond@gmail.com>
Co-authored-by: default avatarJulien Chaumond <chaumond@gmail.com>
parent 1c986f42
...@@ -557,7 +557,18 @@ class Trainer: ...@@ -557,7 +557,18 @@ class Trainer:
logs["epoch"] = self.epoch logs["epoch"] = self.epoch
if self.tb_writer: if self.tb_writer:
for k, v in logs.items(): for k, v in logs.items():
if isinstance(v, (int, float)):
self.tb_writer.add_scalar(k, v, self.global_step) self.tb_writer.add_scalar(k, v, self.global_step)
else:
logger.warning(
"Trainer is attempting to log a value of "
'"%s" of type %s for key "%s" as a scalar. '
"This invocation of Tensorboard's writer.add_scalar() "
"is incorrect so we dropped this attribute.",
v,
type(v),
k,
)
self.tb_writer.flush() self.tb_writer.flush()
if is_wandb_available(): if is_wandb_available():
if self.is_world_master(): if self.is_world_master():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment