composer.loggers.file_logger#
Logs to a file.
Classes
Log data to a file. |
- class composer.loggers.file_logger.FileLogger(filename='{run_name}/logs-rank{rank}.txt', artifact_name=None, *, capture_stdout=True, capture_stderr=True, buffer_size=1, log_level=LogLevel.EPOCH, log_interval=1, flush_interval=100, overwrite=False)[source]#
Bases:
composer.loggers.logger_destination.LoggerDestination
Log data to a file.
- Example usage:
from composer.loggers import FileLogger, LogLevel from composer.trainer import Trainer file_logger = FileLogger( filename="{run_name}/logs-rank{rank}.txt", buffer_size=1, log_level=LogLevel.BATCH, log_interval=2, flush_interval=50 ) trainer = Trainer( ..., loggers=[file_logger] )
Example output:
[FIT][step=2]: { "logged_metric": "logged_value", } [EPOCH][step=2]: { "logged_metric": "logged_value", } [BATCH][step=2]: { "logged_metric": "logged_value", } [EPOCH][step=3]: { "logged_metric": "logged_value", }
- Parameters
filename (str, optional) โ
Format string for the filename.
The following format variables are available:
Variable
Description
{run_name}
The name of the training run. See
run_name
.{rank}
The global rank, as returned by
get_global_rank()
.{local_rank}
The local rank of the process, as returned by
get_local_rank()
.{world_size}
The world size, as returned by
get_world_size()
.{local_world_size}
The local world size, as returned by
get_local_world_size()
.{node_rank}
The node rank, as returned by
get_node_rank()
.Note
When training with multiple devices (i.e. GPUs), ensure that
'{rank}'
appears in the format. Otherwise, multiple processes may attempt to write to the same file.Consider the following example when using default value of โ{run_name}/logs-rank{rank}.txtโ:
>>> file_logger = FileLogger(filename='{run_name}/logs-rank{rank}.txt') >>> trainer = Trainer(loggers=[file_logger], run_name='my-awesome-run') >>> file_logger.filename 'my-awesome-run/logs-rank0.txt'
Default: โ{run_name}/logs-rank{rank}.txtโ
artifact_name (str, optional) โ
Format string for the logfileโs artifact name.
The logfile will be periodically logged (according to the
flush_interval
) as a file artifact. The artifact name will be determined by this format string.See also
log_file_artifact()
for file artifact logging.The same format variables for
filename
are available. Setting this parameter toNone
(the default) will use the same format string asfilename
. It is sometimes helpful to deviate from this default. For example, whenfilename
contains an absolute path, it is recommended to set this parameter explicitely, so the absolute path does not appear in any artifact stores.Leading slashes (
'/'
) will be stripped.Default:
None
(which uses the same format string asfilename
)capture_stdout (bool, optional) โ Whether to include the
stdout``in ``filename
. (default:True
)capture_stderr (bool, optional) โ Whether to include the
stderr``in ``filename
. (default:True
)buffer_size (int, optional) โ Buffer size. See
open()
. Default:1
for line buffering.log_level (LogLevel, optional) โ
LogLevel
(i.e. unit of resolution) at which to record. Default:EPOCH
.log_interval (int, optional) โ Frequency to print logs. If
log_level
isEPOCH
, logs will only be recorded every n epochs. Iflog_level
isBATCH
, logs will be printed every n batches. Otherwise, iflog_level
isFIT
, this parameter is ignored, as calls at theFIT
log level are always recorded. Default:1
.flush_interval (int, optional) โ How frequently to flush the log to the file, relative to the
log_level
. For example, if thelog_level
isEPOCH
, then the logfile will be flushed every n epochs. If thelog_level
isBATCH
, then the logfile will be flushed every n batches. Default:100
.
- property artifact_name#
The artifact name for the logfile.
- property filename#
The filename for the logfile.