Skip to content

Commit 8b4708c

Browse files
feat: add vertex ai skills to repo (#4454)
1 parent f3dd6cb commit 8b4708c

12 files changed

Lines changed: 936 additions & 1 deletion

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ To get started using Vertex AI, you must have a Google Cloud project.
4545
│ │ ├── model_garden
4646
│ │ ├── ...
4747
├── community-content - Sample code and tutorials contributed by the community
48-
48+
├─- skills - Skills related to Vertex AI interaction
4949
```
5050
## Examples
5151

skills/vertex-tuning/SKILL.md

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
---
2+
name: vertex-tuning
3+
description: >
4+
Vertex AI Model Tuning. Use when you need to fine-tune models
5+
using Vertex AI's infrastructure.
6+
---
7+
8+
# Vertex AI Model Tuning
9+
10+
## Overview
11+
12+
This skill provides procedural knowledge for fine-tuning Large Language Models
13+
(LLMs) using Vertex AI's tuning service. It covers the entire lifecycle from
14+
environment setup and data preparation to job configuration, monitoring, and
15+
deployment.
16+
17+
## Workflow Decision Tree
18+
19+
1. **Environment Check**: Has the environment (Auth, APIs, IAM, Venv) been
20+
initialized?
21+
22+
- **No** → Go to [Phase 0: Environment & IAM Setup](#phase-0).
23+
- **Yes** → Proceed.
24+
25+
2. **Dataset Status**: Is the dataset ready in JSONL format and uploaded to
26+
GCS?
27+
28+
- **No** → Go to [Phase 1: Dataset Preparation & Upload](#phase-1).
29+
- **Yes** → Proceed.
30+
31+
3. **Configuration**: Have the target model and hyperparameters been decided?
32+
33+
- **No** → Go to [Phase 2: Recommendations & Configuration](#phase-2).
34+
- **Yes** → Proceed.
35+
36+
4. **Job Status**: Has the tuning job been submitted?
37+
38+
- **No** → Go to
39+
[Phase 3: Tuning Job Execution](#phase-3-tuning-job-execution).
40+
- **Yes** → Proceed.
41+
42+
5. **Job Completion**: Is the tuning job complete?
43+
44+
- **No** → Go to [Phase 4: Monitoring](#phase-4-monitoring).
45+
- **Yes** → Proceed.
46+
47+
6. **Deployment**: Has the tuned model been deployed to an endpoint?
48+
49+
- **No** → Go to [Phase 5: Model Deployment](#phase-5-model-deployment).
50+
- **Yes** → Task Complete.
51+
52+
--------------------------------------------------------------------------------
53+
54+
## Phase 0: Environment & IAM Setup {#phase-0}
55+
56+
Ensure the foundational environment is ready before proceeding.
57+
58+
### 0.1 Authentication & Project Context
59+
60+
- Check if `gcloud` CLI is installed. If it is not installed, prompt the user
61+
for permission to install it before proceeding.
62+
- Verify `gcloud auth list`. If not authenticated, run `gcloud auth login`.
63+
- Ensure `project` and `location` are known. Use `gcloud config get project`
64+
to retrieve the current project (and `gcloud config get compute/region` for
65+
region).
66+
- **CRITICAL: Ask for Confirmation.** You must prompt the user to confirm the
67+
retrieved project and region before proceeding, in case they want to switch
68+
to a different one.
69+
70+
### 0.2 Enable APIs
71+
72+
Ensure `aiplatform.googleapis.com` and `storage.googleapis.com` are enabled.
73+
`bash gcloud services enable aiplatform.googleapis.com storage.googleapis.com
74+
--project=YOUR_PROJECT`
75+
76+
### 0.3 IAM Permissions
77+
78+
Verify the following identities have the required roles.
79+
80+
- **Vertex AI Service Agent**:
81+
`service-PROJECT_NUMBER@gcp-sa-aiplatform.iam.gserviceaccount.com`
82+
- **Managed OSS Fine Tuning Service Agent**:
83+
`service-PROJECT_NUMBER@gcp-sa-vertex-moss-ft.iam.gserviceaccount.com`
84+
- **User Identity**: The account running the commands.
85+
86+
### 0.4 Virtual Environment
87+
88+
Create and use a virtual environment named `tuning_agent_venv` in the home
89+
directory. Install dependencies from `references/requirements.txt`. `bash
90+
python3 -m venv ~/tuning_agent_venv source ~/tuning_agent_venv/bin/activate pip
91+
install -r references/requirements.txt`
92+
93+
--------------------------------------------------------------------------------
94+
95+
## Phase 1: Dataset Preparation & Upload {#phase-1}
96+
97+
Vertex AI requires valid JSONL format in GCS.
98+
99+
### 1.0 Dataset Discovery & Confirmation
100+
101+
- **Ask the User First:** Ask the user if they already have a dataset they
102+
want to use.
103+
- **Auto-Discovery:** If the user does not have a dataset, search the
104+
authenticated project's GCS buckets to find if any existing file has a
105+
reasonable dataset that can do the job the user prompted initially.
106+
- **CRITICAL: Ask for Confirmation.** Do not proceed with dataset preparation
107+
or upload until you present the found or provided dataset to the user and
108+
they confirm the dataset to use.
109+
110+
### 1.1 Formatting & Validation
111+
112+
- **Conversion**: If data is in CSV or JSON, use `vertex-tuning/scripts/prepare_dataset.py`
113+
to convert.
114+
- **Validation Split Confirmation**: If the user only provides a training
115+
dataset, **you must prompt the user** to seek permission to split the
116+
training dataset 80/20 to form a validation dataset (using
117+
`--validation_split 0.2`). If they agree, proceed with the split. If they
118+
decline, just use the training dataset without a validation dataset.
119+
- **Validation**: If data is already in JSONL, validate it before uploading:
120+
`bash python3 vertex-tuning/scripts/prepare_dataset.py
121+
\ --input my_data.jsonl \ --format messages \ --validate_only`
122+
- Refer to [Data Preparation Guide](references/data_prep.md) for required
123+
schemas.
124+
125+
### 1.2 Upload
126+
127+
Upload formatted `.jsonl` files to GCS using a unique directory (e.g., with a
128+
datetime timestamp) to avoid overwriting outputs from different runs.
129+
130+
```bash
131+
gcloud storage cp dataset.jsonl gs://YOUR_BUCKET/tuning_agent_job_<datetime>/dataset.jsonl
132+
```
133+
134+
--------------------------------------------------------------------------------
135+
136+
## Phase 2: Recommendations & Configuration {#phase-2}
137+
138+
Help the user choose the best model and parameters. **Always seek user
139+
confirmation before submitting the job.**
140+
141+
### 2.1 Model Selection
142+
143+
- If the user does not specify a model in their prompt, recommend a model
144+
based on the user's prompt by referencing the
145+
[Models Catalog](references/models.md).
146+
- **Prompt for Confirmation:** Present the recommended model to the user and
147+
ask for their confirmation.
148+
149+
### 2.2 Hyperparameters
150+
151+
- If the user does not specify hyperparameters, recommend `tuning_mode`,
152+
`epochs`, `learning_rate`, and `adapter_size` based on the
153+
[Tuning Guide](references/tuning_guide.md) and model-specific baselines in
154+
the [Models Catalog](references/models.md).
155+
- **Prompt for Confirmation:** Present the recommended hyperparameter
156+
configuration to the user and ask for their approval before proceeding to
157+
job submission.
158+
159+
--------------------------------------------------------------------------------
160+
161+
## Phase 3: Tuning Job Execution
162+
163+
Submit the job using `scripts/tune_model.py`.
164+
165+
```bash
166+
python3 scripts/tune_model.py \
167+
--project YOUR_PROJECT \
168+
--location YOUR_LOCATION \
169+
--bucket YOUR_STAGING_BUCKET \
170+
--base_model BASE_MODEL_ID \
171+
--train_dataset gs://YOUR_BUCKET/tuning_agent_job_<datetime>/dataset.jsonl \
172+
--output_uri gs://YOUR_BUCKET/tuning_agent_job_<datetime>/output \
173+
--epochs EPOCHS \
174+
--learning_rate LR \
175+
--tuning_mode MODE
176+
```
177+
178+
--------------------------------------------------------------------------------
179+
180+
## Phase 4: Monitoring
181+
182+
Monitor the job via the Cloud Console link provided in the script output or by
183+
polling the job status.
184+
185+
--------------------------------------------------------------------------------
186+
187+
## Phase 5: Model Deployment
188+
189+
Once the job is `SUCCEEDED`, deploy the model using `scripts/deploy_model.py`.
190+
191+
```bash
192+
python3 vertex_tuning/scripts/deploy_model.py \
193+
--project YOUR_PROJECT \
194+
--location YOUR_LOCATION \
195+
--artifacts_uri gs://YOUR_BUCKET/tuning_agent_job_<datetime>/output/postprocess/node-0/checkpoints/final \
196+
--machine_type MACHINE_TYPE \
197+
--accelerator_type ACCELERATOR_TYPE \
198+
--accelerator_count COUNT
199+
```
200+
201+
Refer to [Models Catalog](references/models.md) for hardware recommendations.
202+
203+
--------------------------------------------------------------------------------
204+
205+
## Resources
206+
207+
- [Data Preparation Guide](references/data_prep.md)
208+
- [Models Catalog](references/models.md)
209+
- [Tuning Guide](references/tuning_guide.md)
210+
- `scripts/prepare_dataset.py`: Data conversion & validation.
211+
- `scripts/tune_model.py`: Job submission.
212+
- `scripts/deploy_model.py`: Model deployment.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Data Formatting for Vertex AI Model Tuning
2+
3+
Vertex AI Model Tuning requires training data in **JSON Lines (JSONL)**
4+
format. Each line must be a valid JSON object representing a single training
5+
example.
6+
7+
## Supported Formats
8+
9+
### 1. Conversational (Messages) Format
10+
Recommended for chat-based models (Llama 3 Chat, Gemma IT, etc.).
11+
12+
```json
13+
{
14+
"messages": [
15+
{"role": "system", "content": "You are a helpful assistant."},
16+
{"role": "user", "content": "What is the capital of France?"},
17+
{"role": "assistant", "content": "The capital of France is Paris."}
18+
]
19+
}
20+
```
21+
22+
### 2. Instruction (Prompt/Completion) Format
23+
Suitable for base models or simple completion tasks.
24+
25+
```json
26+
{
27+
"prompt": "Summarize the following text: [TEXT]",
28+
"completion": "[SUMMARY]"
29+
}
30+
```
31+
32+
## Dataset Requirements
33+
34+
- **File Type**: `.jsonl`
35+
- **Location**: Must be uploaded to a Google Cloud Storage (GCS) bucket.
36+
- **Validation Split**: If provided, it must be less than 5,000 rows AND less than 25% of the training dataset size.
37+
- **Encoding**: UTF-8.
38+
39+
## Sequence Length Limitations
40+
41+
Each model has a maximum sequence length (context window) supported during
42+
tuning. Examples exceeding this limit may be truncated.
43+
44+
Please refer to the [official documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/models/open-model-tuning)
45+
for the latest maximum sequence length limits for specific models and tuning
46+
modes.
47+
48+
*Note: As a rule of thumb, 1 token is approximately 4 characters of
49+
English text.*
50+
51+
## Bucket Considerations
52+
53+
If the user has not provided a bucket name create one using the following
54+
command with the location same as the tuning job location.
55+
56+
```bash
57+
gcloud storage buckets create gs://vertex-tuning-agent --location=BUCKET_LOCATION
58+
```
59+
60+
## Preparation Workflow
61+
62+
1. **Collect Data**: Gather your raw data in CSV, JSONL, Parquet, or from
63+
Hugging Face.
64+
2. **Apply Template**: Format each example using a template appropriate for
65+
your target model (e.g., Llama 3 prompt template).
66+
3. **Convert to JSONL**: Save the formatted examples to a `.jsonl` file.
67+
4. **Upload to GCS**: Use `gcloud storage cp` to move the file to your bucket.
68+
69+
```bash
70+
gcloud storage cp dataset.jsonl gs://your-bucket/path/dataset.jsonl
71+
```
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Data Preparation for Vertex AI Model Tuning
2+
3+
Vertex AI Model Tuning requires training data in **JSON Lines (JSONL)** format
4+
stored in Google Cloud Storage (GCS).
5+
6+
## Supported JSONL Formats
7+
8+
### 1. Conversational (Messages) Format
9+
Recommended for chat-based models (Llama 3.1/3.2/3.3 Chat, Gemma 3 IT, etc.).
10+
11+
```json
12+
{
13+
"messages": [
14+
{"role": "system", "content": "You are a helpful assistant."},
15+
{"role": "user", "content": "What is the capital of France?"},
16+
{"role": "assistant", "content": "The capital of France is Paris."}
17+
]
18+
}
19+
```
20+
21+
### 2. Instruction (Prompt/Completion) Format
22+
Suitable for base models or simple completion tasks.
23+
24+
```json
25+
{
26+
"prompt": "Summarize the following text: [TEXT]",
27+
"completion": "[SUMMARY]"
28+
}
29+
```
30+
31+
## Dataset Requirements
32+
33+
- **File Type**: Must be `.jsonl`.
34+
- **Encoding**: UTF-8.
35+
- **Location**: Must be in a GCS bucket (e.g., `gs://my-bucket/train.jsonl`).
36+
- **Validation Split**: A separate validation file is optional but recommended. It must be no more than 25% of the training dataset size.
37+
38+
## Bucket Considerations
39+
40+
If a bucket does not exist, create one in the same region as your tuning job:
41+
42+
```bash
43+
gcloud storage buckets create gs://YOUR_BUCKET_NAME --location=YOUR_LOCATION
44+
```
45+
46+
## Formatting Best Practices
47+
48+
1. **Quality over Quantity**: 100 high-quality examples often outperform 1,000 noisy ones.
49+
2. **Consistency**: Use consistent formatting for system prompts and instruction styles.
50+
3. **No Empty Values**: Ensure every example has a valid prompt/user message and completion/assistant response. Use the [preparation script](/cloud/ai/platform/modelgarden/agent_skills/vertex-tuning/scripts/prepare_dataset.py) to validate this.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Starting Model and Tuning Method Recommendation
2+
3+
## Available Models
4+
5+
- Gemma 3 27B IT (google/gemma-3-27b-it)
6+
- Llama 3.1 8B (meta/llama3_1@llama-3.1-8b)
7+
- Llama 3.1 8B Instruct (meta/llama3_1@llama-3.1-8b-instruct)
8+
- Llama 3.2 1B Instruct (meta/llama3-2@llama-3.2-1b-instruct)
9+
- Llama 3.2 3B Instruct (meta/llama3-2@llama-3.2-3b-instruct)
10+
- Llama 3.3 70B Instruct (meta/llama3-3@llama-3.3-70b-instruct)
11+
- Qwen 3 32B (qwen/qwen3@qwen3-32b)
12+
- Llama 4 Scout 17B 16E Instruct (meta/llama4@llama-4-scout-17b-16e-instruct)
13+
14+
## Guidelines to follow for model Selection
15+
16+
Different families are suitable for different types of tasks.
17+
18+
- Qwen is a good choice for code generation or math based tasks.
19+
- Gemma is a good choice for chat based tasks.
20+
- Llama is an okay choice for other tasks.
21+
- Only one model in the list Llama 3.1 8B is not an instruct model, this is
22+
best suited for continuation tasks.
23+
24+
Gauge the complexity of the task by examining samples from the
25+
dataset.
26+
27+
Tasks that are easier should be handled by smaller models, while more complex
28+
tasks should be handled by larger models.
29+
30+
For example, a task that requires simple question answering can be handles by
31+
the 1B or 3B models, while a task that requires complex reasoning should be
32+
handled by either the Qwen 3 32B, Gemma 3 27B or Llama 3.3 70B model.
33+
Any intermediate tasks can be handled by the 8B or 17B models.
34+
35+
Another aspect to consider is if the dataset is multi turn or needs tool calling
36+
capabilities prefer the strongest models. Qwen 3 32B > Gemma 3 27B >
37+
Llama 3.3 70B unless the user explicitly requests otherwise.

0 commit comments

Comments
 (0)