OpenShift AI tutorial - Fraud detection example


Red Hat OpenShift AI Cloud Service 1

Use OpenShift AI to train and deploy an example fraud detection model

Abstract

Step-by-step guidance for using OpenShift AI to train an example model in JupyterLab, deploy the model, refine the model by using automated pipelines, and train the model by using distributed computing frameworks.

Chapter 1. Introduction

Welcome. In this tutorial, you learn how to use data science and artificial intelligence (AI) and machine learning (ML) in an OpenShift development workflow.

You complete the following tasks in Red Hat OpenShift AI without the need to install anything on your computer:

  • Explore a pre-trained fraud detection model by using a Jupyter notebook.
  • Deploy the model by using OpenShift AI model serving.
  • Refine and train the model by using automated pipelines.
  • Learn how to train the model by using distributed computing frameworks.

1.1. About the example fraud detection model

The example fraud detection model monitors credit card transactions for potential fraudulent activity. It analyzes the following credit card transaction details:

  • The geographical distance from an earlier credit card transaction.
  • The price of the current transaction, compared to the median price of all the user’s transactions.
  • Whether the user completed the transaction by using the hardware chip in the credit card, by entering a PIN number, or by making an online purchase.

Based on this data, the model outputs the likelihood of the transaction being fraudulent.

1.2. Before you begin

  • You must have access to an OpenShift cluster which has Red Hat OpenShift AI installed.

    If you do not have access to a cluster that has an instance of OpenShift AI, see the Red Hat OpenShift AI page on the Red Hat Developer website. There, you can create an account and access the free Red Hat Developer Sandbox or you can learn how to install OpenShift AI on your own OpenShift cluster.

    Important

    If your cluster uses self-signed certificates, before you begin the tutorial, your OpenShift AI administrator must add self-signed certificates for OpenShift AI as described in Working with certificates (Self-Managed) or Working with certificates (Cloud Service).

  • Make sure that the version of this tutorial matches the OpenShift AI version on your cluster.

    Red Hat OpenShift AI v2.25 is the version described in this tutorial.

    1. To find the OpenShift AI version for your cluster:

      1. Log in to the OpenShift AI dashboard.
      2. In the top navigation bar, click the help icon ( Help icon ) and then select About.

        The About page shows the installed version.

    2. Check the Red Hat OpenShift AI Supported Configurations page to verify that your installed version is a supported version.
    3. If this version of the tutorial does not match the installed version, access the matching version of the tutorial by navigating to the top-level Red Hat OpenShift AI documentation page and selecting the matching version from the drop-down list.

If you’re ready, start the tutorial.

Chapter 2. Setting up a project and storage

2.2. Setting up your data science project

To implement a data science workflow, you must create a data science project (as described in the following procedure). Projects help your team to organize and work together on resources within separated namespaces. From a project you can create many workbenches, each with their own IDE environment (for example, JupyterLab), and each with their own connections and cluster storage. In addition, the workbenches can share models and data with pipelines and model servers.

Prerequisites

  • You have logged in to Red Hat OpenShift AI.

Procedure

  1. On the navigation menu, select Data science projects. This page lists any existing projects that you have access to.
  2. If you are using the Red Hat Developer Sandbox, it provides a default data science project (for example, myname-dev). Select it and skip to the Verification section.

    If you are using your own OpenShift cluster, you can select an existing project (if any) or create a new one. Click Create project.

    Note

    You can start a Jupyter notebook by clicking the Start basic workbench button, selecting a notebook image, and clicking Start server. However, in that case, it is a one-off Jupyter notebook run in isolation.

  3. In the Create project modal, enter a display name and description.

  4. Click Create.

Verification

You can see your project’s initial state. Individual tabs show more information about the project components and project access permissions:

  • Workbenches are instances of your development and experimentation environment. They typically contain individual development environments (IDEs), such as JupyterLab, RStudio, and Visual Studio Code.
  • Pipelines contain the data science pipelines which run within the project.
  • Models for quickly serving a trained model for real-time inference. You can have many model servers per data science project. One model server can host many models.
  • Cluster storage is a persistent volume that retains the files and data you’re working on within a workbench. A workbench has access to one or more cluster storage instances.
  • Connections contain required configuration parameters for connecting to a data source, such as an S3 object bucket.
  • Permissions define which users and groups can access the project.

2.3. Storing data with connections

Add connections to workbenches to connect your project to data inputs and object storage buckets. A connection is a resource that has the configuration parameters needed to connect to a data source or data sink, such as an AWS S3 object storage bucket.

For this tutorial, you run a provided script that creates the following local Minio storage buckets for you:

  • My Storage - Use this bucket for storing your models and data. You can reuse this bucket and its connection for your notebooks and model servers.
  • Pipelines Artifacts - Use this bucket as storage for your pipeline artifacts. When you create a pipeline server, you need a pipeline artifacts bucket. For this tutorial, create this bucket to separate it from the first storage bucket for clarity.
Note

Although you can use one storage bucket for both storing models and data and for storing pipeline artifacts, this tutorial follows best practice and uses separate storage buckets for each purpose.

The provided script also creates a connection to each storage bucket.

To run the script that installs local MinIO storage buckets and creates connections to them, follow the steps in Running a script to install local object storage buckets and create connections.

Note

If you want to use your own S3-compatible object storage buckets (instead of using the provided script), follow the steps in Creating connections to your own S3-compatible object storage.

For convenience, run a script (provided in the following procedure) that automatically completes these tasks:

  • Creates a Minio instance in your project.
  • Creates two storage buckets in that Minio instance.
  • Generates a random user id and password for your Minio instance.
  • Creates two connections in your project, one for each bucket and both using the same credentials.
  • Installs required network policies for service mesh functionality.

The guide for deploying Minio is the basis for this script.

Important

The Minio-based Object Storage that the script creates is not meant for production usage.

Note

If you want to connect to your own storage, see Creating connections to your own S3-compatible object storage.

Prerequisites

You must know the OpenShift resource name for your data science project so that you run the provided script in the correct project. To get the project’s resource name:

In the OpenShift AI dashboard, select Data science projects and then click the ? icon next to the project name. A text box opens with information about the project, including its resource name:

Note

The following procedure describes how to run the script from the OpenShift console. If you are knowledgeable in OpenShift and can access the cluster from the command line, instead of following the steps in this procedure, you can use the following command to run the script:

oc apply -n <your-project-name/> -f https://github.com/rh-aiservices-bu/fraud-detection/raw/main/setup/setup-s3.yaml
Copy to Clipboard Toggle word wrap

Procedure

  1. In the OpenShift AI dashboard, click the application launcher icon and then select the OpenShift Console option.

  2. In the OpenShift console, click + in the top navigation bar.

  3. Select your project from the list of projects.

  4. Verify that you selected the correct project.

  5. Copy the following code and paste it into the Import YAML editor.

    Note

    This code gets and applies the setup-s3-no-sa.yaml file.

    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: demo-setup
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: demo-setup-edit
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: edit
    subjects:
      - kind: ServiceAccount
        name: demo-setup
    ---
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: create-s3-storage
    spec:
      selector: {}
      template:
        spec:
          containers:
            - args:
                - -ec
                - |-
                  echo -n 'Setting up Minio instance and connections'
                  oc apply -f https://github.com/rh-aiservices-bu/fraud-detection/raw/main/setup/setup-s3-no-sa.yaml
              command:
                - /bin/bash
              image: image-registry.openshift-image-registry.svc:5000/openshift/tools:latest
              imagePullPolicy: IfNotPresent
              name: create-s3-storage
          restartPolicy: Never
          serviceAccount: demo-setup
          serviceAccountName: demo-setup
    Copy to Clipboard Toggle word wrap
  6. Click Create.

Verification

  1. In the OpenShift console, there is a "Resources successfully created" message and a list of the following resources:

    • demo-setup
    • demo-setup-edit
    • create-s3-storage
  2. In the OpenShift AI dashboard:

    1. Select Data science projects and then click the name of your project, Fraud detection.
    2. Click Connections. There are two connections listed: My Storage and Pipeline Artifacts.

Important

If your cluster uses self-signed certificates, your OpenShift AI administrator might need to configure a certificate authority (CA) to securely connect to the S3 object storage, as described in Accessing S3-compatible object storage with self-signed certificates (Self-Managed) or Accessing S3-compatible object storage with self-signed certificates (Cloud Service).

Next step

If you want to complete the pipelines section of this tutorial, go to Enabling data science pipelines.

Otherwise, skip to Creating a workbench.

If you have existing S3-compatible storage buckets that you want to use for this tutorial, you must create a connection to one storage bucket for saving your data and models. If you want to complete the pipelines section of this tutorial, create another connection to a different storage bucket for saving pipeline artifacts.

Note

If you do not have your own s3-compatible storage, or if you want to use a disposable local Minio instance instead, skip this task and follow the steps in Running a script to install local object storage buckets and create connections. The provided script automatically completes the following tasks for you: creates a Minio instance in your project, creates two storage buckets in that Minio instance, creates two connections in your project, one for each bucket and both using the same credentials, and installs required network policies for service mesh functionality.

Prerequisites

To create connections to your existing S3-compatible storage buckets, you need the following credential information for the storage buckets:

  • Endpoint URL
  • Access key
  • Secret key
  • Region
  • Bucket name

If you do not have this information, contact your storage administrator.

Procedure

  1. Create a connection for saving your data and models:

    1. In the OpenShift AI dashboard, navigate to the page for your data science project.
    2. Click the Connections tab, and then click Create connection.

    3. In the Add connection modal, for the Connection type select S3 compatible object storage - v1.
    4. Complete the Add connection form and name your connection My Storage. This connection is for saving your personal work, including data and models.

    5. Click Create.
  2. Create a connection for saving pipeline artifacts:

    Note

    If you do not intend to complete the pipelines section of the tutorial, you can skip this step.

    1. Click Add connection.
    2. Complete the form and name your connection Pipeline Artifacts.

    3. Click Create.

Verification

In the Connections tab for the project, check to see that your connections are listed.

Important

If your cluster uses self-signed certificates, your OpenShift AI administrator might need to provide a certificate authority (CA) to securely connect to the S3 object storage, as described in Accessing S3-compatible object storage with self-signed certificates (Self-Managed) or Accessing S3-compatible object storage with self-signed certificates (Cloud Service).

Next step

If you want to complete the pipelines section of this tutorial, go to Enabling data science pipelines.

Otherwise, skip to Creating a workbench.

2.4. Enabling data science pipelines

You must prepare your tutorial environment so that you can use data science pipelines.

Note

If you do not intend to complete the pipelines section of this tutorial you can skip this step and move on to the next section, Setting up Kueue resources.

Later in this tutorial, you implement an example pipeline by using the JupyterLab Elyra extension. With Elyra, you can create a visual end-to-end pipeline workflow that executes in OpenShift AI.

Prerequisites

Procedure

  1. In the OpenShift AI dashboard, on the Fraud Detection page, click the Pipelines tab.
  2. Click Configure pipeline server.

  3. In the Configure pipeline server form, in the Access key field next to the key icon, click the dropdown menu and then click Pipeline Artifacts.

    The Configure pipeline server form autofills with credentials for the connection.

  4. In the Advanced Settings section, leave the default values.
  5. Click Configure pipeline server.
  6. Wait until the loading spinner disappears and Start by importing a pipeline is displayed.

    Important

    You must wait until the pipeline configuration is complete before you continue and create your workbench. If you create your workbench before the pipeline server is ready, your workbench cannot submit pipelines to it.

    If you have waited more than 5 minutes, and the pipeline server configuration does not complete, you can delete the pipeline server and create it again.

    You can also ask your OpenShift AI administrator to verify that they applied self-signed certificates on your cluster as described in Working with certificates (Self-Managed) or Working with certificates (Cloud Service).

Verification

  1. Navigate to the Pipelines tab for the project.
  2. Next to Import pipeline, click the action menu (⋮) and then select View pipeline server configuration.

    An information box opens and displays the object storage connection information for the pipeline server.

2.5. Setting up Kueue resources

You must prepare your tutorial environment so that you can use Kueue for distributing training with the Training Operator.

In the Distributing training jobs with the Training Operator section of this tutorial, you implement a distributed training job by using Kueue for managing job resources. With Kueue, you can manage cluster resource quotas and how different workloads consume them.

Note

If you are using the Red Hat Developer Sandbox, or if you do not intend to use Kueue to schedule your training jobs in the Distributing training jobs with the Training Operator section of this tutorial, skip this procedure and continue to the next section, Creating a workbench and selecting a workbench image.

Procedure

  1. In the OpenShift AI dashboard, click the application launcher icon and then select the OpenShift Console option.

  2. In the OpenShift console, click + in the top navigation bar.

  3. Select your project from the list of projects.

  4. Verify that you selected the correct project.

  5. Copy the following code and paste it into the Import YAML editor.

    ---
    apiVersion: kueue.x-k8s.io/v1beta1
    kind: ResourceFlavor
    metadata:
      name: default-flavor
    ---
    apiVersion: kueue.x-k8s.io/v1beta1
    kind: ClusterQueue
    metadata:
      name: cluster-queue
    spec:
      namespaceSelector: {}
      resourceGroups:
      - coveredResources: ["cpu", "memory"]
        flavors:
        - name: "default-flavor"
          resources:
          - name: "cpu"
            nominalQuota: 4
          - name: "memory"
            nominalQuota: 8Gi
    ---
    apiVersion: kueue.x-k8s.io/v1beta1
    kind: LocalQueue
    metadata:
      name: local-queue
    spec:
      clusterQueue: cluster-queue
    Copy to Clipboard Toggle word wrap
  6. Click Create.

Verification

  1. In the OpenShift console, there is a "Resources successfully created" message with a list of the following resources:

    • default-flavor
    • cluster-queue
    • local-queue

A workbench is an instance of your development and experimentation environment. When you create a workbench, you select a workbench image that has the tools and libraries that you need for developing models.

Prerequisites

Procedure

  1. Navigate to the project detail page for the data science project that you created in Setting up your data science project.
  2. Click the Workbenches tab, and then click the Create workbench button.

  3. Fill out the name and description.

    Red Hat provides several supported workbench images. In the Workbench image section, you can select one of the default images or a custom image that an administrator has set up for you. The Tensorflow image has the libraries needed for this tutorial.

  4. Select the latest Tensorflow image.

  5. Choose a small deployment.

  6. If your OpenShift cluster has available GPUs, the Create workbench form includes an Accelerator option. Select None. This tutorial does not require any GPUs.
  7. Leave the default environment variables and storage options.

  8. For Connections, click Attach existing connection.
  9. Select My Storage (the object storage that you configured earlier) and then click Attach.

  10. Click Create workbench.

Verification

In the Workbenches tab for the project, the status of the workbench changes from Starting to Running.

Note

If you made a mistake, you can edit the workbench to make changes.

The JupyterLab environment is a web-based environment, but everything you do inside it happens on Red Hat OpenShift AI and is powered by the OpenShift cluster. This means that, without having to install and maintain anything on your own computer, and without using valuable local resources such as CPU, GPU and RAM, you can conduct your data science work in this powerful and stable managed environment.

Prerequisites

You created a workbench, as described in Creating a workbench and selecting a workbench image.

Procedure

  1. Click the link for your workbench. If prompted, log in and allow JupyterLab to authorize your user.

    Your JupyterLab environment window opens.

    This file-browser window shows the files and folders that are saved inside your own personal space in OpenShift AI.

  2. Bring the content of this tutorial inside your JupyterLab environment:

    1. On the toolbar, click the Git Clone icon:

    2. Enter the following tutorial Git https URL:

      https://github.com/rh-aiservices-bu/fraud-detection.git
      Copy to Clipboard Toggle word wrap
    3. Select the Include submodules option, and then click Clone.
    4. In the file browser, double-click the newly-created fraud-detection folder.

    5. In the left navigation bar, click the Git icon, and then click Current Branch to expand the branches and tags selector panel.

      1. On the Branches tab, in the Filter field, enter v2.25.

    6. Select origin/v2.25.

      The current branch changes to v2.25.

Verification

In the file browser, view the notebooks that you cloned from Git.

or

Training a model

3.3. Running code in a notebook

Note

If you’re already at ease with Jupyter, you can skip to the next section.

A notebook is an environment where you have cells that can display formatted text or code.

This is an empty cell:

This is a cell with some code:

Code cells contain Python code that you can run interactively. You can edit the code and then run it. The code does not run on your computer or in the browser, but directly in your connected environment, Red Hat OpenShift AI in your case.

You can run a code cell from the notebook interface or from the keyboard:

  • From the user interface: Select the cell (by clicking inside the cell or to the left side of the cell) and then click Run from the toolbar.

  • From the keyboard: Press CTRL + ENTER to run a cell or press SHIFT + ENTER to run the cell and automatically select the next one.

After you run a cell, you can see the result of its code and information about when the code in the cell ran, as shown in this example:

When you save a notebook, the code and the results are saved. You can reopen the notebook to view the results without having to run the program again, and still having access to the code.

Notebooks are so named because they are like a physical notebook: you can take notes about your experiments, along with the code itself, including any parameters that you set. You can see the output of the experiment inline (this is the result after a cell runs), along with all the notes that you want to take. To take notes, from the menu switch the cell type from Code to Markdown.

Prerequisites

Procedure

  1. In your JupyterLab environment, locate the 0_sandbox.ipynb file and double-click it to launch the notebook. The notebook opens in a new tab in the content section of the environment.

  2. Experiment by, for example, running the existing cells, adding more cells and creating functions.

    You can do what you want - it is your environment and there is no risk of breaking anything or impacting other users. This environment isolation is also a great advantage brought by OpenShift AI.

  3. Optionally, create a new notebook in which the code cells are run by using a Python 3 kernel:

    1. Create a new notebook by either selecting File →New →Notebook or by clicking the Python 3 tile in the Notebook section of the launcher window:

      You can use different kernels, with different languages or versions, to run in your notebook.

Additional resources

Next step

Training a model

3.4. Training a model

In your notebook environment, open the 1_experiment_train.ipynb file and follow the instructions directly in the notebook. The instructions guide you through some simple data exploration, experimentation, and model training tasks.

When you save the model, you convert the model to the portable Open Neural Network Exchange (ONNX) format. By using ONNX, you can transfer models between frameworks with minimal preparation and without the need for rewriting the models.

Chapter 4. Deploying and testing a model

4.1. Preparing a model for deployment

After you train a model, you can deploy it by using the OpenShift AI model serving capabilities.

To prepare a model for deployment, you must move the model from your workbench to your S3-compatible object storage. Use the connection that you created in the Storing data with connections section and upload the model from a notebook.

Prerequisites

  • You created the My Storage connection and have added it to your workbench.

Procedure

  1. In your JupyterLab environment, open the 2_save_model.ipynb file.
  2. Follow the instructions in the notebook to make the model accessible in storage.

Verification

When you have completed the notebook instructions, the models/fraud/1/model.onnx file is in your object storage and it is ready for your model server to use.

4.2. Deploying a model

Given that the model is accessible in storage and saved in the portable ONNX format, you can use an OpenShift AI model server to deploy it as an API.

OpenShift AI offers two options for model serving:

  • Single-model serving - Each model in the project deploys on its own model server. This platform works well for large models or models that need dedicated resources.
  • Multi-model serving - All models in the project deploy on the same model server. This platform is suitable for sharing resources among deployed models. Multi-model serving is the only option offered in the Red Hat Developer Sandbox environment.

For this tutorial, because you are deploying only one model, you can select either serving type. The steps for deploying the fraud detection model depend on the type of model serving platform that you select:

4.2.1. Deploying a model on a single-model server

OpenShift AI single-model servers host only one model. You create a new model server and deploy your model to it.

Prerequisites

  • A user with admin privileges has enabled the single-model serving platform on your OpenShift cluster.

Procedure

  1. In the OpenShift AI dashboard, navigate to the project details page and click the Models tab.

    Note

    Depending on the model serving configuration on your cluster, you might see only one model serving platform option.

  2. In the Single-model serving platform tile, click Select single-model.
  3. In the form, specify the following values:

    1. For Model deployment name, type fraud.
    2. For Serving runtime, select OpenVINO Model Server.
    3. For Model framework (name - version), select onnx-1.
    4. For Deployment mode, select Advanced.
    5. For Existing connection, select My Storage.
    6. Type the path that leads to the version folder that has your model file: models/fraud
    7. Leave the other fields with the default settings.

  4. Click Deploy.

Verification

Notice the loading symbol under the Status section. The symbol changes to a checkmark when the deployment completes successfully.

4.2.2. Deploying a model on a multi-model server

OpenShift AI multi-model servers can host several models at once. You create a new model server and deploy your model to it.

Prerequisites

  • A user with admin privileges has enabled the multi-model serving platform on your OpenShift cluster.

Procedure

  1. In the OpenShift AI dashboard, navigate to the project details page and click the Models tab.

    Note

    Depending on how model serving has been configured on your cluster, you might see only one model serving platform option.

  2. In the Multi-model serving platform tile, click Select multi-model.
  3. In the form, specify the following values:

    1. For Model server name, type a name, for example Model Server.
    2. For Serving runtime, select OpenVINO Model Server.
    3. Leave the other fields with the default settings.

  4. Click Add.
  5. In the Models and model servers list, next to the new model server, click Deploy model.

  6. In the form, specify the following values:

    1. For Model deployment name, type fraud.
    2. For Model framework (name - version), select onnx-1.
    3. For Existing connection, select My Storage.
    4. Type the path that leads to the version folder that has your model file: models/fraud
    5. Leave the other fields with the default settings.

  7. Click Deploy.

Verification

Notice the loading symbol under the Status section. The symbol changes to a checkmark when the deployment completes successfully.

4.3. Testing the model API

After you deploy the model, you can test its API endpoints.

Procedure

  1. In the OpenShift AI dashboard, navigate to the project details page and click the Models tab.
  2. Take note of the model’s Inference endpoint URL. You need this information when you test the model API.

    If the Inference endpoint field has an Internal endpoint details link, click the link to open a text box that shows the URL details, and then take note of the restUrl value.

  3. Return to the JupyterLab environment and try out your new endpoint.

    If you deployed your model with the multi-model serving platform, follow the directions in 3_rest_requests_multi_model.ipynb to try a REST API call and 4_grpc_requests_multi_model.ipynb to try a gRPC API call.

    If you deployed your model with the single-model serving platform, follow the directions in 5_rest_requests_single_model.ipynb to try a REST API call.

(Optional) Running a data science pipeline generated from Python code

Chapter 5. Implementing pipelines

Earlier, you used a notebook to train and save your model. Optionally, you can automate these tasks by using Red Hat OpenShift AI pipelines. Pipelines offer a way to automate the execution of many notebooks and Python code. By using pipelines, you can run long training jobs or retrain your models on a schedule without having to manually run them in a notebook.

To explore the pipeline editor, complete the steps in the following procedures to create your own pipeline.

Alternately, you can skip the following procedures and instead run the 6 Train Save.pipeline file.

5.1.1. Creating a pipeline

You can create a simple pipeline by using the GUI pipeline editor. The pipeline uses the notebook that you used earlier to train a model and then save it to S3 storage.

Prerequisites

  • You configured a pipeline server as described in Enabling data science pipelines.
  • If you configured the pipeline server after you created your workbench, you stopped and then started your workbench.

Procedure

  1. Open your workbench’s JupyterLab environment. If the launcher is not visible, click + to open it.

  2. Click Pipeline Editor.

    You have created a blank pipeline.

  3. Set the default runtime image for when you run your notebook or Python code.

    1. In the pipeline editor, click Open Panel.

    2. Select the Pipeline Properties tab.

    3. In the Pipeline Properties panel, scroll down to Generic Node Defaults and Runtime Image. Set the value to Tensorflow with Cuda and Python 3.11 (UBI 9).

  4. Select FileSave Pipeline.

Verification

  • In the file-browser window, you can see the pipeline file that you created.

5.1.2. Adding nodes to your pipeline

Add some steps, or nodes, in your pipeline for the 1_experiment_train.ipynb and 2_save_model.ipynb notebooks.

Prerequisites

  • You created a pipeline file as described in title

Procedure

  1. From the JupyterLab file-browser panel, drag the 1_experiment_train.ipynb and 2_save_model.ipynb notebooks onto the pipeline canvas.

  2. Click the output port of 1_experiment_train.ipynb and drag a connecting line to the input port of 2_save_model.ipynb.

  3. Save the pipeline.

Verification

  • Your pipeline has two nodes.

Set node properties in your pipeline to specify the training file as a dependency.

Note

If you do not set this file dependency, the file is not included in the node when it runs and the training job fails.

Prerequisites

Procedure

  1. Click the 1_experiment_train.ipynb node.

  2. In the Properties panel, click the Node Properties tab.
  3. Scroll down to the File Dependencies section and then click Add.

  4. Set the value to data/*.csv which has the data to train your model.
  5. Select the Include Subdirectories option.

  6. Save the pipeline.

Verification

  • The training file is a dependency of the first node in your pipeline.

You must set the models/fraud/1/model.onnx file as the output file for both nodes in your pipeline.

Prerequisites

Procedure

  1. Select node 1.
  2. Select the Node Properties tab.
  3. Scroll down to the Output Files section, and then click Add.
  4. Set the value to models/fraud/1/model.onnx.

  5. Repeat steps 2-4 for node 2.
  6. Click Save Pipeline.

Verification

  • In node 1, the notebook creates the models/fraud/1/model.onnx file.
  • In node 2, the notebook uploads the models/fraud/1/model.onnx file to the S3 storage bucket.

5.1.5. Configuring the connection to storage

In node 2, the notebook uploads the model to the S3 storage bucket. You must set the S3 storage bucket keys by using the secret created by the My Storage connection that you set up in Storing data with connections.

You can use this secret in your pipeline nodes without having to save the information in your pipeline code. This is important, for example, if you want to save your pipelines - without any secret keys - to source control.

The name of the secret is aws-connection-my-storage.

Note

If you named your connection something other than My Storage, you can obtain the secret name in the OpenShift AI dashboard by hovering over the help (?) icon in the Connections tab.

The aws-connection-my-storage secret includes the following fields:

  • AWS_ACCESS_KEY_ID
  • AWS_DEFAULT_REGION
  • AWS_S3_BUCKET
  • AWS_S3_ENDPOINT
  • AWS_SECRET_ACCESS_KEY

You must set the secret name and key for each of these fields.

Prerequisites

Procedure

  1. Remove any pre-filled environment variables.

    1. Select node 2, and then select the Node Properties tab.

      Under Additional Properties, note that some environment variables have been pre-filled. The pipeline editor inferred that you need them from the notebook code.

      Because you do not want to save the value in your pipelines, remove all of these environment variables.

    2. Click Remove for each of the pre-filled environment variables.

  2. Add the S3 bucket and keys by using the Kubernetes secret.

    1. Under Kubernetes Secrets, click Add.

    2. Enter the following values and then click Add.

      • Environment Variable: AWS_ACCESS_KEY_ID

  3. Repeat Step 2 for each of the following Kubernetes secrets:

    • Environment Variable: AWS_SECRET_ACCESS_KEY

      • Secret Name: aws-connection-my-storage
      • Secret Key: AWS_SECRET_ACCESS_KEY
    • Environment Variable: AWS_S3_ENDPOINT

      • Secret Name: aws-connection-my-storage
      • Secret Key: AWS_S3_ENDPOINT
    • Environment Variable: AWS_DEFAULT_REGION

      • Secret Name: aws-connection-my-storage
      • Secret Key: AWS_DEFAULT_REGION
    • Environment Variable: AWS_S3_BUCKET

      • Secret Name: aws-connection-my-storage
      • Secret Key: AWS_S3_BUCKET
  4. Select FileSave Pipeline As to save and rename the pipeline. For example, rename it to My Train Save.pipeline.

Verification

  • You set the S3 storage bucket keys by using the secret created by the My Storage connection.

5.1.6. Running your pipeline

Upload the pipeline on your cluster and run it. You can do so directly from the pipeline editor. You can use your own newly created pipeline or the pipeline in the provided 6 Train Save.pipeline file.

Prerequisites

Procedure

  1. Click the play button in the toolbar of the pipeline editor.

  2. Enter a name for your pipeline.
  3. Verify that the Runtime Configuration: is set to Data Science Pipeline.
  4. Click OK.

    Note

    If you see an error message stating that "no runtime configuration for Data Science Pipeline is defined", you might have created your workbench before the pipeline server was available.

    To address this error, you must verify that you configured the pipeline server and then restart the workbench.

    1. Follow these steps in the OpenShift AI dashboard:
    2. Check the status of the pipeline server:

      1. In your Fraud Detection project, click the Pipelines tab.

        • If you see the Configure pipeline server option, follow the steps in Enabling data science pipelines.
        • If you see the Import a pipeline option, the pipeline server is configured. Continue to the next step.
    3. Restart your Fraud Detection workbench:

      1. Click the Workbenches tab.
      2. Click Stop and then click Stop workbench.
      3. After the workbench status is Stopped, click Start.
      4. Wait until the workbench status is Running.
    4. Return to your workbench’s JupyterLab environment and run the pipeline.
  5. In the OpenShift AI dashboard, open your data science project and expand the newly created pipeline.

  6. Click View runs.

  7. Click your run and then view the pipeline run in progress.

Verification

The models/fraud/1/model.onnx file is in your S3 bucket. You can serve the model, as described in Preparing a model for deployment.

Earlier, you created a simple pipeline by using the GUI pipeline editor. You might want to create pipelines by using code that can be version-controlled and shared with others. The Kubeflow pipelines (kfp) SDK provides a Python API for creating pipelines. The SDK is available as a Python package that you can install by using the pip install kfp command. With this package, you can use Python code to create a pipeline and then compile it to YAML format. Then you can import the YAML code into OpenShift AI.

This tutorial does not describe the details of how to use the SDK. Instead, it provides the files for you to view and upload.

  1. Optionally, view the provided Python code in your JupyterLab environment by navigating to the fraud-detection-notebooks project’s pipeline directory. It contains the following files:

    • 7_get_data_train_upload.py is the main pipeline code.
    • build.sh is a script that builds the pipeline and creates the YAML file.

      For your convenience, the output of the build.sh script is provided in the 7_get_data_train_upload.yaml file. The 7_get_data_train_upload.yaml output file is located in the top-level fraud-detection directory.

  2. Right-click the 7_get_data_train_upload.yaml file and then click Download.
  3. Upload the 7_get_data_train_upload.yaml file to OpenShift AI.

    1. In the OpenShift AI dashboard, navigate to your data science project page. Click the Pipelines tab and then click Import pipeline.
    2. Enter values for Pipeline name and Pipeline description.
    3. Click Upload and then select 7_get_data_train_upload.yaml from your local files to upload the pipeline.

    4. Click Import pipeline to import and save the pipeline.

      The pipeline shows in graphic view.

  4. Select ActionsCreate run.
  5. On the Create run page, provide the following values:

    1. For Experiment, leave the value as Default.
    2. For Name, type any name, for example Run 1.
    3. For Pipeline, select the pipeline that you uploaded.

      You can leave the other fields with their default values.

  6. Click Create run to create the run.

    A new run starts immediately.

Chapter 6. Running a distributed workload

You can distribute the training of a machine learning model across many CPUs by using by using Ray or the Training Operator.

6.1. Distributing training jobs

Earlier, you trained the fraud detection model directly in a notebook and then in a pipeline. You can also distribute the training of a machine learning model across many CPUs.

Distributing training is not necessary for a simple model. However, by applying it to the example fraud model, you learn how to train more complex models that require more compute power.

You can try one or both of the following options:

6.1.1. Distributing training jobs with Ray

You can use Ray, a distributed computing framework, to parallelize Python code across many CPUs or GPUs.

In your notebook environment, open the 8_distributed_training.ipynb file and follow the instructions directly in the notebook. The instructions guide you through setting authentication, creating Ray clusters, and working with jobs.

Optionally, if you want to view the Python code for this step, you can find it in the ray-scripts/train_tf_cpu.py file.

For more information about TensorFlow training on Ray, see the Ray TensorFlow guide.

The Training Operator is a tool for scalable distributed training of machine learning (ML) models created with various ML frameworks, such as PyTorch.

You can use the Training Operator to distribute the training of a machine learning model across many hardware resources.

In your notebook environment, open the 9_distributed_training_kfto.ipynb file and follow the instructions directly in the notebook. The instructions guide you through setting authentication, initializing the Training Operator client, and submitting a PyTorchJob.

Optionally, you can view the complete Python code in the kfto-scripts/train_pytorch_cpu.py file.

For more information about PyTorchJob training with the Training Operator, see the Training Operator PyTorchJob guide.

Chapter 7. Conclusion

Congratulations. In this tutorial, you learned how to incorporate data science, artificial intelligence, and machine learning into an OpenShift development workflow.

You used an example fraud detection model and completed the following tasks:

  • Explored a pre-trained fraud detection model by using a Jupyter notebook.
  • Deployed the model by using OpenShift AI model serving.
  • Refined and trained the model by using automated pipelines.
  • Learned how to train the model by using distributed computing frameworks.

Legal Notice

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2026 Red Hat
Back to top