Skip to main content
  1. Data Science Blog/

Model Tuning with VertexAI

·739 words·4 mins· loading · ·
AI Hardware & Infrastructure AI/ML Models Cloud Computing GCP Cloud Google AI Platform Machine Learning AI Model Optimization Cloud AI Services MLOps

Model Tuning with VertexAI

Tuning Large Language Model with VertexAI
#

Why Model Tuning?
#

Tuning is required when you want the model to learn something niche or specific that deviates from general language patterns.

Goal of Tuning
#

Classification
#

prompt: “Classify the following text into one of the following classes: [business, entertainment].”

Summarization
#

prompt: “Summarize: Jessica: That sounds great! See you in Times Square! Alexander: See you at 10!”

response: “#Person1 and #Person2 agree to meet at Times Square at 10:00 AM.”

Extract QA
#

prompt: “Context: There is evidence that there have been significant changes in Amazon rainforest vegetation over the last 21,000 years through the Last Glacial Maximum (LGM) and subsequent deglaciation. Question: What does LGM stand for?”

response: “Last Glacial Maximum”

Prepare your model tuning dataset
#

Recommended configurations#

The following table shows the recommended configurations for tuning a foundation model by task:

TaskNo. of examples in datasetTrain steps
Classification100+100-500
Summarization100-500+200-1000
Extractive QA100+100-500

For train steps, you can try more than one value to get the best performance on a particular dataset, for example, 100, 200, 500.

Dataset format
#

You can create your own dataset for training. Your dataset must be in JSON Lines (JSONL) format where each line contains a single training example. Content of JSONL file will be like below.

{“input_text”: “question: How many copies of Gears of War 3 were sold ? context: Like its predecessors , the game received widespread critical acclaim from critics . Critics praised its story , voice acting , graphics and visuals , and music , but criticized its lack of innovation . Gears of War 3 sold over 3 million copies and was the second best selling game in the U . S . “, “output_text”: “over 3 million copies”} {“input_text”: “question: How many parishes are there in Louisiana ? context: The U . S . state of Louisiana is divided into 64 parishes ( French : paroisses ) in the same manner that 48 other states of the United States are divided into counties , and Alaska is divided into boroughs . “, “output_text”: “64”}

Creating Dataset
#

Prepare model tuning dataset (train dataset) Maintain consistency with test and production data (same format).

For example, if the examples in your dataset includes a “question:” and a “context:”, production traffic should also be formatted to include a “question:” and a “context:” in the same order as it appears in the dataset examples. If you exclude the context, the model will be confused as to what you are asking, even if the exact question was in an example in the dataset.

Include instructions in examples.
Classify the following text into one of the following classes: [business, entertainment] Text: 5 stocks to buy now

Upload tuning dataset to Cloud Storage (Optional)
#

For the demo use following example. Otherwise bring your dataset in the format below. cloud-samples-data/ai-platform/generative_ai/headline_classification.jsonl

Tuning with VertexAI
#

  • VertexAI -> Language -> Create Tune Model
  • Select the tuning dataset (either from google cloud storage or cloud-samples-data/ai-platform/generative_ai/headline_classification.jsonl)
    • The above dataset contains 25 categorical question answering examples. If you use the sample dataset, the training will take 1-2 hours.
  • Configure the model details & Tune
    • Model name: Enter a name for your tuned model.
    • Base model: Select the foundation model that you want to tune.
    • Train steps: Enter the number of steps to run for model tuning. 1000 steps will take 2-3 hours to complete tuning.
    • Learning rate: Control the step size at which a model updates its weights during training. Default: 3.
    • Working directory: Enter the URI of the bucket to store the tuned model. If don’t have one, you can create a new bucket.

After tuning
#

  • To check the status of your model tuning job, go to the Pipelines page. The status of your pipeline can be found in the Runs section.
  • To view your tuned models in the Google Cloud console, go to the Vertex AI Model Registry page.

Use the tuned model
#

  • To use your tuned models with new prompts, go to the Language page.
  • Click Text prompt.
  • In the Model drop down, select the tuned model that you have created.
  • Copy the sample prompt and submit to view the results.
Multi-choice problem: What is the topic of this text?
- business
- entertainment
- health
- sports
- technology
- politics
Text: What is a large language model (LLM)?
The answer is:

Related

Beyond AI Coding: How AI is Becoming a Knowledge Compiler for Software Engineering
·1192 words·6 mins· loading
Artificial Intelligence Software Architecture Business & Career Industry Applications AI for Software Development Software Engineering Enterprise AI Artificial Intelligence Knowledge Management Business Analytics AI Governance Future of Software Development
Beyond AI Coding: How AI is Becoming a Knowledge Compiler for Software Engineering # For the last …
From Eigenvalues to Singular Value Decomposition — How a Matrix Reveals Its Natural Directions, Strengths, and Hidden Simplicity
·4131 words·20 mins· loading
Mathematics Machine Learning Research & Academia Mathematics Mathematics for Machine Learning Mathematics for AI Applied Mathematics Machine Learning Fundamentals Dimensionality Reduction Machine Learning
From Eigenvalues to Singular Value Decomposition # How a matrix reveals its natural directions, …
One Word, Many Meanings: Understanding Every Kind of Product in Linear Algebra and Quantum Computing
·3877 words·19 mins· loading
Mathematics Machine Learning Research & Academia Mathematics Mathematics for Machine Learning Mathematics for AI Quantum Computing Machine Learning Fundamentals Applied Mathematics Machine Learning
One Word, Many Meanings: Understanding Every Kind of Product in Linear Algebra and Quantum …
Where Does Knowledge Live? Rules, Skills, Tools, and AI Employees — From the Dev Desk to the Operations Floor
·5210 words·25 mins· loading
Artificial Intelligence Developer Tools Business & Career Software Architecture AI Coding Assistants Knowledge Management AI Governance Digital Workforce Cursor IDE Quality Management Organizational Design Agentic AI
Where Does Knowledge Live? # A Knowledge Architecture for AI Workers The problem nobody talks about …
Quantum Measurement, Randomness, and Everyday Technology
·777 words·4 mins· loading
Interdisciplinary Topics Research & Academia Quantum Physics Quantum Mechanics Quantum Computing Interdisciplinary Topics
Quantum Measurement, Randomness, and Everyday Technology # This is Part 2 of Learning Quantum …