diff --git a/content/patterns/mlops-fraud-detection/_index.adoc b/content/patterns/mlops-fraud-detection/_index.adoc index d708f5f8f..c6e6f895a 100644 --- a/content/patterns/mlops-fraud-detection/_index.adoc +++ b/content/patterns/mlops-fraud-detection/_index.adoc @@ -1,12 +1,13 @@ --- title: MLOps Fraud Detection -date: 2023-11-12 +date: 2025-11-20 tier: sandbox -summary: This pattern demonstrates how Red Hat OpenShift Data Science and MLFlow can be used together to build an end-to-end MLOps platform. It demonstrates this using a credit card fraud detection use case. +summary: This pattern demonstrates how Red Hat OpenShift AI can be used to build an end-to-end MLOps platform. It demonstrates this using a credit card fraud detection use case. rh_products: - Red Hat OpenShift Container Platform -- Red Hat OpenShift Data Science -- Red Hat OpenShift Data Foundation +- Red Hat OpenShift AI +partners: +- IBM Fusion industries: - financial services aliases: /mlops-fraud-detection/ @@ -17,11 +18,6 @@ links: arch: https://www.redhat.com/architect/portfolio/architecturedetail?ppid=6 bugs: https://github.com/validatedpatterns/mlops-fraud-detection/issues feedback: https://docs.google.com/forms/d/e/1FAIpQLScI76b6tD1WyPu2-d_9CCVDr3Fu5jYERthqLKJDUGwqBg7Vcg/viewform -ci: mfd -contributor: - name: Arslan Khan - contact: mailto:arskhan@redhat.com - git: https://github.com/arslankhanali --- :toc: :imagesdir: /images @@ -34,4 +30,4 @@ include::modules/mfd-architecture.adoc[leveloffset=+1] [id="next-steps_mfd-index"] == Next steps -* link:mfd-getting-started[Deploy the management hub] using Helm. +* link:mfd-getting-started[Install this pattern.] diff --git a/content/patterns/mlops-fraud-detection/mfd-explore-this-pattern.adoc b/content/patterns/mlops-fraud-detection/mfd-explore-this-pattern.adoc new file mode 100644 index 000000000..9db638c61 --- /dev/null +++ b/content/patterns/mlops-fraud-detection/mfd-explore-this-pattern.adoc @@ -0,0 +1,77 @@ +--- +title: Explore this pattern +weight: 20 +aliases: /mlops-fraud-detection/mfd-explore-this-pattern/ +--- +:toc: +:imagesdir: /images +:_content-type: ASSEMBLY +include::modules/comm-attributes.adoc[] + +[id="rhoai-components"] +== {rhoai} components + +Most components installed as part of this pattern are available in the {rhoai} (RHOAI) console. To navigate to this page, click the {rhoai} link in the application launcher of the OpenShift console. + +.The RHOAI Link +image::/images/mlops-fraud-detection/mfd-rhoai-link.png[] + +[id="kubeflow-pipeline"] +=== Kubeflow pipeline + +The pattern installation automatically creates and runs a Kubeflow pipeline to build and train the fraud detection model. To view pipeline details in the RHOAI console, select the *Pipelines* tab. + +.The pipelines tab +image::/images/mlops-fraud-detection/mfd-pipelines-tab.png[] + +This tab displays the fraud-detection pipeline deployed as part of this pattern. To view the specific run that trained the initial model, select the *Runs* tab and then select the *job-run* item. + +.The runs tab +image::/images/mlops-fraud-detection/mfd-runs-tab.png[] + +The *Runs* page displays a diagram of the pipeline, which includes the following three major steps: + +* Obtaining the training data. +* Training the model. +* Uploading the model to MinIO. + +You can view the logs of any stage, such as the training stage, to monitor accuracy changes for each model training epoch. + +.The job-run pipeline details +image::/images/mlops-fraud-detection/mfd-job-run-detail.png[] + +[NOTE] +==== +The source code for this pipeline run is available in the pattern repository at link:https://github.com/validatedpatterns/mlops-fraud-detection/blob/main/src/kubeflow-pipelines/small-model/train_upload_model.yaml[src/kubeflow-pipelines/small-model]. +==== + +[id="kserve-model-serving"] +=== Kserve model serving + +You can view the model deployment in the Model Deployments tab of the RHOAI console. + +.The model deployment +image::/images/mlops-fraud-detection/mfd-model-deployments.png[] + +[id="inferencing-application"] +== Inferencing application + +The pattern installs a simple Gradio front end to communicate with the fraud detection model. To access the application, click the link in the application launcher of the OpenShift console. + +.The inferencing application link +image::/images/mlops-fraud-detection/mfd-inf-app-link.png[] + +You can manually configure transaction details in the form. The application includes two examples: a fraudulent transaction and a non-fraudulent transaction. + +.Using the fraud example +image::/images/mlops-fraud-detection/mfd-inferencing-app.png[] + +[IMPORTANT] +==== +Due to the non-deterministic nature of the training process, the model might not always identify these transactions accurately. +==== + +[NOTE] +==== +The source code for the inferencing application is available in the pattern repository at link:https://github.com/validatedpatterns/mlops-fraud-detection/blob/main/src/inferencing-app/app.py[src/inferencing-app]. +==== diff --git a/content/patterns/mlops-fraud-detection/mfd-getting-started.adoc b/content/patterns/mlops-fraud-detection/mfd-getting-started.adoc index a33ecc2f9..3e894cf3f 100644 --- a/content/patterns/mlops-fraud-detection/mfd-getting-started.adoc +++ b/content/patterns/mlops-fraud-detection/mfd-getting-started.adoc @@ -11,4 +11,4 @@ include::modules/mfd-deploying-mfd-pattern.adoc[leveloffset=1] = Next Steps -* link:../mfd-running-the-demo[Run the demo]. +* link:../mfd-explore-this-pattern[Explore this pattern]. diff --git a/content/patterns/mlops-fraud-detection/mfd-ibm-fusion.adoc b/content/patterns/mlops-fraud-detection/mfd-ibm-fusion.adoc new file mode 100644 index 000000000..cb6b07fae --- /dev/null +++ b/content/patterns/mlops-fraud-detection/mfd-ibm-fusion.adoc @@ -0,0 +1,12 @@ +--- +title: Fraud Detection on IBM Fusion +weight: 30 +aliases: /mlops-fraud-detection/mfd-ibm-fustion/ +--- +:toc: +:imagesdir: /images +:_content-type: ASSEMBLY + +== MLOPS credit card fraud detection on IBM Fusion + +This pattern is deployed with IBM Fusion. For more details, see the link:https://community.ibm.com/community/user/blogs/saif-adil/2026/01/08/deploying-ai-driven-credit-card-fraud-detection[IBM Community Post]. diff --git a/content/patterns/mlops-fraud-detection/mfd-running-the-demo.adoc b/content/patterns/mlops-fraud-detection/mfd-running-the-demo.adoc deleted file mode 100644 index c44bd0480..000000000 --- a/content/patterns/mlops-fraud-detection/mfd-running-the-demo.adoc +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: Running the Fraud Detection Demo -weight: 10 -aliases: /mlops-fraud-detection/mfd-running-the-demo/ ---- -:toc: -:imagesdir: /images -:_content-type: ASSEMBLY -include::modules/comm-attributes.adoc[] - -include::modules/mfd-using-mfd-demo.adoc[leveloffset=1] - -= Next Steps - -link:https://groups.google.com/g/validatedpatterns[Help & Feedback] -link:https://github.com/validatedpatterns/mlops-fraud-detection/issues[Report Bugs] \ No newline at end of file diff --git a/modules/mfd-about-mlops-fraud-detection.adoc b/modules/mfd-about-mlops-fraud-detection.adoc index 448b821a4..9ed8b2f12 100644 --- a/modules/mfd-about-mlops-fraud-detection.adoc +++ b/modules/mfd-about-mlops-fraud-detection.adoc @@ -2,13 +2,15 @@ :imagesdir: ../../images [id="about-mlops-fraud-detection-pattern"] -= About the MLOps Fraud Detection += About the MLOps Fraud Detection Pattern + +NOTE: This pattern has been reworked for a modern RHOAI experience. To see the original pattern, check out the link:https://github.com/validatedpatterns/mlops-fraud-detection/tree/legacy[legacy branch]. MLOps Credit Card Fraud Detection use case:: -* Build and train models in RHODS to detect credit card fraud -* Track and store those models with MLFlow -* Serve a model stored in MLFlow using RHODS Model Serving (or MLFlow serving) -* Deploy a model application in OpenShift that runs sends data to the served model and displays the prediction +* Build, train and serve models in RHOAI to detect credit card fraud +* Use Kubeflow pipelines in RHOAI for declarative model building workflows +* Store models in S3-compatible storage with Minio +* Serve ML models using Kserve on RHOAI + Background:: @@ -21,8 +23,9 @@ The model is built on a Credit Card Fraud Detection model, which predicts if a c == Technology Highlights: * Event-Driven Architecture -* Data Science on OpenShift -* Model registry using MLFlow +* Data Science on Red Hat OpenShift AI +* Declarative MLOps pipeline with Kubeflow +* ML model serving with Kserve == Solution Discussion @@ -33,7 +36,7 @@ This architecture pattern demonstrates four strengths: * *Cost Efficiency*: By automating the detection process, AI reduces the need for extensive manual review of transactions, which can be time-consuming and costly. * *Flexibility and Agility*: An cloud native architecture that supports the use of microservices, containers, and serverless computing, allowing for more flexible and agile development and deployment of AI models. This means faster iteration and deployment of new fraud detection algorithms. -== Demo Video - -.Overview of the solution for credit card fraud detection -video::9Yx_XUOMMYI[youtube] +[INFO] +==== +This pattern is based on the OpenShift AI tutorial for link:https://docs.redhat.com/en/documentation/red_hat_openshift_ai_cloud_service/1/html-single/openshift_ai_tutorial_-_fraud_detection_example/index[fraud detection]. +==== diff --git a/modules/mfd-architecture.adoc b/modules/mfd-architecture.adoc index 54bf20bbe..c22947fd5 100644 --- a/modules/mfd-architecture.adoc +++ b/modules/mfd-architecture.adoc @@ -6,13 +6,11 @@ Description of each component: -* *Data Set*: The data set contains the data used for training and evaluating the model we will build in this demo. -* *RHODS Notebook*: We will build and train the model using a Jupyter Notebook running in RHODS. -* *MLFlow Experiment tracking*: We use MLFlow to track the parameters and metrics (such as accuracy, loss, etc) of a model training run. These runs can be grouped under different "experiments", making it easy to keep track of the runs. -* *MLFlow Model registry*: As we track the experiment we also store the trained model through MLFlow so we can easily version it and assign a stage to it (for example Staging, Production, Archive). -* *S3 (ODF)*: This is where the models are stored and what the MLFlow model registry interfaces with. We use ODF (OpenShift Data Foundation) according to the MLFlow guide, but it can be replaced with another solution. -* *RHODS Model Serving*: We recommend using RHODS Model Serving for serving the model. It's based on ModelMesh and allows us to easily send requests to an endpoint for getting predictions. -* *Application interface*: This is the interface used to run predictions with the model. In our case, we will build a visual interface (interactive app) using Gradio and let it load the model from the MLFlow model registry. +* *Data Set*: The dataset contains the data used for training and evaluating the model built in this tutorial. The dataset is sourced from the link:https://github.com/rh-aiservices-bu/fraud-detection/tree/main/data[github.com/rh-aiservices-bu/fraud-detection] +* *Kubeflow Pipeline*: The Kubeflow pipeline builds, trains, and uploads the model. The source for this pipeline is in the pattern repository at link:https://github.com/validatedpatterns/mlops-fraud-detection/blob/main/src/kubeflow-pipelines/small-model/train_upload_model.yaml[src/kubeflow-pipelines/small-model/train_upload_model.yaml]. Upon pattern installation, the system automatically runs this pipeline once to train the initial model. +* *S3 (Minio)*: Minio provides storage for the models and serves as the storage interface for the Kubeflow pipeline. While this pattern uses Minio for parity with the source tutorial, any S3-compatible storage solution is compatible. +* *Kserve Model Serving*: The pattern uses the Kserve model serving capabilities in Red Hat OpenShift AI (RHOAI) to serve models with an OpenVINO model server. +* *Application interface*: This interface runs predictions with the model. This pattern includes a visual interface (interactive application) built with Gradio that loads the model from Minio. //figure 1 originally .Overview of the solution reference architecture @@ -39,15 +37,3 @@ Red Hat® OpenShift® AI is an AI-focused portfolio that provides tools to train https://www.redhat.com/en/technologies/cloud-computing/openshift/try-it[Red Hat OpenShift GitOps]:: A declarative application continuous delivery tool for Kubernetes based on the ArgoCD project. Application definitions, configurations, and environments are declarative and version controlled in Git. It can automatically push the desired application state into a cluster, quickly find out if the application state is in sync with the desired state, and manage applications in multi-cluster environments. - -https://www.redhat.com/en/technologies/jboss-middleware/amq[Red Hat AMQ Streams]:: -Red Hat AMQ streams is a massively scalable, distributed, and high-performance data streaming platform based on the Apache Kafka project. It offers a distributed backbone that allows microservices and other applications to share data with high throughput and low latency. Red Hat AMQ Streams is available in the Red Hat AMQ product. - -Hashicorp Vault (community):: -Provides a secure centralized store for dynamic infrastructure and applications across clusters, including over low-trust networks between clouds and data centers. - -MLFlow Model Registry (community):: -A centralized model store, set of APIs, and UI, to collaboratively manage the full lifecycle of an MLflow Model. It provides model lineage (which MLflow experiment and run produced the model), model versioning, model aliasing, model tagging, and annotations. - -Other:: -This solution also uses a variety of _observability tools_ including the Prometheus monitoring and Grafana dashboard that are integrated with OpenShift as well as components of the Observatorium meta-project which includes Thanos and the Loki API. \ No newline at end of file diff --git a/modules/mfd-deploying-mfd-pattern.adoc b/modules/mfd-deploying-mfd-pattern.adoc index 08d8d1eea..783a82daf 100644 --- a/modules/mfd-deploying-mfd-pattern.adoc +++ b/modules/mfd-deploying-mfd-pattern.adoc @@ -6,26 +6,17 @@ == Prerequisites -. An OpenShift cluster (Go to https://console.redhat.com/openshift/create[the OpenShift console]). Cluster must have a dynamic StorageClass to provision PersistentVolumes. +. An OpenShift cluster (Go to https://console.redhat.com/openshift/create[the OpenShift console]). Cluster must have a dynamic StorageClass to provision PersistentVolumes. // See also link:../../mlops-fraud-detection/cluster-sizing[sizing your cluster]. . A GitHub account (and a token for it with repositories permissions, to read from and write to your forks) For installation tooling dependencies, see link:https://validatedpatterns.io/learn/quickstart/[Patterns quick start]. -The use of this pattern depends on having a Red Hat OpenShift cluster. In this version of the validated pattern -there is no dedicated Hub / Edge cluster for the *MLOps Fraud Detection* pattern. This single node pattern can be extend as a managed cluster(s) to a central hub. -// See link:../../mlops-fraud-detection/ideas-for-customization[ideas for customization.] - If you do not have a running Red Hat OpenShift cluster you can start one on a public or private cloud by using link:https://console.redhat.com/openshift/create[Red Hat's cloud service]. -[id="utilities"] -= Utilities - -A number of utilities have been built by the validated patterns team to lower the barrier to entry for using the community or Red Hat Validated Patterns. To use these utilities you will need to export some environment variables for your cloud provider: - -[id="preparation"] -= Preparation +[id="installation"] += Installing this pattern . Fork the link:https://github.com/validatedpatterns/mlops-fraud-detection[mlops-fraud-detection] repo on GitHub. It is necessary to fork because your fork will be updated as part of the GitOps and DevOps processes. . Clone the forked copy of this repository. @@ -35,68 +26,6 @@ A number of utilities have been built by the validated patterns team to lower th git clone git@github.com:/mlops-fraud-detection.git ---- -. Create a local copy of the Helm secrets values file that can safely include credentials -+ -*DO NOT COMMIT THIS FILE* -+ -You do not want to push credentials to GitHub. -+ -[source,terminal] ----- -cp values-secret-mlops-fraud-detection.yaml.template ~/values-secret.yaml -vi ~/values-secret.yaml ----- - -*values-secret.yaml example* - -[source,yaml] ----- -secrets: -//Nothing at time of writing. ----- - -When you edit the file you can make changes to the various DB and Grafana passwords if you wish. - -. Customize the `values-global.yaml` for your deployment -+ -[source,terminal] ----- -git checkout -b my-branch -vi values-global.yaml ----- - -*Replace instances of PROVIDE_ with your specific configuration* - -[source,yaml] ----- -global: - pattern: mlops-fraud-detection - hubClusterDomain: "AUTO" # this is for test only This value is automatically fetched when Invoking against a cluster - - options: - useCSV: false - syncPolicy: Automatic - installPlanApproval: Automatic - -main: - clusterGroupName: hub ----- - -[source,terminal] ----- - git add values-global.yaml - git commit values-global.yaml - git push origin my-branch ----- - -. You can deploy the pattern using the link:/infrastructure/using-validated-pattern-operator/[validated pattern operator]. If you do use the operator then skip to Validating the Environment below. -. Preview the changes that will be made to the Helm charts. -+ -[source,terminal] ----- -./pattern.sh make show ----- - . Login to your cluster using oc login or exporting the KUBECONFIG + [source,terminal] @@ -111,82 +40,11 @@ oc login export KUBECONFIG=~/my-ocp-env/auth/kubeconfig ---- -[id="check-the-values-files-before-deployment-getting-started"] -== Check the values files before deployment - -You can run a check before deployment to make sure that you have the required variables to deploy the -MLOps Fraud Detection Validated Pattern. - -You can run `make predeploy` to check your values. This will allow you to review your values and changed them in -the case there are typos or old values. The values files that should be reviewed prior to deploying the -MLOps Fraud Detection Validated Pattern are: - -|=== -| Values File | Description - -| values-secret.yaml / values-secret-mlops-fraud-detection.yaml -| This is the values file that will include the rhpam and fhir-psql-db sections with all database et al secrets - -| values-global.yaml -| File that is used to contain all the global values used by Helm -|=== - -= Deploy - -. Apply the changes to your cluster +. Install this pattern on your cluster + [source,terminal] ---- ./pattern.sh make install ---- -+ -If the install fails and you go back over the instructions and see what was missed and change it, then run `make update` to continue the installation. - -. This takes some time. Especially for the OpenShift Data Foundation operator components to install and synchronize. The `make install` provides some progress updates during the install. It can take up to twenty minutes. Compare your `make install` run progress with the following video showing a successful install. - -. Check that the operators have been installed in the UI. -.. To verify, in the OpenShift Container Platform web console, navigate to *Operators → Installed Operators* page. - .. Check that the Operator is installed in the `openshift-operators` namespace and its status is `Succeeded`. - -[id="using-openshift-gitops-to-check-on-application-progress-getting-started"] -== Using OpenShift GitOps to check on Application progress - -You can also check on the progress using OpenShift GitOps to check on the various applications deployed. - -. Obtain the ArgoCD URLs and passwords. -+ -The URLs and login credentials for ArgoCD change depending on the pattern -name and the site names they control. Follow the instructions below to find -them, however you choose to deploy the pattern. -+ -Display the fully qualified domain names, and matching login credentials, for -all ArgoCD instances: -+ -[source,terminal] ----- -ARGO_CMD=`oc get secrets -A -o jsonpath='{range .items[*]}{"oc get -n "}{.metadata.namespace}{" routes; oc -n "}{.metadata.namespace}{" extract secrets/"}{.metadata.name}{" --to=-\\n"}{end}' | grep gitops-cluster` -CMD=`echo $ARGO_CMD | sed 's|- oc|-;oc|g'` -eval $CMD ----- -+ -The result should look something like: -+ -[,text] ----- -NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD -hub-gitops-server hub-gitops-server-mlops-fraud-detection-hub.apps.mfd-cluster.aws.validatedpatterns.com hub-gitops-server https passthrough/Redirect None -# admin.password -xsyYU6eSWtwniEk1X3jL0c2TGfQgVpDH -NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD -cluster cluster-openshift-gitops.apps.mfd-cluster.aws.validatedpatterns.com cluster 8080 reencrypt/Allow None -kam kam-openshift-gitops.apps.mfd-cluster.aws.validatedpatterns.com kam 8443 passthrough/None None -openshift-gitops-server openshift-gitops-server-openshift-gitops.apps.mfd-cluster.aws.validatedpatterns.com openshift-gitops-server https passthrough/Redirect None -# admin.password -FdGgWHsBYkeqOczE3PuRpU1jLn7C2fD6 ----- -+ -The most important ArgoCD instance to examine at this point is `mlops-fraud-detection-hub`. This is where all the applications for the pattern can be tracked. - -. Check all applications are synchronised. There are thirteen different ArgoCD "applications" deployed as part of this pattern. - +The installation will conclude when all the ArgoCD applications installed as part of this pattern are healthy and synced. diff --git a/static/images/mlops-fraud-detection/mfd-inf-app-link.png b/static/images/mlops-fraud-detection/mfd-inf-app-link.png new file mode 100644 index 000000000..d0a29d670 Binary files /dev/null and b/static/images/mlops-fraud-detection/mfd-inf-app-link.png differ diff --git a/static/images/mlops-fraud-detection/mfd-inferencing-app.png b/static/images/mlops-fraud-detection/mfd-inferencing-app.png new file mode 100644 index 000000000..dfe35250d Binary files /dev/null and b/static/images/mlops-fraud-detection/mfd-inferencing-app.png differ diff --git a/static/images/mlops-fraud-detection/mfd-job-run-detail.png b/static/images/mlops-fraud-detection/mfd-job-run-detail.png new file mode 100644 index 000000000..feaffd0ad Binary files /dev/null and b/static/images/mlops-fraud-detection/mfd-job-run-detail.png differ diff --git a/static/images/mlops-fraud-detection/mfd-model-deployments.png b/static/images/mlops-fraud-detection/mfd-model-deployments.png new file mode 100644 index 000000000..59535026b Binary files /dev/null and b/static/images/mlops-fraud-detection/mfd-model-deployments.png differ diff --git a/static/images/mlops-fraud-detection/mfd-pipelines-tab.png b/static/images/mlops-fraud-detection/mfd-pipelines-tab.png new file mode 100644 index 000000000..3ced5a6f1 Binary files /dev/null and b/static/images/mlops-fraud-detection/mfd-pipelines-tab.png differ diff --git a/static/images/mlops-fraud-detection/mfd-rhoai-link.png b/static/images/mlops-fraud-detection/mfd-rhoai-link.png new file mode 100644 index 000000000..addd561f7 Binary files /dev/null and b/static/images/mlops-fraud-detection/mfd-rhoai-link.png differ diff --git a/static/images/mlops-fraud-detection/mfd-runs-tab.png b/static/images/mlops-fraud-detection/mfd-runs-tab.png new file mode 100644 index 000000000..f48b7d2e8 Binary files /dev/null and b/static/images/mlops-fraud-detection/mfd-runs-tab.png differ