Trainer class features an extendable logging mechanism that can be used to log metrics to various backends.
On this page, you will learn about how to set up logging to the console via the Logging class as well as how to add Logger classes to the Trainer as well.
Prerequisites
Please ensure that you have read through the Cerebras Model Zoo Trainer Overview beforehand. The rest of this page assumes that you already have at least a cursory understanding of what the Cerebras Model Zoo Trainer is and how to use the python API. Also, make sure that you’ve read through Customizing the Trainer with Callbacks as this page will assume that you are familiar with theCallback mechanism.
Logging to Console
TheTrainer exposes a logger attr which returns a Python logger object which can be used to log various messages to the console with different levels.
For example,
logger can be configured by passing in a Logging object to the Trainer’s constructor.
logger has been configured to print INFO messages to the console by default.
See Control Logging Frequency for an explanation of the log_steps argument.
Logging Metrics
The way to log metrics using theTrainer is to construct and pass in Logger subclasses.
Included out-of-the-box are
-
ProgressLogger: Logs progress metrics to the console -
TensorBoardLogger: Logs metrics to a TensorBoard event file.
Logger subclasses can be constructed and passed into the trainer via the loggers argument:
trainer.log_metrics to log some metric to all loggers.
loss is being logged to the TensorBoardLogger at the current global step.
Logging Name Scope
The trainer also features aname_scope mechanism for logging which is intended to be used to group related logs together.
train/loss and train/accuracy.
Control Logging Frequency
It is often the case in very long runs that logging metrics every step is undesirably verbose. To remedy this, you can specifylog_steps to the Logging class.
log_metrics is called every step, only every 10 steps does the metric actually get logged.
To query whether or not current step is a log step, you can call trainer.is_log_step.
Writing a Custom Logger
Now that you know all about theLogger class and how it’s integrated into the Trainer class, it is fairly straightforward to write your own custom loggers.
To write your own custom Logger class, all you need to do is inherit from the base Logger class and override the following methods:
-
log_metrics: Logs the provided metrics at the provided step. -
flush: Flushes the logs
That is all there is to it. This logger can now be used inside the
Trainer as follows:

