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:

conf/config.yaml#
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 to EXPORT_ARTIFACTS.

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

abstract log_artifact(filename, path='')[source]#

Log an artifact (e.g., a file).

Parameters:
  • filename (str) – The name of the artifact.

  • path (str) – The absolute path or relative path from the current working directory to the artifact. Defaults to “”.

Return type:

None

end_run()[source]#

Optional end run method called at the end of the run (cb_on_train_end).

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.

autrainer.loggers.MLFlowLogger[source]#

alias of ~autrainer.loggers.mlflow_logger.

autrainer.loggers.TensorBoardLogger[source]#

alias of ~autrainer.loggers.tensorboard_logger.

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.

Constants#

The following constants are used to specify the logging depth as well as the parameters and artifacts exported by the loggers.

autrainer.loggers.abstract_logger.EXPORT_ARTIFACTS: List[str | Dict[str, str]] = ['model_summary.txt', 'metrics.csv', {'config.yaml': '.hydra'}]#

Artifacts to log for runs.

autrainer.loggers.abstract_logger.EXPORT_IGNORE_PARAMS = ['results_dir', 'experiment_id', 'model.dataset', 'training_type', 'save_frequency', 'dataset.metrics', 'plotting', 'model.transform', 'dataset.transform', 'augmentation.steps', 'loggers', 'progress_bar', 'continue_training', 'remove_continued_runs', 'save_train_outputs', 'save_dev_outputs', 'save_test_outputs']#

Ignored configuration parameters for logging.

autrainer.loggers.abstract_logger.EXPORT_LOGGING_DEPTH = 2#

Depth of logging for configuration parameters.