Skip to content

Commit eacd596

Browse files
Merge pull request #247274 from ahughes-msft/monitoring-mdc-work
Custom monitoring signal documentation
2 parents 98c9c94 + 7a5f26f commit eacd596

File tree

3 files changed

+110
-14
lines changed

3 files changed

+110
-14
lines changed

articles/machine-learning/how-to-collect-production-data.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ First, you'll need to add custom logging code to your scoring script (`score.py`
9494
> [!NOTE]
9595
> Currently, only pandas DataFrames can be logged with the `collect()` API. If the data is not in a DataFrame when passed to `collect()`, it will not be logged to storage and an error will be reported.
9696

97-
The following code is an example of a full scoring script (`score.py`) that uses the custom logging Python SDK:
97+
The following code is an example of a full scoring script (`score.py`) that uses the custom logging Python SDK. In this example, a third `Collector` called `inputs_outputs_collector` logs a joined DataFrame of the `model_inputs` and the `model_outputs`. This joined DataFrame enables additional monitoring signals (feature attribution drift, etc.). If you are not interested in those monitoring signals, please feel free to remove this `Collector`.
9898

9999
```python
100100
import pandas as pd
101101
import json
102102
from azureml.ai.monitoring import Collector
103103

104104
def init():
105-
global inputs_collector, outputs_collector
105+
global inputs_collector, outputs_collector, inputs_outputs_collector
106106

107107
# instantiate collectors with appropriate names, make sure align with deployment spec
108108
inputs_collector = Collector(name='model_inputs')
@@ -172,9 +172,11 @@ data_collector:
172172
enabled: 'True'
173173
model_outputs:
174174
enabled: 'True'
175+
model_inputs_outputs:
176+
enabled: 'True'
175177
```
176178

177-
The following code is an example of a comprehensive deployment YAML for a managed online endpoint deployment. You should update the deployment YAML according to your scenario.
179+
The following code is an example of a comprehensive deployment YAML for a managed online endpoint deployment. You should update the deployment YAML according to your scenario. For more examples on how to format your deployment YAML for inference data logging, see [https://github.com/Azure/azureml-examples/tree/main/cli/endpoints/online/data-collector](https://github.com/Azure/azureml-examples/tree/main/cli/endpoints/online/data-collector).
178180

179181
```yml
180182
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineDeployment.schema.json
@@ -195,6 +197,8 @@ data_collector:
195197
enabled: 'True'
196198
model_outputs:
197199
enabled: 'True'
200+
model_inputs_outputs:
201+
enabled: 'True'
198202
```
199203

200204
Optionally, you can adjust the following additional parameters for your `data_collector`:
@@ -385,4 +389,6 @@ After enabling data collection, production inference data will be logged to your
385389

386390
To learn how to monitor the performance of your models with the collected production inference data, see the following articles:
387391

392+
- [What is Azure Machine Learning model monitoring?](concept-model-monitoring.md)
393+
- [Monitor performance of models deployed to production](how-to-monitor-model-performance.md)
388394
- [What are Azure Machine Learning endpoints?](concept-endpoints.md)

articles/machine-learning/how-to-monitor-model-performance.md

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,9 @@ created_monitor = poller.result()
501501

502502
---
503503

504-
## Set up model monitoring for models deployed outside of Azure Machine Learning
504+
## Set up model monitoring by bringing your own production data to Azure Machine Learning
505505

506-
You can also set up model monitoring for models deployed to Azure Machine Learning batch endpoints or deployed outside of Azure Machine Learning. To monitor these models, you must meet the following requirements:
506+
You can also set up model monitoring for models deployed to Azure Machine Learning batch endpoints or deployed outside of Azure Machine Learning. If you have production data but no deployment, you can use the data to perform continuous model monitoring. To monitor these models, you must meet the following requirements:
507507

508508
* You have a way to collect production inference data from models deployed in production.
509509
* You can register the collected production inference data as an Azure Machine Learning data asset, and ensure continuous updates of the data.
@@ -516,7 +516,6 @@ You can also set up model monitoring for models deployed to Azure Machine Learni
516516
| input | input_data | uri_folder | The collected production inference data, which is registered as Azure Machine Learning data asset. | azureml:myproduction_inference_data:1 |
517517
| output | preprocessed_data | mltable | A tabular dataset, which matches a subset of baseline data schema. | |
518518

519-
520519
# [Azure CLI](#tab/azure-cli)
521520

522521
Once you've satisfied the previous requirements, you can set up model monitoring with the following CLI command and YAML definition:
@@ -769,6 +768,97 @@ created_monitor = poller.result()
769768
The studio currently doesn't support monitoring for models that are deployed outside of Azure Machine Learning. See the Azure CLI or Python tabs instead.
770769

771770
---
771+
772+
## Set up model monitoring with custom signals and metrics
773+
774+
With Azure Machine Learning model monitoring, you have the option to define your own custom signal and implement any metric of your choice to monitor your model. You can register this signal as an Azure Machine Learning component. When your Azure Machine Learning model monitoring job runs on the specified schedule, it will compute the metric(s) you have defined within your custom signal, just as it does for the prebuilt signals (data drift, prediction drift, data quality, & feature attribution drift). To get started with defining your own custom signal, you must meet the following requirement:
775+
776+
* You must define your custom signal and register it as an Azure Machine Learning component. The Azure Machine Learning component must have these input and output signatures:
777+
778+
### Component input signature
779+
780+
The component input DataFrame should contain a `mltable` with the processed data from the preprocessing component and any number of literals, each representing an implemented metric as part of the custom signal component. For example, if you have implemented one metric, `std_deviation`, then you will need an input for `std_deviation_threshold`. Generally, there should be one input per metric with the name {metric_name}_threshold.
781+
782+
| signature name | type | description | example value |
783+
|---|---|---|---|
784+
| production_data | mltable | A tabular dataset, which matches a subset of baseline data schema. | |
785+
| std_deviation_threshold | literal, string | Respective threshold for the implemented metric. | 2 |
786+
787+
### Component output signature
788+
789+
The component output DataFrame should contain four columns: `group`, `metric_name`, `metric_value`, and `threshold_value`:
790+
791+
| signature name | type | description | example value |
792+
|---|---|---|---|
793+
| group | literal, string | Top level logical grouping to be applied to this custom metric. | TRANSACTIONAMOUNT |
794+
| metric_name | literal, string | The name of the custom metric. | std_deviation |
795+
| metric_value | mltable | The value of the custom metric. | 44,896.082 |
796+
| threshold_value | | The threshold for the custom metric. | 2 |
797+
798+
Here is an example output from a custom signal component computing the metric, `std_deviation`:
799+
800+
| group | metric_value | metric_name | threshold_value |
801+
|---|---|---|---|
802+
| TRANSACTIONAMOUNT | 44,896.082 | std_deviation | 2 |
803+
| LOCALHOUR | 3.983 | std_deviation | 2 |
804+
| TRANSACTIONAMOUNTUSD | 54,004.902 | std_deviation | 2 |
805+
| DIGITALITEMCOUNT | 7.238 | std_deviation | 2 |
806+
| PHYSICALITEMCOUNT | 5.509 | std_deviation | 2 |
807+
808+
An example custom signal component definition and metric computation code can be found in our GitHub repo at [https://github.com/Azure/azureml-examples/tree/main/cli/monitoring/components/custom_signal](https://github.com/Azure/azureml-examples/tree/main/cli/monitoring/components/custom_signal).
809+
810+
# [Azure CLI](#tab/azure-cli)
811+
812+
Once you've satisfied the previous requirements, you can set up model monitoring with the following CLI command and YAML definition:
813+
814+
```azurecli
815+
az ml schedule create -f ./custom-monitoring.yaml
816+
```
817+
818+
The following YAML contains the definition for model monitoring with a custom signal. It is assumed that you have already created and registered your component with the custom signal definition to Azure Machine Learning. In this example, the `component_id` of the registered custom signal component is `azureml:my_custom_signal:1.0.0`:
819+
820+
```yaml
821+
# custom-monitoring.yaml
822+
$schema: http://azureml/sdk-2-0/Schedule.json
823+
name: my-custom-signal
824+
trigger:
825+
type: recurrence
826+
frequency: day # can be minute, hour, day, week, month
827+
interval: 7 # #every day
828+
create_monitor:
829+
compute:
830+
instance_type: "standard_e8s_v3"
831+
runtime_version: "3.2"
832+
monitoring_signals:
833+
customSignal:
834+
type: custom
835+
data_window_size: 360
836+
component_id: azureml:my_custom_signal:1.0.0
837+
input_datasets:
838+
production_data:
839+
input_dataset:
840+
type: uri_folder
841+
path: azureml:custom_without_drift:1
842+
dataset_context: test
843+
pre_processing_component: azureml:custom_preprocessor:1.0.0
844+
metric_thresholds:
845+
- metric_name: std_dev
846+
threshold: 2
847+
alert_notification:
848+
emails:
849+
850+
```
851+
852+
# [Python](#tab/python)
853+
854+
The Python SDK currently doesn't support monitoring for custom signals. See the Azure CLI tab instead.
855+
856+
# [Studio](#tab/azure-studio)
857+
858+
The studio currently doesn't support monitoring for custom signals. See the Azure CLI tab instead.
859+
860+
---
861+
772862
## Next steps
773863
774864
- [Data collection from models in production (preview)](concept-data-collection.md)

0 commit comments

Comments
 (0)