You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/machine-learning/how-to-log-view-metrics.md
+26-26Lines changed: 26 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -146,9 +146,9 @@ params = {
146
146
mlflow.log_params(params)
147
147
```
148
148
149
-
## Log metrics synchronously
149
+
## Log metrics
150
150
151
-
Metrics, as opposite to parameters, are always numeric. MLflow allows the logging of metrics in a synchronous way, meaning that metrics are persisted and immediately available for consumption upon call return. The following table describes how to log specific numeric types:
151
+
Metrics, as opposite to parameters, are always numeric, and they can be logged either synchronously or asynchronously. When metrics are logged, they are immediately available for consumption upon call return. The following table describes how to log specific numeric types:
152
152
153
153
|Logged value|Example code| Notes|
154
154
|----|----|----|
@@ -157,30 +157,29 @@ Metrics, as opposite to parameters, are always numeric. MLflow allows the loggin
157
157
|Log a boolean value | `mlflow.log_metric("my_metric", 0)`| 0 = True, 1 = False|
158
158
159
159
> [!IMPORTANT]
160
-
> **Performance considerations:** If you need to log multiple metrics (or multiple values for the same metric), avoid making calls to `mlflow.log_metric` in loops. Better performance can be achieved by logging a batch of metrics. Use the method `mlflow.log_metrics` which accepts a dictionary with all the metrics you want to log at once or use `MLflowClient.log_batch` which accepts multiple type of elements for logging. See [Log curves or list of values](#log-curves-or-list-of-values) for an example.
160
+
> **Performance considerations:** If you need to log multiple metrics (or multiple values for the same metric), avoid making calls to `mlflow.log_metric` in loops. Better performance can be achieved by using [asynchronous logging](#log-metrics-asynchronously) with `mlflow.log_metric("metric1", 9.42, synchronous=False)` or [logging a batch of metrics](#log-curves-or-list-of-values).
161
161
162
-
### Log curves or list of values
162
+
### Log metrics asynchronously
163
163
164
-
Curves (or a list of numeric values) can be logged with MLflow by logging the same metric multiple times. The following example shows how to do it:
164
+
MLflow also allows logging of metrics in an asynchronous way. Asynchronous metric logging is particularly useful in cases with high throughput where large training jobs with hundreds of compute nodes might be running and trying to log metrics concurrently.
165
+
166
+
Asynchronous metric logging allows you to log metrics and wait for them to be ingested before trying to read them back. This approach scales to large training routines that log hundreds of thousands of metric values.
167
+
168
+
MLflow logs metrics synchronously by default, however, you can change this behavior at any time:
165
169
166
170
```python
167
-
list_to_log = [1, 2, 3, 2, 1, 2, 3, 2, 1]
168
-
from mlflow.entities import Metric
169
-
from mlflow.tracking import MlflowClient
170
-
import time
171
+
import mlflow
171
172
172
-
client = MlflowClient()
173
-
client.log_batch(mlflow.active_run().info.run_id,
174
-
metrics=[Metric(key="sample_list", value=val, timestamp=int(time.time() * 1000), step=0) for val in list_to_log])
173
+
mlflow.config.enable_async_logging()
175
174
```
176
175
177
-
## Log metrics asynchronously
178
-
179
-
MLflow also allows logging of metrics in an asynchronous way. Asynchronous metric logging is particularly useful in cases with high throughput where large training jobs with hundreds of compute nodes might be running and trying to log metrics concurrently.
176
+
The same property can be set, using an environment variable:
180
177
181
-
Asynchronous metric logging allows you to log metrics and wait for them to be ingested before trying to read them back. This approach scales to large training routines that log hundreds of thousands of metric values.
178
+
```python
179
+
export MLFLOW_ENABLE_ASYNC_LOGGING=True
180
+
```
182
181
183
-
To log metrics asynchronously, use the MLflow logging API as you typically would, but add the extra parameter `synchronous=False`.
182
+
To log specific metrics asynchronously, use the MLflow logging API as you typically would, but add the extra parameter `synchronous=False`.
184
183
185
184
```python
186
185
import mlflow
@@ -238,21 +237,22 @@ run_operation.wait()
238
237
239
238
You don't have to call `wait()` on your routines if you don't need immediate access to the metric values. Azure Machine Learning automatically waits when the job is about to finish, to see if there is any pending metric to be persisted. By the time a job is completed in Azure Machine Learning, all metrics are guaranteed to be persisted.
240
239
241
-
### Changing the default logging behavior
242
240
243
-
If you're performiong [automatic logging](#automatic-logging), using `autolog`, or you're using a logger like PyTorch lightning, You won't have access to the method `log_metric(synchronous=False)` directly. In such cases, you can change the default logging behavior by using the following configuration:
241
+
### Log curves or list of values
242
+
243
+
Curves (or a list of numeric values) can be logged with MLflow by logging the same metric multiple times. The following example shows how to do it:
244
244
245
245
```python
246
-
import mlflow
246
+
list_to_log = [1, 2, 3, 2, 1, 2, 3, 2, 1]
247
+
from mlflow.entities import Metric
248
+
from mlflow.tracking import MlflowClient
249
+
import time
247
250
248
-
mlflow.config.enable_async_logging()
251
+
client = MlflowClient()
252
+
client.log_batch(mlflow.active_run().info.run_id,
253
+
metrics=[Metric(key="sample_list", value=val, timestamp=int(time.time() * 1000), step=0) for val in list_to_log])
249
254
```
250
255
251
-
The same property can be set, using an environment variable:
0 commit comments