Monitoring your AI systems
Monitor your OpenShift AI models for fairness and reliability
Abstract
Chapter 1. Overview of monitoring your AI systems Copy linkLink copied to clipboard!
Use TrustyAI to monitor your models for data drift and bias.
These tools help ensure that your data science and machine learning models are transparent, fair, and reliable.
Configure and set up TrustyAI for your project, and then perform the following checks:
- Bias: Check for unfair patterns or biases in data and model predictions to ensure your model’s decisions are unbiased.
- Data drift: Detect changes in input data distributions over time by comparing the latest real-world data to the original training data. Comparing the data identifies shifts or deviations that could impact model performance, ensuring that the model remains accurate and reliable.
Chapter 2. Configuring TrustyAI Copy linkLink copied to clipboard!
To configure model monitoring with TrustyAI for data scientists to use in OpenShift AI, a cluster administrator does the following tasks:
- Configure monitoring for the model serving platform
- Enable the TrustyAI component in the Red Hat OpenShift AI Operator
- Configure TrustyAI to use a database, if you want to use your database instead of a PVC for storage with TrustyAI
- Install the TrustyAI service on each project that contains models that the data scientists want to monitor
- (Optional) Configure TrustyAI and KServe RawDeployment mode integration
2.1. Configuring monitoring for your model serving platform Copy linkLink copied to clipboard!
For deploying large models such as large language models (LLMs), use the model serving platform.
+ To configure monitoring for this platform, see Configuring monitoring for the model serving platform.
2.2. Enabling the TrustyAI component Copy linkLink copied to clipboard!
To allow your data scientists to use model monitoring with TrustyAI, you must enable the TrustyAI component in OpenShift AI.
Prerequisites
- You have cluster administrator privileges for your OpenShift cluster.
- You have access to the data science cluster.
- You have installed Red Hat OpenShift AI.
Procedure
- In the OpenShift console, click Operators → Installed Operators.
- Search for the Red Hat OpenShift AI Operator, and then click the Operator name to open the Operator details page.
- Click the Data Science Cluster tab.
- Click the default instance name (for example, default-dsc) to open the instance details page.
- Click the YAML tab to show the instance specifications.
In the
spec:componentssection, set themanagementStatefield for thetrustyaicomponent toManaged:trustyai: managementState: Managedtrustyai: managementState: ManagedCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Click Save.
Verification
Check the status of the trustyai-service-operator pod:
- In the OpenShift console, from the Project list, select redhat-ods-applications.
- Click Workloads → Deployments.
Search for the trustyai-service-operator-controller-manager deployment. Check the status:
- Click the deployment name to open the deployment details page.
- Click the Pods tab.
View the pod status.
When the status of the trustyai-service-operator-controller-manager-<pod-id> pod is Running, the pod is ready to use.
2.3. Configuring TrustyAI with a database Copy linkLink copied to clipboard!
If you have a relational database in your OpenShift cluster such as MySQL or MariaDB, you can configure TrustyAI to use your database instead of a persistent volume claim (PVC). Using a database instead of a PVC for storage can improve scalability, performance, and data management in TrustyAI. Provide TrustyAI with a database configuration secret before deployment. You can create a secret or specify the name of an existing Kubernetes secret within your project.
Prerequisites
- You have cluster administrator privileges for your OpenShift cluster.
You have installed the OpenShift CLI (
oc) as described in the appropriate documentation for your cluster:- Installing the OpenShift CLI for OpenShift Container Platform
- Installing the OpenShift CLI for Red Hat OpenShift Service on AWS
- You have enabled the TrustyAI component, as described in Enabling the TrustyAI component.
- The data scientist has created a project, as described in Creating a project, that contains the models that the data scientist wants to monitor.
- If you are configuring the TrustyAI service with an external MySQL database, your database must already be in your cluster and use at least MySQL version 5.x. However, Red Hat recommends that you use MySQL version 8.x.
- If you are configuring the TrustyAI service with a MariaDB database, your database must already be in your cluster and use MariaDB version 10.3 or later. However, Red Hat recommends that you use at least MariaDB version 10.5.
The transport security layer (TLS) protocol does not work with the MariaDB operator 0.29 or later versions.
The MariaDB operator for s390x is not supported at this time.
Procedure
In a terminal window, if you are not already logged in to your OpenShift cluster as a cluster administrator, log in to the OpenShift CLI (
oc) as shown in the following example:oc login <openshift_cluster_url> -u <admin_username> -p <password>
$ oc login <openshift_cluster_url> -u <admin_username> -p <password>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: If you want to use a TLS connection between TrustyAI and the database, create a TrustyAI service database TLS secret that uses the same certificates that you want to use for the database.
Create a YAML file to contain your TLS secret and add the following code:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Save the file with the file name <service_name>-db-tls.yaml. For example, if your service name is
trustyai-service, save the file as trustyai-service-db-tls.yaml. Apply the YAML file in the project that contains the models that the data scientist wants to monitor:
oc apply -f <service_name>-db-tls.yaml -n <project_name>
$ oc apply -f <service_name>-db-tls.yaml -n <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Create a secret (or specify an existing one) that has your database credentials.
Create a YAML file to contain your secret and add the following code:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The only currently supported
databaseKindvalue ismariadb. - 2
- The username you want TrustyAI to use when interfacing with the database.
- 3
- The password that TrustyAI must use when connecting to the database.
- 4
- The Kubernetes (K8s) service that TrustyAI must use when connecting to the database (the default
mariadb) . - 5
- The port that TrustyAI must use when connecting to the database (default is 3306).
- 6
- The database schema generation strategy to be used by TrustyAI. It is the setting for the
quarkus.hibernate-orm.database.generationargument, which determines how TrustyAI interacts with the database on its initial connection. Set tonone,create,drop-and-create,drop,update, orvalidate. - 7
- The name of the individual database within the database service that the username and password authenticate to, as well as the specific database name that TrustyAI should read and write to on the database server.
- Save the file with the file name db-credentials.yaml. You will need this name later when you install or change the TrustyAI service.
Apply the YAML file in the project that contains the models that the data scientist wants to monitor:
oc apply -f db-credentials.yaml -n <project_name>
$ oc apply -f db-credentials.yaml -n <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
If you are installing TrustyAI for the first time on a project, continue to Installing the TrustyAI service for a project.
If you already installed TrustyAI on a project, you can migrate the existing TrustyAI service from using a PVC to using a database.
Create a YAML file to update the TrustyAI service custom resource (CR) and add the following code:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Set to
trueto prompt the migration from PVC to database storage. - 2
- The name of the TrustyAI service instance.
- 3
- The storage format for the data. Set this field to
DATABASE. - 4
- The location within the PVC where you were storing the data. This must match the value specified in the existing CR.
- 5
- The size of the data to request.
- 6
- The name of the secret with your database credentials that you created in an earlier step. For example,
db-credentials. - 7
- The suffix for the existing stored data files. This must match the value specified in the existing CR.
- 8
- The interval at which to calculate the metrics. The default is
5s. The duration is specified with the ISO-8601 format. For example,5sfor 5 seconds,5mfor 5 minutes, and5hfor 5 hours.
- Save the file. For example, trustyai_crd.yaml.
Apply the new TrustyAI service CR to the project that contains the models that the data scientist wants to monitor:
oc apply -f trustyai_crd.yaml -n <project_name>
$ oc apply -f trustyai_crd.yaml -n <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.4. Installing the TrustyAI service for a project Copy linkLink copied to clipboard!
Install the TrustyAI service on a project to provide access to its features for all models deployed within that project. An instance of the TrustyAI service is required for each project, or namespace, that contains models that the data scientists want to monitor.
Install only one instance of the TrustyAI service in a project. Multiple instances in the same project can result in unexpected behavior.
TrustyAI only supports models deployed with OpenVINO Model Server (OVMS). Non-OVMS models are not supported. Installing TrustyAI into a namespace where non-OVMS models are deployed can cause errors in the TrustyAI service.
2.4.1. Installing the TrustyAI service by using the CLI Copy linkLink copied to clipboard!
You can use the OpenShift CLI (oc) to install an instance of the TrustyAI service.
Prerequisites
- You have cluster administrator privileges for your OpenShift cluster.
You have installed the OpenShift CLI (
oc) as described in the appropriate documentation for your cluster:- Installing the OpenShift CLI for OpenShift Container Platform
- Installing the OpenShift CLI for Red Hat OpenShift Service on AWS
- You have configured monitoring for the model serving platform, as described in Configuring monitoring for your model serving platform.
- You have enabled the TrustyAI component, as described in Enabling the TrustyAI component.
- If you are using TrustyAI with a database instead of PVC, you have configured TrustyAI to use the database, as described in Configuring TrustyAI with a database.
- The data scientist has created a project, as described in Creating a project, that contains the models that the data scientist wants to monitor.
Procedure
- Open a new terminal window.
Follow these steps to log in to your OpenShift cluster as a cluster administrator:
- In the OpenShift web console, click your user name and select Copy login command.
- After you have logged in, click Display token.
Copy the Log in with this token command and paste it in the OpenShift CLI (
oc).oc login --token=<token> --server=<openshift_cluster_url>
$ oc login --token=<token> --server=<openshift_cluster_url>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Navigate to the project that contains the models that the data scientist wants to monitor.
oc project <project_name>
oc project <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
oc project my-project
oc project my-projectCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
TrustyAIServicecustom resource (CR) file, for exampletrustyai_crd.yaml:Example CR file for TrustyAI using a database
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The name of the TrustyAI service instance.
- 2
- The storage format for the data, either
DATABASEorPVC(persistent volume claim). Red Hat recommends that you use a database setup for better scalability, performance, and data management in TrustyAI. - 3
- The size of the data to request.
- 4
- The name of the secret with your database credentials that you created in Configuring TrustyAI with a database. For example,
db-credentials. - 5
- The interval at which to calculate the metrics. The default is
5s. The duration is specified with the ISO-8601 format. For example,5sfor 5 seconds,5mfor 5 minutes, and5hfor 5 hours.
Example CR file for TrustyAI using a PVC
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The name of the TrustyAI service instance.
- 2
- The storage format for the data, either
DATABASEorPVC(persistent volume claim). - 3
- The location within the PVC where you want to store the data.
- 4
- The size of the PVC to request.
- 5
- The suffix for the stored data files.
- 6
- The format of the data. Currently, only comma-separated value (CSV) format is supported.
- 7
- The interval at which to calculate the metrics. The default is
5s. The duration is specified with the ISO-8601 format. For example,5sfor 5 seconds,5mfor 5 minutes, and5hfor 5 hours. - 8
- (Optional) The observation’s historical window size to use for metrics calculation. The default is
5000, which means that the metrics are calculated using the 5,000 latest inferences.
Add the TrustyAI service’s CR to your project:
oc apply -f trustyai_crd.yaml
oc apply -f trustyai_crd.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command returns output similar to the following:
trusty-service created
trusty-service createdCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that you installed the TrustyAI service:
oc get pods | grep trustyai
oc get pods | grep trustyai
You should see a response similar to the following:
trustyai-service-5d45b5884f-96h5z 1/1 Running
trustyai-service-5d45b5884f-96h5z 1/1 Running
2.5. Enabling TrustyAI Integration with KServe RawDeployment Copy linkLink copied to clipboard!
To use the TrustyAI service with KServe RawDeployment mode, you must first update the KServe ConfigMap, then create another ConfigMap in your model’s namespace to hold the Certificate Authority (CA) certificate.
Prerequisites
- You have installed Red Hat OpenShift AI.
- You have cluster administrator privileges for your OpenShift AI cluster.
- You have access to a data science cluster that has TrustyAI enabled.
- You have enabled the model serving platform.
Procedure
Update the KServe ConfigMap (
inferenceservice-config) in the OpenShift AI UI:- From the OpenShift console, click Workloads → ConfigMaps.
-
From the project drop-down list, select the
redhat-ods-applicationsnamespace. -
Find the
inferenceservice-configConfigMap. - Click the options menu (⋮) for that ConfigMap, and then click Edit ConfigMap.
Add the following parameters to the logger key:
"caBundle": "kserve-logger-ca-bundle", "caCertFile": "service-ca.crt", "tlsSkipVerify": false
"caBundle": "kserve-logger-ca-bundle", "caCertFile": "service-ca.crt", "tlsSkipVerify": falseCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Click Save.
Create a ConfigMap in your model’s namespace to hold the CA certificate:
- Click Create Config Map.
Enter the following code in the created ConfigMap:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
- Click Save.
The caBundle name can be any valid Kubernetes name, as long as it matches the name you used in the KServe ConfigMap. The caCertFile needs to match the cert name available in the CA bundle.
Verification
When you send inferences to your KServe Raw model, TrustyAI acknowledges the data capture in the output logs.
If you do not observe any data on the Trusty AI logs, complete these configuration steps and redeploy the pod.
Chapter 3. Setting up TrustyAI for your project Copy linkLink copied to clipboard!
To set up model monitoring with TrustyAI for a project, a data scientist does the following tasks:
- Authenticate the TrustyAI service
- Send training data to TrustyAI for bias or data drift monitoring
- Label your data fields (optional)
After setting up, a data scientist can create and view bias and data drift metrics for deployed models.
3.1. Authenticating the TrustyAI service Copy linkLink copied to clipboard!
To access TrustyAI service external endpoints, you must provide OAuth proxy (oauth-proxy) authentication. You must obtain a user token, or a token from a service account with sufficient privileges, and then pass the token to the TrustyAI service when using curl commands.
Prerequisites
You have installed the OpenShift CLI (
oc) as described in the appropriate documentation for your cluster:- Installing the OpenShift CLI for OpenShift Container Platform
- Installing the OpenShift CLI for Red Hat OpenShift Service on AWS
- Your OpenShift cluster administrator added you as a user to the OpenShift cluster and has installed the TrustyAI service for the project that contains the deployed models.
Procedure
- Open a new terminal window.
Follow these steps to log in to your OpenShift cluster:
- In the upper-right corner of the OpenShift web console, click your user name and select Copy login command.
- After you have logged in, click Display token.
Copy the Log in with this token command and paste it in the OpenShift CLI (
oc).oc login --token=<token> --server=<openshift_cluster_url>
$ oc login --token=<token> --server=<openshift_cluster_url>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Enter the following command to set a user token variable on OpenShift:
export TOKEN=$(oc whoami -t)
export TOKEN=$(oc whoami -t)Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Enter the following command to check the user token variable:
echo $TOKEN
echo $TOKENCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Next step
When running curl commands, pass the token to the TrustyAI service using the Authorization header. For example:
curl -H "Authorization: Bearer $TOKEN" $TRUSTY_ROUTE
curl -H "Authorization: Bearer $TOKEN" $TRUSTY_ROUTE
3.2. Uploading training data to TrustyAI Copy linkLink copied to clipboard!
Upload training data to use with TrustyAI for bias monitoring or data drift detection.
Prerequisites
- Your cluster administrator added you as a user to the OpenShift cluster and has installed the TrustyAI service for the project that contains the deployed models.
- You have model training data to upload.
- You authenticated the TrustyAI service as described in Authenticating the TrustyAI service.
Procedure
Set the
TRUSTY_ROUTEvariable to the external route for the TrustyAI service in your project:TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send the training data to the
/data/uploadendpoint:curl -sk $TRUSTY_ROUTE/data/upload \ --header 'Authorization: Bearer ${TOKEN}' \ --header 'Content-Type: application/json' \ -d @data/training_data.jsoncurl -sk $TRUSTY_ROUTE/data/upload \ --header 'Authorization: Bearer ${TOKEN}' \ --header 'Content-Type: application/json' \ -d @data/training_data.jsonCopy to Clipboard Copied! Toggle word wrap Toggle overflow The following message is displayed if the upload was successful:
1000 datapoints successfully added to gaussian-credit-model data.
Verification
Verify that TrustyAI has received the data via the
/infoendpoint by inputting this query:curl -H 'Authorization: Bearer ${TOKEN}' \ $TRUSTY_ROUTE/info | jq ".[0].data"curl -H 'Authorization: Bearer ${TOKEN}' \ $TRUSTY_ROUTE/info | jq ".[0].data"Copy to Clipboard Copied! Toggle word wrap Toggle overflow The output returns a json file containing the following information for the model:
- The names, data types, and positions of fields in the input and output.
-
The observed values that these fields take. This value is usually
nullbecause there are too many unique feature values to enumerate. -
The total number of input-output pairs observed. It should be
1000.
3.3. Sending training data to TrustyAI Copy linkLink copied to clipboard!
To use TrustyAI for bias monitoring or data drift detection, you must send training data for your model to TrustyAI.
Prerequisites
- Your OpenShift cluster administrator added you as a user to the OpenShift cluster and has installed the TrustyAI service for the project that contains the deployed models.
- You authenticated the TrustyAI service as described in Authenticating the TrustyAI service.
- You have uploaded model training data to TrustyAI.
- Your deployed model is registered with TrustyAI.
Procedure
Verify that the TrustyAI service has registered your deployed model:
- In the OpenShift console, go to Workloads → Pods.
- From the project list, select the project that contains your deployed model.
Inspect the
InferenceServicefor your deployed model. For example, run the following command:oc describe inferenceservice my-model -n my-namespace
oc describe inferenceservice my-model -n my-namespaceCopy to Clipboard Copied! Toggle word wrap Toggle overflow When inspecting the
InferenceService, you should see the following field in the specification:Logger: # ... Mode: all URL: https://trustyai-service.my-namespace.svc.cluster.localLogger: # ... Mode: all URL: https://trustyai-service.my-namespace.svc.cluster.localCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Set the
TRUSTY_ROUTEvariable to the external route for the TrustyAI service pod:TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Get the inference endpoints for the deployed model, as described in Accessing the inference endpoint for a deployed model.
- Send data to this endpoint. For more information, see the KServe v2 Inference Protocol documentation.
Verification
Follow these steps to view cluster metrics and verify that TrustyAI is receiving data.
- Log in to the OpenShift web console.
- Switch to the Developer perspective.
- In the left menu, click Observe.
- On the Metrics page, click the Select query list and then select Custom query.
-
In the Expression field, enter
trustyai_model_observations_totaland press Enter. Your model should be listed and reporting observed inferences. - Optional: Select a time range from the list above the graph. For example, select 5m.
3.4. Labeling data fields Copy linkLink copied to clipboard!
After you send model training data to TrustyAI, you might want to apply a set of name mappings to your inputs and outputs so that the field names are meaningful and easier to work with.
Prerequisites
- Your OpenShift cluster administrator added you as a user to the OpenShift cluster and has installed the TrustyAI service for the project that contains the deployed models.
- You sent training data to TrustyAI as described in Sending training data to TrustyAI.
Procedure
- Open a new terminal window.
Follow these steps to log in to your OpenShift cluster:
- In the upper-right corner of the OpenShift web console, click your user name and select Copy login command.
- After you have logged in, click Display token.
Copy the Log in with this token command and paste it in the OpenShift CLI (
oc).oc login --token=<token> --server=<openshift_cluster_url>
$ oc login --token=<token> --server=<openshift_cluster_url>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
In the OpenShift CLI (
oc), get the route to the TrustyAI service:TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})Copy to Clipboard Copied! Toggle word wrap Toggle overflow To examine TrustyAI’s model metadata, query the
/infoendpoint:curl -H "Authorization: Bearer $TOKEN" $TRUSTY_ROUTE/info | jq ".[0].data"
curl -H "Authorization: Bearer $TOKEN" $TRUSTY_ROUTE/info | jq ".[0].data"Copy to Clipboard Copied! Toggle word wrap Toggle overflow This outputs a JSON file containing the following information for each model:
- The names, data types, and positions of input fields and output fields.
- The observed field values.
- The total number of input-output pairs observed.
Use
POST /info/namesto apply name mappings to the fields, similar to the following example.Change the
model-name,original-name, andPredictionvalues to those used in your model. Change theNew namevalues to the labels that you want to use.Copy to Clipboard Copied! Toggle word wrap Toggle overflow For another example, see https://github.com/trustyai-explainability/odh-trustyai-demos/blob/main/2-BiasMonitoring/kserve-demo/scripts/apply_name_mapping.sh.
Verification
A "Feature and output name mapping successfully applied" message is displayed.
Chapter 4. Monitoring model bias Copy linkLink copied to clipboard!
As a data scientist, you might want to monitor your machine learning models for bias. This means monitoring for algorithmic deficiencies that might skew the outcomes or decisions that the model produces. Importantly, this type of monitoring helps you to ensure that the model is not biased against particular protected groups or features.
Red Hat OpenShift AI provides a set of metrics that help you to monitor your models for bias. You can use the OpenShift AI interface to choose an available metric and then configure model-specific details such as a protected attribute, the privileged and unprivileged groups, the outcome you want to monitor, and a threshold for bias. You then see a chart of the calculated values for a specified number of model inferences.
For more information about the specific bias metrics, see Using bias metrics.
4.1. Creating a bias metric Copy linkLink copied to clipboard!
To monitor a deployed model for bias, you must first create bias metrics. When you create a bias metric, you specify details relevant to your model such as a protected attribute, privileged and unprivileged groups, a model outcome and a value that you want to monitor, and the acceptable threshold for bias.
For information about the specific bias metrics, see Using bias metrics.
For the complete list of TrustyAI metrics, see TrustyAI service API.
You can create a bias metric for a model by using the OpenShift AI dashboard or by using the OpenShift CLI (oc).
4.1.1. Creating a bias metric by using the dashboard Copy linkLink copied to clipboard!
You can use the OpenShift AI dashboard to create a bias metric for a model.
Prerequisites
- You are familiar with the bias metrics that you can use with OpenShift AI and how to interpret them.
- You are familiar with the specific data set schema and understand the names and meanings of the inputs and outputs.
- Your OpenShift cluster administrator added you as a user to the OpenShift cluster and has installed the TrustyAI service for the project that contains the deployed models.
- You set up TrustyAI for your project, as described in Setting up TrustyAI for your project.
Procedure
Optional: To set the
TRUSTY_ROUTEvariable, follow these steps.In a terminal window, log in to the OpenShift cluster where OpenShift AI is deployed.
oc login
oc loginCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set the
TRUSTY_ROUTEvariable to the external route for the TrustyAI service pod.TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})Copy to Clipboard Copied! Toggle word wrap Toggle overflow
- In the left menu of the OpenShift AI dashboard, click AI hub → Deployments.
- On the Deployments page, select your project from the drop-down list.
- Click the name of the model that you want to configure bias metrics for.
- On the metrics page for the model, click the Model bias tab.
- Click Configure.
In the Configure bias metrics dialog, complete the following steps to configure bias metrics:
- In the Metric name field, type a unique name for your bias metric. Note that you cannot change the name of this metric later.
- From the Metric type list, select one of the metrics types that are available in OpenShift AI.
In the Protected attribute field, type the name of an attribute in your model that you want to monitor for bias.
TipYou can use a
curlcommand to query the metadata endpoint and view input attribute names and values. For example:curl -H "Authorization: Bearer $TOKEN" $TRUSTY_ROUTE/info | jq ".[0].data.inputSchema"- In the Privileged value field, type the name of a privileged group for the protected attribute that you specified.
- In the Unprivileged value field, type the name of an unprivileged group for the protected attribute that you specified.
In the Output field, type the name of the model outcome that you want to monitor for bias.
TipYou can use a
curlcommand to query the metadata endpoint and view output attribute names and values. For example:curl -H "Authorization: Bearer $TOKEN" $TRUSTY_ROUTE/info | jq ".[0].data.outputSchema"- In the Output value field, type the value of the outcome that you want to monitor for bias.
- In the Violation threshold field, type the bias threshold for your selected metric type. This threshold value defines how far the specified metric can be from the fairness value for your metric, before the model is considered biased.
- In the Metric batch size field, type the number of model inferences that OpenShift AI includes each time it calculates the metric.
Ensure that the values you entered are correct.
NoteYou cannot edit a model bias metric configuration after you create it. Instead, you can duplicate a metric and then edit (configure) it; however, the history of the original metric is not applied to the copy.
- Click Configure.
Verification
- The Bias metric configuration page shows the bias metrics that you configured for your model.
Next step
To view metrics, on the Bias metric configuration page, click View metrics in the upper-right corner.
4.1.2. Creating a bias metric by using the CLI Copy linkLink copied to clipboard!
You can use the OpenShift CLI (oc) to create a bias metric for a model.
Prerequisites
- You are familiar with the bias metrics that you can use with OpenShift AI and how to interpret them.
- You are familiar with the specific data set schema and understand the names and meanings of the inputs and outputs.
- Your OpenShift cluster administrator added you as a user to the OpenShift cluster and has installed the TrustyAI service for the project that contains the deployed models.
- You set up TrustyAI for your project, as described in Setting up TrustyAI for your project.
Procedure
In a terminal window, log in to the OpenShift cluster where OpenShift AI is deployed.
oc login
oc loginCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set the
TRUSTY_ROUTEvariable to the external route for the TrustyAI service pod.TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optionally, get the full list of TrustyAI service endpoints and payloads.
curl -H "Authorization: Bearer $TOKEN" --location $TRUSTY_ROUTE/q/openapi
curl -H "Authorization: Bearer $TOKEN" --location $TRUSTY_ROUTE/q/openapiCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use
POST /metrics/group/fairness/spd/requestto schedule a recurring bias monitoring metric with the following syntax and payload structure:Syntax:
curl -sk -H "Authorization: Bearer $TOKEN" -X POST --location $TRUSTY_ROUTE/metrics/group/fairness/spd/request \ --header 'Content-Type: application/json' \ --data <payload>
curl -sk -H "Authorization: Bearer $TOKEN" -X POST --location $TRUSTY_ROUTE/metrics/group/fairness/spd/request \ --header 'Content-Type: application/json' \ --data <payload>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Payload structure:
modelId- The name of the model to query.
protectedAttribute- The name of the feature that distinguishes the groups that you are checking for fairness.
privilegedAttribute- The suspected favored (positively biased) class.
unprivilegedAttribute- The suspected unfavored (negatively biased) class.
outcomeName- The name of the output that provides the output you are examining for fairness.
favorableOutcome-
The value of the
outcomeNameoutput that describes the favorable or desired model prediction. batchSize- The number of previous inferences to include in the calculation.
For example:
Verification
The bias metrics request should return output similar to the following:
The specificDefinition field helps you understand the real-world interpretation of these metric values. For this example, the model is fair over the Is Male-Identifying? field, with the rate of positive outcome only differing by about -0.3%.
4.1.3. Duplicating a bias metric Copy linkLink copied to clipboard!
If you want to edit an existing metric, you can duplicate (copy) it in the OpenShift AI interface and then edit the values in the copy. However, note that the history of the original metric is not applied to the copy.
Prerequisites
- You are familiar with the bias metrics that you can use with OpenShift AI and how to interpret them.
- You are familiar with the specific data set schema and understand the names and meanings of the inputs and outputs.
- There is an existing bias metric that you want to duplicate.
Procedure
- In the left menu of the OpenShift AI dashboard, click AI hub → Deployments.
- On the Deployments page, click the name of the model with the bias metric that you want to duplicate.
- On the metrics page for the model, click the Model bias tab.
- Click Configure.
- On the Bias metric configuration page, click the action menu (⋮) next to the metric that you want to copy and then click Duplicate.
In the Configure bias metric dialog, follow these steps:
- In the Metric name field, type a unique name for your bias metric. Note that you cannot change the name of this metric later.
- Change the values of the fields as needed. For a description of these fields, see Creating a bias metric by using the dashboard.
- Ensure that the values you entered are correct, and then click Configure.
Verification
- The Bias metric configuration page shows the bias metrics that you configured for your model.
Next step
To view metrics, on the Bias metric configuration page, click View metrics in the upper-right corner.
4.2. Deleting a bias metric Copy linkLink copied to clipboard!
You can delete a bias metric for a model by using the OpenShift AI dashboard or by using the OpenShift CLI (oc).
4.2.1. Deleting a bias metric by using the dashboard Copy linkLink copied to clipboard!
You can use the OpenShift AI dashboard to delete a bias metric for a model.
Prerequisites
- You have logged in to Red Hat OpenShift AI.
- There is an existing bias metric that you want to delete.
Procedure
- In the left menu of the OpenShift AI dashboard, click AI hub → Deployments.
- On the Deployments page, click the name of the model with the bias metric that you want to delete.
- On the metrics page for the model, click the Model bias tab.
- Click Configure.
- Click the action menu (⋮) next to the metric that you want to delete and then click Delete.
In the Delete bias metric dialog, type the metric name to confirm the deletion.
NoteYou cannot undo deleting a bias metric.
- Click Delete bias metric.
Verification
- The Bias metric configuration page does not show the bias metric that you deleted.
4.2.2. Deleting a bias metric by using the CLI Copy linkLink copied to clipboard!
You can use the OpenShift CLI (oc) to delete a bias metric for a model.
Prerequisites
You have installed the OpenShift CLI (
oc) as described in the appropriate documentation for your cluster:- Installing the OpenShift CLI for OpenShift Container Platform
- Installing the OpenShift CLI for Red Hat OpenShift Service on AWS
- You have a user token for authentication as described in Authenticating the TrustyAI service.
- There is an existing bias metric that you want to delete.
Procedure
- Open a new terminal window.
Follow these steps to log in to your OpenShift cluster:
- In the upper-right corner of the OpenShift web console, click your user name and select Copy login command.
- After you have logged in, click Display token.
Copy the Log in with this token command and paste it in the OpenShift CLI (
oc).oc login --token=<token> --server=<openshift_cluster_url>
$ oc login --token=<token> --server=<openshift_cluster_url>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
In the OpenShift CLI (
oc), get the route to the TrustyAI service:TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: To list all currently active requests for a metric, use
GET /metrics/{{metric}}/requests. For example, to list all currently scheduled SPD metrics, type:curl -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/spd/requests"
curl -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/spd/requests"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, to list all currently scheduled metric requests, use
GET /metrics/all/requests.curl -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/all/requests"
curl -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/all/requests"Copy to Clipboard Copied! Toggle word wrap Toggle overflow To delete a metric, send an HTTP
DELETErequest to the/metrics/$METRIC/requestendpoint to stop the periodic calculation, including the id of periodic task that you want to cancel in the payload. For example:curl -H "Authorization: Bearer $TOKEN" -X DELETE --location "$TRUSTY_ROUTE/metrics/spd/request" \ -H "Content-Type: application/json" \ -d "{ \"requestId\": \"3281c891-e2a5-4eb3-b05d-7f3831acbb56\" }"curl -H "Authorization: Bearer $TOKEN" -X DELETE --location "$TRUSTY_ROUTE/metrics/spd/request" \ -H "Content-Type: application/json" \ -d "{ \"requestId\": \"3281c891-e2a5-4eb3-b05d-7f3831acbb56\" }"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Use GET /metrics/{{metric}}/requests to list all currently active requests for the metric and verify the metric that you deleted is not shown. For example:
curl -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/spd/requests"
curl -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/spd/requests"
4.3. Viewing bias metrics for a model Copy linkLink copied to clipboard!
After you create bias monitoring metrics, you can use the OpenShift AI dashboard to view and update the metrics that you configured.
Prerequisite
- You configured bias metrics for your model as described in Creating a bias metric.
Procedure
- In the OpenShift AI dashboard, click AI hub → Deployments.
- On the Deployments page, click the name of a model that you want to view bias metrics for.
- On the metrics page for the model, click the Model bias tab.
To update the metrics shown on the page, follow these steps:
In the Metrics to display section, use the Select a metric list to select a metric to show on the page.
NoteEach time you select a metric to show on the page, an additional Select a metric list is displayed. This enables you to show multiple metrics on the page.
- From the Time range list in the upper-right corner, select a value.
From the Refresh interval list in the upper-right corner, select a value.
The metrics page shows the metrics that you selected.
Optional: To remove one or more metrics from the page, in the Metrics to display section, perform one of the following actions:
- To remove an individual metric, click the cancel icon (✖) next to the metric name.
- To remove all metrics, click the cancel icon (✖) in the Select a metric list.
- Optional: To return to configuring bias metrics for the model, on the metrics page, click Configure in the upper-right corner.
Verification
- The metrics page shows the metrics selections that you made.
4.4. Using bias metrics Copy linkLink copied to clipboard!
You can use the following bias metrics in Red Hat OpenShift AI:
- Statistical Parity Difference
Statistical Parity Difference (SPD) is the difference in the probability of a favorable outcome prediction between unprivileged and privileged groups. The formal definition of SPD is the following:
- ŷ = 1 is the favorable outcome.
- Dᵤ and Dₚ are the unprivileged and privileged group data.
You can interpret SPD values as follows:
-
A value of
0means that the model is behaving fairly for a selected attribute (for example, race, gender). -
A value in the range
-0.1to0.1means that the model is reasonably fair for a selected attribute. Instead, you can attribute the difference in probability to other factors, such as the sample size. -
A value outside the range
-0.1to0.1indicates that the model is unfair for a selected attribute. - A negative value indicates that the model has bias against the unprivileged group.
- A positive value indicates that the model has bias against the privileged group.
- Disparate Impact Ratio
Disparate Impact Ratio (DIR) is the ratio of the probability of a favorable outcome prediction for unprivileged groups to that of privileged groups. The formal definition of DIR is the following:
- ŷ = 1 is the favorable outcome.
- Dᵤ and Dₚ are the unprivileged and privileged group data.
The threshold to identify bias depends on your own criteria and specific use case.
For example, if your threshold for identifying bias is represented by a DIR value below
0.8or above1.2, you can interpret the DIR values as follows:-
A value of
1means that the model is fair for a selected attribute. -
A value of between
0.8and1.2means that the model is reasonably fair for a selected attribute. -
A value below
0.8or above1.2indicates bias.
Chapter 5. Monitoring data drift Copy linkLink copied to clipboard!
Data drift refers to changes that occur in the distribution of incoming data that differ significantly from the data on which the model was originally trained. This distributional shift can cause model performance to become unreliable, because machine learning models rely heavily on the patterns in their training data.
Detecting data drift helps ensure that your models continue to perform as expected and that they remain accurate and reliable. Trusty AI measures the statistical alignment between a model’s training data and its incoming inference data using specialized metrics.
Metrics for drift detection include:
- Mean-Shift
- FourierMMD
- Kolmogorov-Smirnov
- ApproxKSTest
5.1. Creating a drift metric Copy linkLink copied to clipboard!
To monitor a deployed model for data drift, you must first create drift metrics.
For information about the specific data drift metrics, see Using drift metrics.
For the complete list of TrustyAI metrics, see TrustyAI service API.
5.1.1. Creating a drift metric by using the CLI Copy linkLink copied to clipboard!
You can use the OpenShift CLI (oc) to create a data drift metric for a model.
Prerequisites
- You are familiar with the specific data set schema and understand the relevant inputs and outputs.
- Your OpenShift cluster administrator added you as a user to the OpenShift cluster and has installed the TrustyAI service for the project that contains the deployed models.
- You set up TrustyAI for your project, as described in Setting up TrustyAI for your project.
Procedure
- Open a new terminal window.
Follow these steps to log in to your OpenShift cluster:
- In the upper-right corner of the OpenShift web console, click your user name and select Copy login command.
- After you have logged in, click Display token.
Copy the Log in with this token command and paste it in the OpenShift CLI (
oc).oc login --token=<token> --server=<openshift_cluster_url>
$ oc login --token=<token> --server=<openshift_cluster_url>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Set the
TRUSTY_ROUTEvariable to the external route for the TrustyAI service pod.TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optionally, get the full list of TrustyAI service endpoints and payloads.
curl -H "Authorization: Bearer $TOKEN" --location $TRUSTY_ROUTE/q/openapi
curl -H "Authorization: Bearer $TOKEN" --location $TRUSTY_ROUTE/q/openapiCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use
POST /metrics/drift/meanshift/requestto schedule a recurring drift monitoring metric with the following syntax and payload structure:Syntax:
curl -k -H "Authorization: Bearer $TOKEN" -X POST --location $TRUSTY_ROUTE/metrics/drift/meanshift/request \ --header 'Content-Type: application/json' \ --data <payload>
curl -k -H "Authorization: Bearer $TOKEN" -X POST --location $TRUSTY_ROUTE/metrics/drift/meanshift/request \ --header 'Content-Type: application/json' \ --data <payload>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Payload structure:
modelId- The name of the model to monitor.
referenceTag- The data to use as the reference distribution.
For example:
5.2. Deleting a drift metric by using the CLI Copy linkLink copied to clipboard!
You can use the OpenShift CLI (oc) to delete a drift metric for a model.
Prerequisites
You have installed the OpenShift CLI (
oc) as described in the appropriate documentation for your cluster:- Installing the OpenShift CLI for OpenShift Container Platform
- Installing the OpenShift CLI for Red Hat OpenShift Service on AWS
- You have a user token for authentication as described in Authenticating the TrustyAI service.
- There is an existing drift metric that you want to delete.
Procedure
- Open a new terminal window.
Follow these steps to log in to your OpenShift cluster:
- In the OpenShift web console, click your user name and select Copy login command.
- After you have logged in, click Display token.
Copy the Log in with this token command and paste it in the OpenShift CLI (
oc).oc login --token=<token> --server=<openshift_cluster_url>
$ oc login --token=<token> --server=<openshift_cluster_url>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
In the OpenShift CLI (
oc), get the route to the TrustyAI service:TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: To list all currently active requests for a metric, use
GET /metrics/{{metric}}/requests. For example, to list all currently scheduled MeanShift metrics, type:curl -k -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/drift/meanshift/requests"
curl -k -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/drift/meanshift/requests"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, to list all currently scheduled metric requests, use
GET /metrics/all/requests.curl -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/all/requests"
curl -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/all/requests"Copy to Clipboard Copied! Toggle word wrap Toggle overflow To delete a metric, send an HTTP
DELETErequest to the/metrics/$METRIC/requestendpoint to stop the periodic calculation, including the id of periodic task that you want to cancel in the payload. For example:curl -k -H "Authorization: Bearer $TOKEN" -X DELETE --location "$TRUSTY_ROUTE/metrics/drift/meanshift/request" \ -H "Content-Type: application/json" \ -d "{ \"requestId\": \"$id\" }"curl -k -H "Authorization: Bearer $TOKEN" -X DELETE --location "$TRUSTY_ROUTE/metrics/drift/meanshift/request" \ -H "Content-Type: application/json" \ -d "{ \"requestId\": \"$id\" }"Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Use GET /metrics/{{metric}}/requests to list all currently active requests for the metric and verify the metric that you deleted is not shown. For example:
curl -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/drift/meanshift/requests"
curl -H "Authorization: Bearer $TOKEN" -X GET --location "$TRUSTY_ROUTE/metrics/drift/meanshift/requests"
5.3. Viewing drift metrics for a model Copy linkLink copied to clipboard!
After you create data drift monitoring metrics, use the OpenShift web console to view and update the drift metrics that you configured.
Prerequisites
-
You have been assigned the
monitoring-rules-viewrole. For more information, see Granting users permission to configure monitoring for user-defined projects. - You are familiar with how to monitor project metrics in the OpenShift web console. For more information, see Monitoring your project metrics.
Procedure
- Log in to the OpenShift web console.
- Switch to the Developer perspective.
- In the left menu, click Observe.
-
As described in Monitoring your project metrics, use the web console to run queries for
trustyai_*metrics.
5.4. Using drift metrics Copy linkLink copied to clipboard!
You can use the following data drift metrics in Red Hat OpenShift AI:
- MeanShift
The MeanShift metric calculates the per-column probability that the data values in a test data set are from the same distribution as those in a training data set (assuming that the values are normally distributed). This metric measures the difference in the means of specific features between the two datasets.
MeanShift is useful for identifying straightforward changes in data distributions, such as when the entire distribution has shifted to the left or right along the feature axis.
This metric returns the probability that the distribution seen in the "real world" data is derived from the same distribution as the reference data. The closer the value is to 0, the more likely there is to be significant drift.
- FourierMMD
The FourierMMD metric provides the probability that the data values in a test data set have drifted from the training data set distribution, assuming that the computed Maximum Mean Discrepancy (MMD) values are normally distributed. This metric compares the empirical distributions of the data sets by using an MMD measure in the Fourier domain.
FourierMMD is useful for detecting subtle shifts in data distributions that might be overlooked by simpler statistical measures.
This metric returns the probability that the distribution seen in the "real world" data has drifted from the reference data. The closer the value is to 1, the more likely there is to be significant drift.
- KSTest
The KSTest metric calculates two Kolmogorov-Smirnov tests for each column to determine whether the data sets are derived from the same distributions. This metric measures the maximum distance between the empirical cumulative distribution functions (CDFs) of the data sets, without assuming any specific underlying distribution.
KSTest is useful for detecting changes in distribution shape, location, and scale.
This metric returns the probability that the distribution seen in the "real world" data is derived from the same distribution as the reference data. The closer the value is to 0, the more likely there is to be significant drift.
- ApproxKSTest
The ApproxKSTest metric performs an approximate Kolmogorov-Smirnov test, ensuring that the maximum error is
6*epsiloncompared to an exact KSTest.ApproxKSTest is useful for detecting changes in distributions for large data sets where performing an exact KSTest might be computationally expensive.
This metric returns the probability that the distribution seen in the "real world" data is derived from the same distribution as the reference data. The closer the value is to 0, the more likely there is to be significant drift.
5.5. Using a drift metric in a credit card scenario Copy linkLink copied to clipboard!
This example scenario deploys an XGBoost model into your cluster and reviews its output using a drift metric.
The XGBoost model was created for the purpose of this demonstration and predicts credit card approval based on the following features: age, credit score, years of education, and years in employment.
When the model is deployed and the data that you upload is formatted, use the mean shift metric to monitor for data drift. This metric is useful for ensuring that a model remains accurate and reliable in a production environment.
Mean shift compares a numeric test dataset against a numeric training dataset. It produces a p-value that measures the probability the test data has originated from the same numeric distribution as the training data. A p-value less than 0.05 indicates a statistically significant drift between the two datasets. A p-value equal to or greater than 0.05 indicates no statistically significant evidence of drift.
Mean shift performs best when each feature in the data is normally distributed. Choose a different metric for working with different or unknown data distributions.
Prerequisites
- Your cluster administrator added you as a user to the cluster and configured TrustyAI for use in the project that contains the deployed models.
- You set up TrustyAI for your project, as described in Setting up TrustyAI for your project.
Procedure
Obtain a bearer token to authenticate your external endpoints by running the following command:
oc apply -f resources/service_account.yaml export TOKEN=$(oc create token user-one)
$ oc apply -f resources/service_account.yaml export TOKEN=$(oc create token user-one)Copy to Clipboard Copied! Toggle word wrap Toggle overflow In your model namespace, deploy the storage container, serving runtime, and the credit model:
oc project model-namespace || true oc apply -f resources/model_storage_container.yaml oc apply -f resources/odh-mlserver-1.x.yaml oc apply -f resources/model_gaussian_credit.yaml
$ oc project model-namespace || true $ oc apply -f resources/model_storage_container.yaml $ oc apply -f resources/odh-mlserver-1.x.yaml $ oc apply -f resources/model_gaussian_credit.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set the route for your data upload:
TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})TRUSTY_ROUTE=https://$(oc get route/trustyai-service --template={{.spec.host}})Copy to Clipboard Copied! Toggle word wrap Toggle overflow Download the training data payload (file size 472 KB):
wget https://github.com/trustyai-explainability/odh-trustyai-demos/blob/72f748da9410f92a60bea73ce5e3f47c10ad1cea/3-DataDrift/kserve-demo/data/training_data.json -O training_data.json
wget https://github.com/trustyai-explainability/odh-trustyai-demos/blob/72f748da9410f92a60bea73ce5e3f47c10ad1cea/3-DataDrift/kserve-demo/data/training_data.json -O training_data.jsonCopy to Clipboard Copied! Toggle word wrap Toggle overflow Label your model training data. This data has four main fields. The
model_nameanddata_tagfields require a label because they are directly referenced in the Metrics dashboard later in the scenario. In addition to the required fields, it is best to also label response and request fields. The four fields are:-
model_name: The name of the model that correlates to this data. The name should match that of the model provided in the model YAML, which isgaussian-credit-model. -
data_tag: A string tag to reference this particular set of data. Use the string"TRAINING". -
request: This is a KServe inference request, as if you were sending this data directly to the model server’s/inferendpoint. -
response: The KServe inference response that is returned from sending the above request to the model.
-
Upload the model training data to the TrustyAI endpoint:
curl -sk -H "Authorization: Bearer ${TOKEN}" $TRUSTY_ROUTE/data/upload \ --header 'Content-Type: application/json' \ -d @training_data.jsoncurl -sk -H "Authorization: Bearer ${TOKEN}" $TRUSTY_ROUTE/data/upload \ --header 'Content-Type: application/json' \ -d @training_data.jsonCopy to Clipboard Copied! Toggle word wrap Toggle overflow The following message appears confirming the data upload:
1000 datapoints successfully added to gaussian-credit-model data.Label your model input and output fields with the actual column names of the data in your KServe payloads. Send a JSON payload containing a simple set of
original-name:new-name pairs, assigning new meaningful names to the input and output features of your model. A message that says "Feature and output name mapping successfully applied" appears if the request is successful:Copy to Clipboard Copied! Toggle word wrap Toggle overflow TipDefine name mappings in TrustyAI to assign memorable names to input or output names. These names can then be used in subsequent requests to the TrustyAI service.
Verify that TrustyAI has received the data by querying the
/infoendpoint:curl -H "Authorization: Bearer ${TOKEN}" $TRUSTY_ROUTE/info | jq '.["gaussian-credit-model"].data.inputSchema'curl -H "Authorization: Bearer ${TOKEN}" $TRUSTY_ROUTE/info | jq '.["gaussian-credit-model"].data.inputSchema'Copy to Clipboard Copied! Toggle word wrap Toggle overflow The following output appears as a JSON file confirming that TrustyAI has successfully received the data:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a recurring drift monitoring metric using
/metrics/drift/meanshift/request. This will measure the drift of all recorded inference data against the reference distribution. The body of the payload requires amodelIdthat sets which model to monitor and a referenceTag that determines which data to use as the reference distribution. The values of these fields should match themodelIdandreferenceTaginside your data upload payload:curl -k -H "Authorization: Bearer ${TOKEN}" -X POST --location $TRUSTY_ROUTE/metrics/drift/meanshift/request -H "Content-Type: application/json" \ -d "{ \"modelId\": \"gaussian-credit-model\", \"referenceTag\": \"TRAINING\" }"curl -k -H "Authorization: Bearer ${TOKEN}" -X POST --location $TRUSTY_ROUTE/metrics/drift/meanshift/request -H "Content-Type: application/json" \ -d "{ \"modelId\": \"gaussian-credit-model\", \"referenceTag\": \"TRAINING\" }"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check the metrics in the OpenShift console under Observe → Metrics:
- Set the time window to 5 minutes and the refresh interval to 15 seconds.
In the Expression field, enter
trustyai_meanshift.NoteIt may take a few seconds before the cluster monitoring stacks picks up the new metric. You may need to refresh before the new metrics appear, if you’re already in the section of the OpenShift console.
- Observe in the Metric Chart onscreen that a metric is emitted for each of the four features and the single output, making for five measurements in total. All metric values should equal 1 (no drift), because we only have the training data, which can’t drift from itself.
Collect some simulated real-world inferences to observe the drift monitoring. To do this, send small batches of data to the model, mimicking a real-world deployment:
Get the route to the model:
MODEL=gaussian-credit-model BASE_ROUTE=$(oc get inferenceservice gaussian-credit-model -o jsonpath='{.status.url}') MODEL_ROUTE="${BASE_ROUTE}/v2/models/${MODEL}/infer"MODEL=gaussian-credit-model BASE_ROUTE=$(oc get inferenceservice gaussian-credit-model -o jsonpath='{.status.url}') MODEL_ROUTE="${BASE_ROUTE}/v2/models/${MODEL}/infer"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Download the data batch and send data payloads to your model:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Observe the updated drift metrics in the Observe → Metrics section of the OpenShift console. The mean shift metric values for the various features change:
- The values for Credit Score, Age, and Acceptance Probability have all dropped to 0, indicating there is a statistically very high likelihood that the values of these fields in the inference data come from a different distribution than that of the training data.
- The Years of Employment and Years of Education scores have dropped to 0.34 and 0.82 respectively, indicating that there is a little drift, but not enough to be particularly concerning.