Loggers#
Loggers can be added by specifying a list of loggers
in the main configuration using Shorthand Syntax.
Tip
To create custom loggers, refer to the custom loggers tutorial.
For example, to add a MLFlowLogger
, specify it in the main configuration by adding a list of loggers
:
1...
2loggers:
3 - autrainer.loggers.MLFlowLogger:
4 output_dir: ${results_dir}/.mlflowruns
5...
Abstract Logger#
All loggers inherit from the AbstractLogger
class.
- class autrainer.loggers.AbstractLogger(exp_name, run_name, metrics, tracking_metric, artifacts=['model_summary.txt', 'metrics.csv', {'config.yaml': '.hydra'}])[source]#
Base class for loggers.
- Parameters:
exp_name (
str
) – The name of the experiment.run_name (
str
) – The name of the run.metrics (
List
[AbstractMetric
]) – The metrics to log.tracking_metric (
AbstractMetric
) – The metric to determine the best results.artifacts (
List
[Union
[str
,Dict
[str
,str
]]]) – The artifacts to log. Defaults toARTIFACTS
.
- log_and_update_metrics(metrics, iteration=None)[source]#
Log all metrics in the metrics dictionary for the given iteration. Automatically updates the best metrics based on the tracking metric.
- Parameters:
metrics (
Dict
[str
,Union
[int
,float
]]) – The metrics to log, with the metric name as the key and the metric value as the value.iteration (
Optional
[int
]) – The iteration, epoch, or step number. If None, the iteration will not be logged (e.g., for test metrics). Defaults to None.
- Return type:
None
- setup()[source]#
Optional setup method called at the beginning of the run (cb_on_train_begin).
- Return type:
None
- abstract log_params(params)[source]#
Log the parameters of the configuration.
- Parameters:
params (
Union
[dict
,DictConfig
]) – The parameters of the configuration.- Return type:
None
- abstract log_metrics(metrics, iteration=None)[source]#
Log the metrics for the given iteration.
- Parameters:
metrics (
Dict
[str
,Union
[int
,float
]]) – The metrics to log, with the metric name as the key and the metric value as the value.iteration – The iteration, epoch, or step number. If None, the iteration will not be logged (e.g., for test metrics). Defaults to None.
- Return type:
None
- abstract log_timers(timers)[source]#
Log all timers (e.g., mean times for train, dev, and test).
- Parameters:
timers (
Dict
[str
,float
]) – The timers to log, with the timer name as the key and the timer value as the value.- Return type:
None
Optional Loggers#
The MLFlowLogger
logs data to MLFlow, while the TensorBoardLogger
logs data to TensorBoard.
Both loggers require additional dependencies, which are not installed by default.
To install all necessary dependencies, refer to the Installation section.
To start the MLflow or TensorBoard server, run the following commands:
mlflow server --backend-store-uri /path/to/results/.mlflowruns
tensorboard --logdir /path/to/results/.tensorboard
In both cases, the path should be the same as the output_dir
specified in the configuration.
Fallback Logger#
If a logger such as MLFlowLogger
is specified in the configuration,
but the required dependencies are not installed,
the FallbackLogger
will be used instead.
This logger will log a warning message and will not log any data.
- class autrainer.loggers.FallbackLogger(requested_logger=None, extras=None)[source]#
Fallback logger for when a requested logger is not available.
If the requested logger is not available, a warning is logged. If both requested_logger and extras are None, nothing is logged. The logger serves as a no-op.
- Parameters:
requested_logger (
Optional
[str
]) – The requested logger. Defaults to None.extras (
Optional
[str
]) – The extras required to install the logger. Defaults to None.