Vertex AI의 멀티모달 데이터 세트를 사용하면 생성형 AI를 위한 멀티모달 데이터 세트를 생성, 관리, 공유, 활용할 수 있습니다. 멀티모달 데이터 세트는 다음과 같은 주요 기능을 제공합니다.
BigQuery, DataFrames 또는 Cloud Storage의 JSONL 파일에서 데이터 세트를 로드할 수 있습니다.
데이터 세트를 한 번만 만들면 감독 학습 미세 조정, 일괄 예측 등 다양한 작업 유형에서 재사용할 수 있어, 데이터 중복 및 형식 문제를 방지합니다.
모든 생성형 AI 데이터 세트를 단일 관리 위치에서 보관할 수 있습니다.
스키마와 구조를 검증하고 후속 작업에 필요한 리소스를 산출하여 오류를 사전에 탐지하고 비용을 추정할 수 있습니다.
Vertex AI SDK for Python 또는 REST API를 통해 멀티모달 데이터 세트를 사용할 수 있습니다.
멀티모달 데이터 세트는 Vertex AI의 관리형 데이터 세트 유형 중 하나입니다. 이러한 데이터 세트는 다음과 같은 점에서 다른 유형의 관리형 데이터 세트와 다릅니다.
- 멀티모달 데이터 세트는 텍스트, 이미지, 오디오, 동영상 등 모든 모달리티 데이터를 포함할 수 있습니다. 다른 관리형 데이터 세트 유형은 단일 모달리티만 지원합니다.
- 멀티모달 데이터 세트는 생성형 모델을 활용한 미세 조정, 일괄 예측 등 Vertex AI의 생성형 AI 서비스에만 사용할 수 있습니다. 다른 관리형 데이터 세트 유형은 Vertex AI 예측 모델에서만 사용할 수 있습니다.
- 멀티모달 데이터 세트는
assemble
,assess
와 같은 추가 메서드를 지원하여 데이터 미리보기, 요청 검증, 비용 추정을 수행할 수 있습니다. - 멀티모달 데이터 세트는 BigQuery에 저장되며 대규모 데이터 세트 처리에 최적화되어 있습니다.
시작하기 전에
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI, BigQuery, and Cloud Storage APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI, BigQuery, and Cloud Storage APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. - Vertex AI SDK for Python 설치 및 초기화
- 다음 라이브러리를 가져옵니다.
from google.cloud.aiplatform.preview import datasets # To use related features, you may also need to import some of the following features: from vertexai.preview.tuning import sft from vertexai.batch_prediction import BatchPredictionJob from vertexai.generative_models import Content, Part, Tool, ToolConfig, SafetySetting, GenerationConfig, FunctionDeclaration
Pandas DataFrame에서 만들기
my_dataset = datasets.MultimodalDataset.from_pandas( dataframe=my_dataframe, target_table_id=table_id # optional )
BigQuery DataFrame에서 만들기:
my_dataset = datasets.MultimodalDataset.from_bigframes( dataframe=my_dataframe, target_table_id=table_id # optional )
BigQuery 테이블에서 만들기
my_dataset_from_bigquery = datasets.MultimodalDataset.from_bigquery( bigquery_uri=f"bq://projectId.datasetId.tableId" )
REST API를 사용하여 BigQuery 테이블에서 만들기
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT/locations/LOCATION/datasets" \ -d '{ "display_name": "TestDataset", "metadataSchemaUri": "gs://google-cloud-aiplatform/schema/dataset/metadata/multimodal_1.0.0.yaml", "metadata": { "inputConfig": { "bigquery_source": { "uri": "bq://projectId.datasetId.tableId" } } } }'
Cloud Storage의 JSONL 파일에서 만들기. 다음 예시에서는 JSONL 파일이 이미 Gemini용으로 형식이 지정된 요청을 포함하고 있으므로, 별도의 조합 과정이 필요하지 않습니다.
my_dataset = datasets.MultimodalDataset.from_gemini_request_jsonl( gcs_uri = gcs_uri_of_jsonl_file, )
기존 멀티모달 데이터 세트에서 만들기
# Get the most recently created dataset first_dataset = datasets.MultimodalDataset.list()[0] # Load dataset based on its name same_dataset = datasets.MultimodalDataset(first_dataset.name)
템플릿을 생성합니다. 템플릿 구성 방법에는 두 가지가 있습니다.
construct_single_turn_template
도우미 메서드를 사용합니다.
template_config = datasets.construct_single_turn_template( prompt="This is the image: {image_uris}", response="{labels}", system_instruction='You are a botanical image classifier. Analyze the provided image ' 'and determine the most accurate classification of the flower.' 'These are the only flower categories: [\'daisy\', \'dandelion\', \'roses\', \'sunflowers\', \'tulips\'].' 'Return only one category per image.' )
GeminiExample
에서 템플릿을 수동으로 생성: 이 방법은 다중 턴 대화 등 더 세밀한 제어를 제공합니다. 다음 코드 샘플에는field_mapping
을 지정하는 주석 처리된 선택적 코드도 포함되어 있습니다. 이를 사용하면 데이터 세트의 실제 열 이름과 다른 자리표시자 이름을 사용할 수 있습니다. 예를 들면 다음과 같습니다.
# Define a GeminiExample gemini_example = datasets.GeminiExample( contents=[ Content(role="user", parts=[Part.from_text("This is the image: {image_uris}")]), Content(role="model", parts=[Part.from_text("This is the flower class: {label}.")]), Content(role="user", parts=[Part.from_text("Your response should only contain the class label.")]), Content(role="model", parts=[Part.from_text("{label}")]), # Optional: If you specify a field_mapping, you can use different placeholder values. For example: # Content(role="user", parts=[Part.from_text("This is the image: {uri_placeholder}")]), # Content(role="model", parts=[Part.from_text("This is the flower class: {flower_placeholder}.")]), # Content(role="user", parts=[Part.from_text("Your response should only contain the class label.")]), # Content(role="model", parts=[Part.from_text("{flower_placeholder}")]), ], system_instruction=Content( parts=[ Part.from_text( 'You are a botanical image classifier. Analyze the provided image ' 'and determine the most accurate classification of the flower.' 'These are the only flower categories: [\'daisy\', \'dandelion\', \'roses\', \'sunflowers\', \'tulips\'].' 'Return only one category per image.' ) ] ), ) # construct the template, specifying a map for the placeholder template_config = datasets.GeminiTemplateConfig( gemini_example=gemini_example, # Optional: Map the template placeholders to the column names of your dataset. # Not required if the template placesholders are column names of the dataset. # field_mapping={"uri_placeholder": "image_uris", "flower_placeholder": "labels"}, )
데이터 세트에 연결합니다.
my_dataset.attach_template_config(template_config=template_config)
- BigQuery 테이블의 URI입니다. BigQuery 테이블에서 생성된 데이터 세트의 경우, 이는 소스
bigquery_uri
입니다. JSONL 또는 DataFrame 같은 다른 소스에서 생성된 데이터 세트의 경우, 이는 데이터가 복사된 BigQuery 테이블입니다. gemini_template_config
.멀티모달 데이터 세트는 생성형 AI 기능에서만 사용할 수 있습니다. AutoML 학습 및 커스텀 학습과 같은 비생성형 AI 기능에서는 사용할 수 없습니다.
멀티모달 데이터 세트는 Google 모델(Gemini 등)에서만 사용할 수 있습니다. 서드 파티 모델에서는 사용할 수 없습니다.
데이터 세트
Create
작업- 기존 BigQuery 테이블 또는 DataFrame에서 생성된 데이터 세트는 추가 스토리지 비용이 발생하지 않습니다. 데이터 복사본을 저장하는 대신 논리적 뷰를 사용하기 때문입니다.
- 다른 소스에서 생성된 데이터 세트는 데이터를 새 BigQuery 테이블에 복사하므로 BigQuery 스토리지 비용이 발생합니다. 예를 들어 활성 논리 스토리지는 GiB당 월 $0.02입니다.
데이터 세트
Assemble
작업이 메서드는 데이터 세트 전체를 모델 요청 형식으로 담은 새 BigQuery 테이블을 생성하므로 BigQuery 스토리지 비용이 발생합니다. 예를 들어 활성 논리 스토리지는 GiB당 월 $0.02입니다.
이 메서드는 데이터 세트를 한 번 읽으므로 BigQuery 쿼리 비용도 발생합니다. 예를 들어 주문형 컴퓨팅의 가격 책정은 TiB당 $6.25입니다. 데이터 세트 검증 및 리소스 추정
Assess
데이터 세트를 한 번 읽으므로 BigQuery 쿼리 비용이 발생합니다. 예를 들어 주문형 컴퓨팅의 가격 책정은 TiB당 $6.25입니다.
데이터 세트 만들기
다음과 같은 다양한 소스에서 멀티모달 dataset
를 만들 수 있습니다.
템플릿 생성 및 연결
템플릿은 멀티모달 데이터 세트를 모델에 전달할 수 있는 형식으로 변환하는 방법을 정의합니다. 이는 조정 또는 일괄 예측 작업을 실행할 때 필요합니다.
Vertex AI SDK for Python
REST
patch
메서드를 호출하고 metadata
필드를 다음으로 업데이트합니다.
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d $'{
"metadata": {
"input_config": {
"bigquery_source": {
"uri": "bq://projectId.datasetId.tableId"
}
},
"gemini_template_config_source": {
"gemini_template_config": {
"gemini_example": {
"contents": [
{
"role": "user",
"parts": [
{
"text": "This is the image: {image_uris}"
}
]
},
{
"role": "model",
"parts": [
{
"text": "response"
}
]
}
]
"systemInstruction": {
"parts": [
{
"text": "You are a botanical image classifier."
}
]
}
}
}
}
}
}' \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID?updateMask=metadata"
(선택사항) 데이터 세트 조합
assemble
메서드는 템플릿을 적용해 데이터 세트를 변환하고 출력 결과를 새 BigQuery 테이블에 저장합니다. 이를 통해 데이터가 모델에 전달되기 전에 미리보기를 할 수 있습니다.
기본적으로 데이터 세트에 연결된 template_config
가 사용되지만, 다른 템플릿을 지정하여 기본 동작을 재정의할 수 있습니다.
Vertex AI SDK for Python
table_id, assembly = my_dataset.assemble(template_config=template_config)
# Inspect the results
assembly.head()
REST
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID:assemble" \
-d '{}'
예를 들어 멀티모달 데이터 세트에 다음 데이터가 있다고 가정해보세요.
행 | image_uris | 라벨 |
---|---|---|
1 | gs://cloud-samples-data/ai-platform/flowers/daisy/1396526833_fb867165be_n.jpg | daisy |
그런 다음 assemble
메서드가 table_id
라는 이름의 새 BigQuery 테이블을 만들고, 각 행에는 요청 본문이 포함됩니다. 예를 들면 다음과 같습니다.
{
"contents": [
{
"parts": [
{
"text": "This is the image: "
},
{
"fileData": {
"fileUri": "gs://cloud-samples-data/ai-platform/flowers/daisy/1396526833_fb867165be_n.jpg",
"mimeType": "image/jpeg"
}
}
],
"role": "user"
},
{
"parts": [
{
"text": "daisy"
}
],
"role": "model"
}
],
"systemInstruction": {
"parts": [
{
"text": "You are a botanical image classifier. Analyze the provided image and determine the most accurate classification of the flower.These are the only flower categories: ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips'].Return only one category per image."
}
]
}
}
모델 조정
멀티모달 데이터 세트를 사용하여 Gemini 모델을 조정할 수 있습니다.
(선택사항) 데이터 세트 검증
데이터 세트를 평가하여 데이터 세트 형식 오류 또는 모델 오류 같은 문제가 있는지 확인합니다.
Vertex AI SDK for Python
assess_tuning_validity()
를 호출합니다. 기본적으로 데이터 세트에 연결된 template_config
가 사용되지만, 다른 템플릿을 지정하여 기본 동작을 재정의할 수 있습니다.
# Attach template
my_dataset.attach_template_config(template_config=template_config)
# Validation for tuning
validation = my_dataset.assess_tuning_validity(
model_name="gemini-2.0-flash-001",
dataset_usage="SFT_TRAINING"
)
# Inspect validation result
validation.errors
REST
assess
메서드를 호출하고 TuningValidationAssessmentConfig
를 제공합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID:assess" \
-d '{
"tuningValidationAssessmentConfig": {
"modelName": "projects/PROJECT_ID/locations/LOCATION/models/gemini-2.0-flash-001",
"datasetUsage": "SFT_TRAINING"
}
}'
(선택사항) 리소스 사용량 추정
데이터 세트를 평가하여 조정 작업의 토큰 수와 청구 가능한 문자 수를 가져옵니다.
Vertex AI SDK for Python
assess_tuning_resources()
를 호출합니다.
# Resource estimation for tuning.
tuning_resources = my_dataset.assess_tuning_resources(
model_name="gemini-2.0-flash-001"
)
print(tuning_resources)
# For example, TuningResourceUsageAssessmentResult(token_count=362688, billable_character_count=122000)
REST
assess
메서드를 호출하고 TuningResourceUsageAssessmentConfig
를 제공합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID:assess" \
-d '{
"tuningResourceUsageAssessmentConfig": {
"modelName": "projects/PROJECT_ID/locations/LOCATION/models/gemini-2.0-flash-001"
}
}'
조정 작업 실행
Vertex AI SDK for Python
from vertexai.tuning import sft
sft_tuning_job = sft.train(
source_model="gemini-2.0-flash-001",
# Pass the Vertex Multimodal Datasets directly
train_dataset=my_multimodal_dataset,
validation_dataset=my_multimodal_validation_dataset,
)
Google Gen AI SDK
from google import genai
from google.genai.types import HttpOptions, CreateTuningJobConfig
client = genai.Client(http_options=HttpOptions(api_version="v1"))
tuning_job = client.tunings.tune(
base_model="gemini-2.0-flash-001",
# Pass the resource name of the Vertex Multimodal Dataset, not the dataset object
training_dataset={
"vertex_dataset_resource": my_multimodal_dataset.resource_name
},
# Optional
config=CreateTuningJobConfig(
tuned_model_display_name="Example tuning job"),
)
자세한 내용은 조정 작업 만들기를 참조하세요.
일괄 예측
멀티모달 데이터 세트를 사용하여 일괄 예측을 수행할 수 있습니다.
(선택사항) 데이터 세트 검증
데이터 세트를 평가하여 데이터 세트 형식 오류 또는 모델 오류 같은 문제가 있는지 확인합니다.
Vertex AI SDK for Python
assess_batch_prediction_validity()
를 호출합니다. 기본적으로 데이터 세트에 연결된 template_config
가 사용되지만, 다른 템플릿을 지정하여 기본 동작을 재정의할 수 있습니다.
# Attach template
my_dataset.attach_template_config(template_config=template_config)
# Validation for batch prediction
validation = my_dataset.assess_batch_prediction_validity(
model_name="gemini-2.0-flash-001",
dataset_usage="SFT_TRAINING"
)
# Inspect validation result
validation.errors
REST
assess
메서드를 호출하고 batchPredictionValidationAssessmentConfig
를 제공합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID:assess" \
-d '{
"batchPredictionValidationAssessmentConfig": {
"modelName": "projects/PROJECT_ID/locations/LOCATION/models/gemini-2.0-flash-001",
}
}'
(선택사항) 리소스 사용량 추정
데이터 세트를 평가하여 작업에 필요한 토큰 수를 가져올 수 있습니다.
Vertex AI SDK for Python
assess_batch_prediction_resources()
를 호출합니다.
batch_prediction_resources = my_dataset.assess_batch_prediction_resources(
model_name="gemini-2.0-flash"
)
print(batch_prediction_resources)
# For example, BatchPredictionResourceUsageAssessmentResult(token_count=362688, audio_token_count=122000)
REST
assess
메서드를 호출하고 batchPredictionResourceUsageAssessmentConfig
를 제공합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
"https://LOCATION-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID:assess" \
-d '{
"batchPredictionResourceUsageAssessmentConfig": {
"modelName": "projects/PROJECT_ID/locations/LOCATION/models/gemini-2.0-flash-001"
}
}'
일괄 예측 작업 실행
멀티모달 데이터 세트를 사용해서 조합된 출력의 BigQuery table_id
를 전달하여 일괄 예측을 수행할 수 있습니다.
Vertex AI SDK for Python
from vertexai.batch_prediction import BatchPredictionJob
# Dataset needs to have an attached template_config to batch prediction
my_dataset.attach_template_config(template_config=template_config)
# assemble dataset to get assembly table id
assembly_table_id, _ = my_dataset.assemble()
batch_prediction_job = BatchPredictionJob.submit(
source_model="gemini-2.0-flash-001",
input_dataset=assembly_table_id,
)
Google Gen AI SDK
from google import genai
client = genai.Client(http_options=HttpOptions(api_version="v1"))
# Attach template_config and assemble dataset
my_dataset.attach_template_config(template_config=template_config)
assembly_table_id, _ = my_dataset.assemble()
job = client.batches.create(
model="gemini-2.0-flash-001",
src=assembly_table_id,
)
자세한 내용은 일괄 예측 작업 요청을 참조하세요.
제한사항
가격 책정
모델을 조정하거나 일괄 예측 작업을 실행하면 생성형 AI 사용량과 BigQuery에서 데이터 세트를 쿼리하는 요금이 청구됩니다.
멀티모달 데이터 세트를 생성, 조합, 평가하면 BigQuery에서 멀티모달 데이터 세트를 저장하고 쿼리하는 요금이 청구됩니다. 구체적으로 다음 작업이 이러한 기본 서비스를 사용합니다.
가격 계산기를 사용하여 예상 사용량을 토대로 예상 비용을 산출합니다.