Skip to content

Commit e747969

Browse files
authored
Update how-to-log-view-metrics.md
1 parent e9dc032 commit e747969

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

articles/machine-learning/how-to-log-view-metrics.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ params = {
146146
mlflow.log_params(params)
147147
```
148148
149-
## Log metrics synchronously
149+
## Log metrics
150150
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:
152152
153153
|Logged value|Example code| Notes|
154154
|----|----|----|
@@ -157,30 +157,29 @@ Metrics, as opposite to parameters, are always numeric. MLflow allows the loggin
157157
|Log a boolean value | `mlflow.log_metric("my_metric", 0)`| 0 = True, 1 = False|
158158
159159
> [!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).
161161
162-
### Log curves or list of values
162+
### Log metrics asynchronously
163163
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:
165169
166170
```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
171172
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()
175174
```
176175
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:
180177
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+
```
182181
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`.
184183
185184
```python
186185
import mlflow
@@ -238,21 +237,22 @@ run_operation.wait()
238237
239238
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.
240239
241-
### Changing the default logging behavior
242240
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:
244244
245245
```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
247250
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])
249254
```
250255
251-
The same property can be set, using an environment variable:
252-
253-
```python
254-
export MLFLOW_ENABLE_ASYNC_LOGGING=True
255-
```
256256
257257
## Log images
258258

0 commit comments

Comments
 (0)