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.
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:
- For metrics:
log_metric()
,log_metrics()
. - For parameters:
log_parameter()
,log_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 metrics: Metrics Tab.
- For parameters: Hyperparameters Tab.
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 |
|
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 |
|
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 |
|
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 |
|
The screenshot below showcases how the nested parameters are displayed in the Hyperparameters tab.