Skip to content

Commit c07420c

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 14e0354 + 3b9313b commit c07420c

File tree

4 files changed

+1429
-0
lines changed

4 files changed

+1429
-0
lines changed

examples/kfto-sft-feast-rag/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Fine-Tuning a RAG Model with Feast on OpenShift AI
2+
3+
This project provides an end-to-end example of how to fine-tune a Retrieval-Augmented Generation (RAG) model on **OpenShift AI**. It uses the **Feast** (Feature Store) for efficient retrieval of context and the **Kubeflow Training SDK** to orchestrate the distributed fine-tuning job on the cluster.
4+
5+
The core idea is to enhance a generator model (like BART) by providing it with relevant documents retrieved from a knowledge base at runtime. This notebook handles the entire lifecycle: ingesting data into the feature store, fine-tuning the RAG model on synthetically generated Q&A pairs, and testing the final artifact.
6+
7+
***
8+
9+
## Prerequisites
10+
11+
Before you begin, ensure you have the following setup:
12+
13+
* An OpenShift cluster with OpenShift AI (RHOAI) 2.20+ installed:
14+
* The `dashboard`, `trainingoperator` and `workbenches` components enabled.
15+
* Workbench with medium size container, 1 NVIDIA GPU / 1 AMD GPU accelerator, and cluster storage of 200GB.
16+
* Sufficient worker nodes for your configuration(s) with NVIDIA GPUs (Ampere-based or newer recommended) or AMD GPUs depending on your environment.
17+
* A dynamic storage provisioner supporting RWX PVC provisioning.
18+
* A standalone Milvus deployment. See example [here](https://github.com/rh-aiservices-bu/llm-on-openshift/tree/main/vector-databases/milvus#deployment).
19+
20+
***
21+
22+
## Workbench Setup
23+
24+
You must run this notebook from within an OpenShift AI Workbench. Follow these steps to create one:
25+
26+
* Access the OpenShift AI dashboard:
27+
* Log in, then go to _Data Science Projects_ and create a project.
28+
* Once the project is created, click on _Create a workbench_.
29+
* Then create a workbench with a preferred name and with the following settings:
30+
* Select the `PyTorch` (or the `ROCm-PyTorch`) workbench image with the recommended version.
31+
* Select the `Medium` as the deployment container size.
32+
* Add one NVIDIA / AMD accelerator (GPU) depending on environment.
33+
* Create a storage that'll be shared between the workbench and the fine-tuning runs.
34+
Make sure it uses a storage class with RWX capability and give it enough capacity according to the size of the model you want to fine-tune.
35+
> [!NOTE]
36+
> You can attach an existing shared storage if you already have one instead.
37+
* Review the storage configuration and click "Create workbench"
38+
* From the "Workbenches" page, click the icon ![Open icon](https://raw.githubusercontent.com/primer/octicons/main/icons/link-external-16.svg) on the workbench you've just created once it becomes ready.
39+
* From the workbench, clone this repository, i.e., `https://github.com/opendatahub-io/distributed-workloads.git`
40+
* Navigate to the `distributed-workloads/examples/kfto-sft-feast-rag` directory and open the `sft_feast_rag_model` notebook
41+
42+
You can now proceed with the instructions from the notebook.
43+
***
44+
45+
## Workflow Overview
46+
47+
The notebook is structured to guide you through the following key stages:
48+
49+
* **feature_repo/feature_store.yaml**
50+
This is the core configuration file for the RAG project's feature store, configuring a Milvus online store on a local provider.
51+
* In order to configure Milvus you should:
52+
- Update `feature_store.yaml` with your Milvus connection details:
53+
- host
54+
- port (default: 19530)
55+
- credentials (if required)
56+
* **Environment Setup**: Installs all necessary Python libraries, including the Kubeflow Training SDK, Feast, and Hugging Face Transformers.
57+
* **Data Ingestion with Feast**:
58+
* Loads the `facebook/wiki_dpr` dataset.
59+
* Chunks the documents into smaller, manageable passages.
60+
* Generates vector embeddings for each passage using a `sentence-transformers` model.
61+
* Initializes a Feast feature store and ingests the passages and their embeddings into the online store.
62+
* **Distributed Training**:
63+
* The core training logic is defined in a `main` function.
64+
* It defines a `RagSequenceForGeneration` model, combining a question-encoder with a generator model.
65+
* It uses a custom `FeastRAGRetriever` to connect the RAG model to the Feast feature store.
66+
* The notebook uses the Kubeflow `TrainingClient` to submit this `main` function as a distributed `PyTorchJob` to the OpenShift cluster.
67+
* **Monitoring**: You can monitor the job's progress directly through its logs and visualize metrics using the integrated TensorBoard dashboard.
68+
* **Inference and Testing**: After the training job is complete, the final, fine-tuned RAG model is loaded from shared storage for testing.
69+
70+
***
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
project: ragproject
2+
provider: local
3+
registry: data/registry.db
4+
online_store:
5+
type: milvus
6+
host: # Insert Milvus route host
7+
username: # Insert Milvus username if required
8+
password: # Insert Milvus password if required
9+
port: 19530
10+
vector_enabled: true
11+
embedding_dim: 384
12+
index_type: FLAT
13+
metric_type: COSINE
14+
offline_store:
15+
type: file
16+
entity_key_serialization_version: 3
17+
auth:
18+
type: no_auth
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from datetime import timedelta
2+
3+
from feast import Entity, FeatureView, Field, FileSource, ValueType
4+
from feast.data_format import ParquetFormat
5+
from feast.types import Array, Float32, String
6+
7+
# Define your entity (primary key for feature lookup)
8+
wiki_passage = Entity(
9+
name="passage_id",
10+
join_keys=["passage_id"],
11+
value_type=ValueType.STRING,
12+
description="Unique ID of a Wikipedia passage",
13+
)
14+
15+
parquet_file_path = "data/wiki_dpr.parquet"
16+
17+
# Define offline source
18+
wiki_dpr_source = FileSource(
19+
name="wiki_dpr_source",
20+
file_format=ParquetFormat(),
21+
path=parquet_file_path,
22+
timestamp_field="event_timestamp",
23+
)
24+
25+
# Define the feature view for the Wikipedia passage content
26+
wiki_passage_feature_view = FeatureView(
27+
name="wiki_passages",
28+
entities=[wiki_passage],
29+
ttl=timedelta(days=1),
30+
schema=[
31+
Field(
32+
name="passage_text",
33+
dtype=String,
34+
description="Content of the Wikipedia passage",
35+
),
36+
Field(
37+
name="embedding",
38+
dtype=Array(Float32),
39+
description="vectors",
40+
vector_index=True,
41+
vector_length=384,
42+
vector_search_metric="COSINE",
43+
),
44+
],
45+
online=True,
46+
source=wiki_dpr_source,
47+
description="Content features of Wikipedia passages",
48+
)

0 commit comments

Comments
 (0)