Vertex AI의 멀티모달 데이터 세트를 사용하면 생성형 AI용 멀티모달 데이터 세트를 만들고, 관리하고, 공유하고, 사용할 수 있습니다. 멀티모달 데이터 세트는 다음과 같은 주요 기능을 제공합니다.
BigQuery, DataFrame 또는 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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI, BigQuery, and Cloud Storage APIs.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI, BigQuery, and Cloud Storage APIs.
- Python용 Vertex AI SDK 설치 및 초기화
- 다음 라이브러리를 가져옵니다.
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 )
-
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가 아닌 기능에는 사용할 수 없습니다.
멀티모달 데이터 세트는 Gemini와 같은 Google 모델에서만 사용할 수 있습니다. 서드 파티 모델과 함께 사용할 수 없습니다.
데이터 세트
Create
개- 기존 BigQuery 테이블 또는 DataFrame에서 생성된 데이터 세트에는 추가 스토리지 비용이 발생하지 않습니다. 데이터의 다른 복사본을 저장하는 대신 논리적 뷰를 사용하기 때문입니다.
- 다른 소스에서 생성된 데이터 세트는 데이터를 새 BigQuery 테이블에 복사하므로 BigQuery의 스토리지 비용이 발생합니다. 예를 들어 활성 논리 스토리지는 GiB당 월 $0.02입니다.
데이터 세트
Assemble
개이 메서드는 모델 요청 형식의 전체 데이터 세트를 포함하는 새 BigQuery 테이블을 생성하므로 BigQuery에 스토리지 비용이 발생합니다. 예를 들어 활성 논리 스토리지는 GiB당 월 $0.02입니다.
이 메서드는 데이터 세트를 한 번 읽으므로 BigQuery에서 쿼리 비용이 발생합니다. 예를 들어 가격 책정의 주문형 컴퓨팅은 TiB당 6.25달러입니다. 데이터 세트 검증 및 리소스 추정
Assess
데이터 세트를 한 번 읽으므로 BigQuery에서 쿼리 비용이 발생합니다. 예를 들어 가격 책정의 주문형 컴퓨팅은 TiB당 6.25달러입니다.
데이터 세트 만들기
다양한 소스에서 멀티모달 dataset
을 만들 수 있습니다.
템플릿 구성 및 첨부
템플릿은 멀티모달 데이터세트를 모델에 전달할 수 있는 형식으로 변환하는 방법을 정의합니다. 조정 또는 일괄 예측 작업을 실행하는 데 필요합니다.
Python용 Vertex AI SDK
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
가 사용되지만 템플릿을 지정하여 기본 동작을 재정의할 수 있습니다.
Python용 Vertex AI SDK
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 모델을 조정할 수 있습니다.
(선택사항) 데이터 세트 검증
데이터 세트를 평가하여 데이터 세트 형식 오류 또는 모델 오류와 같은 오류가 포함되어 있는지 확인합니다.
Python용 Vertex AI SDK
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"
}
}'
(선택사항) 리소스 사용량 추정
데이터 세트를 평가하여 조정 작업의 토큰 수와 청구 가능한 문자 수를 가져옵니다.
Python용 Vertex AI SDK
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"
}
}'
조정 작업 실행
Python용 Vertex AI SDK
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"),
)
자세한 내용은 조정 작업 만들기를 참고하세요.
일괄 예측
멀티모달 데이터 세트를 사용하여 일괄 예측을 가져올 수 있습니다.
(선택사항) 데이터 세트 검증
데이터 세트를 평가하여 데이터 세트 형식 오류 또는 모델 오류와 같은 오류가 포함되어 있는지 확인합니다.
Python용 Vertex AI SDK
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",
}
}'
(선택사항) 리소스 사용량 추정
데이터 세트를 평가하여 작업의 토큰 수를 확인합니다.
Python용 Vertex AI SDK
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"
}
}'
일괄 예측 작업 실행
조립된 출력의 BigQuerytable_id
를 전달하여 멀티모달 데이터 세트를 사용하여 일괄 예측을 실행할 수 있습니다.
Python용 Vertex AI SDK
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에 멀티모달 데이터 세트를 저장하고 쿼리하는 데 요금이 청구됩니다. 특히 다음 작업은 이러한 기본 서비스를 사용합니다.
가격 계산기를 사용하여 예상 사용량을 토대로 예상 비용을 산출합니다.