Skip to content

Commit

Permalink
Merge branch 'main' into thinking-0127
Browse files Browse the repository at this point in the history
  • Loading branch information
gericdong authored Jan 27, 2025
2 parents 57deda1 + aed6ebf commit 742d797
Show file tree
Hide file tree
Showing 10 changed files with 449 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@
/generative-ai/vision/use-cases/hey_llm @tushuhei @GoogleCloudPlatform/generative-ai-devrel
/generative-ai/gemini/sample-apps/llamaindex-rag/backend/indexing/ @Lionel-Lim @GoogleCloudPlatform/generative-ai-devrel
/generative-ai/gemini/multimodal-live-api/websocket-demo-app/ @ZackAkil @GoogleCloudPlatform/generative-ai-devrel
/generative-ai/gemini/sample-apps/genai-mlops-tune-and-eval @willisc7 @GoogleCloudPlatform/generative-ai-devrel
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ podcast
podcasts
podfile
podhelper
podman
powerups
praw
prcntg
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ For more Vertex AI samples, please visit the [Vertex AI samples GitHub repositor
<br>
<a href="search/"><code>search/</code></a>
</td>
<td>Use this folder if you're interested in using <a href="https://cloud.google.com/enterprise-search">Vertex AI Search</a>, a Google-managed solution to help you rapidly build search engines for websites and across enterprise data. (Formerly known as Enterprise Search on Generative AI App Builder)</td>
<td>Use this folder if you're interested in using <a href="https://cloud.google.com/enterprise-search">Vertex AI Search</a>, a Google-managed solution to help you rapidly build search engines for websites and across enterprise data. (Formerly known as Enterprise Search on Generative AI App Builder).</td>
</tr>
<tr>
<td>
Expand All @@ -63,7 +63,7 @@ For more Vertex AI samples, please visit the [Vertex AI samples GitHub repositor
<br>
<a href="conversation/"><code>conversation/</code></a>
</td>
<td>Use this folder if you're interested in using <a href="https://cloud.google.com/generative-ai-app-builder">Vertex AI Conversation</a>, a Google-managed solution to help you rapidly build chat bots for websites and across enterprise data. (Formerly known as Chat Apps on Generative AI App Builder)</td>
<td>Use this folder if you're interested in using <a href="https://cloud.google.com/generative-ai-app-builder">Vertex AI Conversation</a>, a Google-managed solution to help you rapidly build chat bots for websites and across enterprise data. (Formerly known as Chat Apps on Generative AI App Builder).</td>
</tr>
<tr>
<td>
Expand Down Expand Up @@ -116,7 +116,7 @@ For more Vertex AI samples, please visit the [Vertex AI samples GitHub repositor
<br>
<a href="RESOURCES.md"><code>RESOURCES.md</code></a>
</td>
<td>Learning resources (e.g. blogs, YouTube playlists) about Generative AI on Google Cloud</td>
<td>Learning resources (e.g. blogs, YouTube playlists) about Generative AI on Google Cloud.</td>
</tr>
</table>
<!-- markdownlint-enable MD033 -->
Expand Down
2 changes: 1 addition & 1 deletion gemini/reasoning-engine/tutorial_langgraph.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"This notebook covers the following steps:\n",
"\n",
"- **Define Tools**: Create custom Python functions to act as tools your AI application can use.\n",
"- **Define Router**: Create custom Python functions to act as tools your AI application can use.\n",
"- **Define Router**: Set up routing logic to control conversation flow and tool selection.\n",
"- **Build a LangGraph Application**: Structure your application using LangGraph, including the Gemini model and custom tools that you define.\n",
"- **Local Testing**: Test your LangGraph application locally to ensure functionality.\n",
"- **Deploying to Vertex AI**: Seamlessly deploy your LangGraph application to Reasoning Engine for scalable execution.\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.11-slim

RUN pip install --no-cache-dir poetry==1.6.1

RUN poetry config virtualenvs.create false

WORKDIR /code

COPY ./pyproject.toml ./README.md ./poetry.lock* ./

COPY ./app ./app

RUN poetry install --no-interaction --no-ansi --no-dev

EXPOSE 8080

CMD ["uvicorn", "app.server:app", "--host", "0.0.0.0", "--port", "8080"]
6 changes: 6 additions & 0 deletions gemini/tuning/genai-mlops-tune-and-eval/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__pycache__
pipeline.json
venv
local/local_outputs
local/pipeline.json
local/venv
83 changes: 83 additions & 0 deletions gemini/tuning/genai-mlops-tune-and-eval/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Gen AI MLOps Tune and Evaluation

Author: [Chris Willis](https://github.com/willisc7)

This tutorial will take you through using Vertex AI Pipelines to automate tuning an LLM and evaluating it against a previously tuned LLM. The example used is an LLM that summarizes a week of glucose values for a diabetes patient.

![Diagram](https://storage.googleapis.com/github-repo/generative-ai/gemini/tuning/mlops-tune-and-eval/diagram.png)

## Optional: Prepare the data

This step is optional because I've already prepared the data in `gs://github-repo/generative-ai/gemini/tuning/mlops-tune-and-eval/patient_1_glucose_examples.jsonl`.

- Create a week of glucose sample data for one patient using the following prompt with Gemini:

```none
Create a CSV with a week's worth of example glucose values for a diabetic patient. The columns should be date, time, patient ID, and glucose value. Each day there should be timestamps for 7am, 8am, 11am, 12pm, 5pm, and 6pm. Most of the glucose values should be between 70 and 100. Some of the glucose values should be 100-150.
```

- Flatten the CSV by doing the following:
1. Open the CSV
2. Press Ctrl + a to select all text
3. Press Alt + Shift + i to go to the end of each line
4. Add a newline character (i.e. \n)
5. Press Delete to squash it all to a single line
- Copy `glucose_examples_template.jsonl` (or create it if it doesn't exist) to `patient_X_glucose_examples.jsonl`
- Copy the flattened CSV and paste it into the patient_X_glucose_examples.jsonl
- Flatten the contents of the patient_X_glucose_examples.jsonl file using a JSON to JSONL converter online

## Setup IAM, Tuning Examples, and Vertex AI Pipelines

- Grant Default Compute Service Account IAM permissions

```sh
PROJECT_NUMBER=$(gcloud projects describe $(gcloud config get-value project) --format="value(projectNumber)")
SERVICE_ACCOUNT="${PROJECT_NUMBER}[email protected]"

gcloud projects add-iam-policy-binding $PROJECT_NUMBER \
--member="serviceAccount:${SERVICE_ACCOUNT}" \
--role="roles/aiplatform.user"
gcloud projects add-iam-policy-binding $PROJECT_NUMBER \
--member="serviceAccount:${SERVICE_ACCOUNT}" \
--role="roles/storage.objectUser"
```

- Enable the Cloud Resource Manager API

```sh
gcloud services enable cloudresourcemanager.googleapis.com
```

- Create the pipeline root bucket

```sh
gsutil mb gs://vertex-ai-pipeline-root-$(date +%Y%m%d)
```

## Run Vertex AI Pipelines

- Install required packages and compile the pipeline

```sh
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
kfp dsl compile --py pipeline.py --output pipeline.json
```

- Edit `pipeline.py` and change the following:

- `project` - change to your project ID

- Edit `submit_pipeline_job.py` and change the following:

- `pipeline_root` - change to the `gs://vertex-ai-pipeline-root-<DATETIME>` bucket you created earlier
- `project` - change to your project ID

- Create the pipeline run

```sh
python submit_pipeline_job.py
```

- For subsequent runs, change `baseline_model_endpoint` in `submit_pipeline_job.py` to a tuned model endpoint you want to compare against (typically the previously trained endpoint)
Loading

0 comments on commit 742d797

Please sign in to comment.