此内容没有您所选择的语言版本。
Chapter 3. Setting up TrustyAI for your project
To set up model monitoring with TrustyAI for a data science 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 复制链接链接已复制到粘贴板!
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 data science 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 复制链接链接已复制到粘贴板!
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 data science 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 复制链接链接已复制到粘贴板!
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 data science 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.
Verify that the TrustyAI service has registered your deployed model, as follows:
-
In the OpenShift web console, navigate to Workloads
Pods. - From the project list, select the project that contains your deployed model.
-
Select the pod for your serving platform (for example,
modelmesh-serving-ovms-1.x-xxxxx). -
On the Environment tab, verify that the
MM_PAYLOAD_PROCESSORSenvironment variable is set.
-
In the OpenShift web console, navigate to Workloads
Procedure
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 复制链接链接已复制到粘贴板!
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 data science 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.