ksuit.writers.log_writer

Classes

LogWriter

Writes logs into a local file and (optionally) to an online webinterface (identified via the tracker).

Module Contents

class ksuit.writers.log_writer.LogWriter(path_provider, update_counter, tracker)

Writes logs into a local file and (optionally) to an online webinterface (identified via the tracker). All logs that should be written for a certain update in the training will be cached and written to the tracker all at once. For writing the logs to disk, everything for the full training process is cached and only after training finished, the logs are written to disk (writing repeatedly to disk takes a long time).

Parameters:
  • path_provider (ksuit.providers.PathProvider) – Provides the path to store all logs to the disk after training.

  • update_counter (ksuit.utils.training.UpdateCounter) – Provides the current training progress add the current epoch/update/sample to every log entry. This allows, e.g., changing the x-axis to “epoch” in online visiualization tools.

  • tracker (ksuit.trackers.BaseTracker) – Provides an interface for logging to an online experiment tracking platform.

logger
path_provider
update_counter
tracker
log_entries = []
log_cache: dict[str, Any] | None = None
non_scalar_keys
get_all_metric_values(key)

Retrieves all values of a metric from all log entries. Used mainly for integration tests.

Parameters:

key (str) – Identifier of the metric.

Returns:

The values of the metric over the course of training. Log entries that do not contain the key are skipped.

Return type:

list[float]

finish()

Stores all logs from the training to the disk.

Return type:

None

flush()

Composes a log entry with all metrics that were calculated for the current training state. This method is called after every update and if no metrics were logged, it simply does nothing.

Return type:

None

add_scalar(key, value, logger=None, format_str=None)

Adds a scalar value to the log. :param key: Metric identifier. :param value: Scalar tensor or float with the value that should be logged. :param logger: If defined, will log the value to stdout. :param format_str: If defined, will alter the log to stdout to be in the provided format.

Parameters:
Return type:

None

add_nonscalar(key, value)

Adds a non-scalar value to the log. :param key: Metric identifier. :param value: Non-scalar value that should be logged (e.g., wandb.Image, wandb.Histogram, …).

Parameters:
  • key (str)

  • value (Any)

Return type:

None