tlc.core.metrics_writer.metrics_writer#

A class for writing metrics to persistent storage.

Module Contents#

Classes#

Class

Description

MetricsWriter

A class for writing metrics to persistent storage.

API#

class tlc.core.metrics_writer.metrics_writer.MetricsWriter(run_url: tlc.core.url.Url | str, dataset_url: str = '', dataset_name: str = '', override_column_schemas: dict[str, tlc.core.schema.Schema] = {})#

A class for writing metrics to persistent storage.

Uses an internal TableWriter to write tables.

Will always add columns “example_id” and “input_table_id” to the table, if not specified.

Will add schema-overrides for columns “example_id”, “epoch”, and “input_table_id” if they are present. These will take precedence over any schema overrides passed in to the constructor.

Subsequent calls to add_batch must be column-compatible, with each column having the same length within a batch.

Parameters:
  • run_url – The URL of the run to write metrics for.

  • dataset_url – The URL of the dataset to write metrics for.

  • dataset_name – The name of the dataset to write metrics for.

  • key – A unique key to use for the metrics table. See TableWriter for more details.

add_batch(metrics_batch: MutableMapping[str, tlc.core.builtins.types.MetricData]) None#

Add a batch of metrics to the buffer.

The metrics batches sent in to subsequent calls to add_batch on the same MetricsWriter must have the same metrics keys, with values of the same type and length.

Parameters:

metrics_batch – A dictionary of metrics, where the keys are the metric names and the values are lists of metric values.

Raises:

ValueError: If the length of the metrics lists are not equal.

static preprocess_batch(batch: MutableMapping[str, tlc.core.builtins.types.MetricData]) MutableMapping[str, tlc.core.builtins.types.MetricData]#

Preprocess a batch of metrics before adding it to the buffer.

This method should take care of any changes that need to be made to the batch before it is sent to the storage layer. Raise an exception if the batch cannot be converted to a valid format.

set_override_column_schemas(override_column_schemas: dict[str, tlc.core.schema.Schema]) None#

Set the override column schemas for the underlying table writer.

get_written_metrics_infos() list[tlc.core.builtins.types.MetricTableInfo]#

Get the list of written metrics infos.

flush() None#

Flush the metrics writer.

clear() None#

Clear the metrics writer.