Skip to content

Log metrics and parameters

Comet logs a variety of metrics and parameters for you, specific to the machine learning framework you are using, if an integration exists.

For any experiment attributes which are not automatically logged, you can use Comet's metrics and parameters logging with any custom metric and parameter, defined as either a single value or a collection of key<>value pairs. Metrics are meant to be used for time-series data or to track the performance of a training run while parameters (also called hyperparameters) typically indicate a parameter to a model or training algorithm.

Example Metrics tab
Examples of metrics displayed in the Comet UI for a Comet demo project

Comet allows you to access all parameters and metrics logged for the training run in the Single Experiment page, and compare them across experiments using the experiment comparison functionality. To boost your analysis options, you can further create and visualize plots based on any combination and aggregation of these metrics and parameters through a variety of panels.

The following methods can be used to log metrics and parameters:

The following panels can be used to visualize metrics and parameters:

In addition a summary of the metrics and parameters can be view for each training run in the following Single Experiment page tabs:

For example, you could...

Create a parallel coordinates chart that visualizes the relationship between learning rate, accuracy, and model convergence speed, helping to identify the optimal learning rate range for faster training without sacrificing accuracy.

Log a single metric/parameter once

The example below showcases how to log a single metric to an experiment.

Note that you can use the exact same logic to log an parameter, with the exception that parameters only support the step argument.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import comet_ml

# Initialize the Comet Experiment
comet_ml.init()
exp = comet_ml.Experiment()

# Create an example metric
my_metric = 0.01

# Log the metric to Comet
exp.log_metric(name="my_metric", value=my_metric)

You can optionally specify a step (or epoch) argument for the logging to keep track of when the metric/parameter has been recorded during the model training.

Log a single metric/parameter many times

The example below showcases how to log multiple values for the same single metric across steps or epochs.

Note that you can use the exact same logic to log an parameter, with the exception that metrics also support the epoch argument.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import comet_ml
import random

# Initialize the Comet Experiment
comet_ml.init()
exp = comet_ml.Experiment()

for step in range(0, 1000):
    # Create an example metric
    my_metric = random.random()

    # Log the metric to Comet
    exp.log_metric(name="my_metric", value=my_metric, step=step)

The step (or epoch) argument is necessary to be able to view the metric/parameter as a function of the logging time or the time since the start of the experiment, necessary to support advanced experiment analysis.

Tip

It is common to log metrics many times during model training, and occasionally you may want to log parameters over time too (e.g., with a decaying learning rate).

Warning

If you log more than 15,000 values, Comet will start to down-sample your values using reservoir sampling so that a maximum of 15,000 values are stored by the Comet platform. If you are running Comet on-premise, you can reach out to your deployment engineer if you want to increase this configuration value.

Log multiple metrics/parameters

The example below showcases how to log multiple metrics (once).

Note that you can use the exact same logic to log multiple parameters, with the exception that metrics also support the epoch argument and parameters also provide a nested_support argument.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import comet_ml

# Initialize the Comet Experiment
comet_ml.init()
exp = comet_ml.Experiment()

# Create example metrics
metrics = {"my_metric_1": 0.01, "my_metric_2": 0.99}

# Log the metrics to Comet
exp.log_metrics(metrics)

Additionally, you can add a prefix argument (that will be attached to all the keys the dictionary) or specify the step argument.

Log nested parameters

The example below showcases how to log nested parameters.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import comet_ml

# Initialize the Comet Experiment
comet_ml.init()
exp = comet_ml.Experiment()

# Create example nested parameters
nested_parameters = {
    "my_parameter_1": 0.001,
    "my_parameter_2": {
        "item1": 0.9,
        "item2": 0.999,
        "item3": 1e-8,
    },
    "my_parameter_3": [0.1, 0.5, 0.9],
}

# Log the parameters to Comet
exp.log_parameters(parameters=nested_parameters)

The screenshot below showcases how the nested parameters are displayed in the Hyperparameters tab.

Example Hyperparameters tab with nested parameters
The example nested parameters in the Comet UI
Apr. 29, 2024