FileLogger#
- class composer.loggers.FileLogger(filename='{run_name}/logs-rank{rank}.txt', remote_file_name=None, *, capture_stdout=True, capture_stderr=True, buffer_size=1, log_traces=True, flush_interval=100, overwrite=False)[source]#
Log data to a file.
- Example usage:
from composer.loggers import FileLogger from composer.trainer import Trainer file_logger = FileLogger( filename="{run_name}/logs-rank{rank}.txt", buffer_size=1, 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
Logger.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โ
remote_file_name (str, optional) โ
Format string for the logfileโs name.
The logfile will be periodically logged (according to the
flush_interval
) as a file. The file name will be determined by this format string.See also
Uploading Files for notes for file uploading.
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 remote file 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_traces (bool, optional) โ Whether to log algorithm traces. See
Engine
for more detail.flush_interval (int, optional) โ How frequently to flush the log to the file in batches Default:
100
.overwrite (bool, optional) โ Whether to overwrite an existing logfile. (default:
False
)
- property filename#
The filename for the logfile.
- property remote_file_name#
The remote file name for the logfile.
- write(prefix, s)[source]#
Write to the logfile.
Note
If the
write
occurs before theEvent.INIT
event, the write will be enqueued, as the file is not yet open.