Skip to content

Commit 880a31f

Browse files
BenjaminKazemicopybara-github
authored andcommitted
feat: GenAI SDK client(multimodal) - Support Assess Batch Prediction Resources for the multimodal datasets.
PiperOrigin-RevId: 868355650
1 parent 12f5aa5 commit 880a31f

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed

tests/unit/vertexai/genai/replays/test_assess_multimodal_dataset.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,28 @@ def test_assess_tuning_validity(client):
8989
assert isinstance(response, types.TuningValidationAssessmentResult)
9090

9191

92+
def test_assess_batch_prediction_resources(client):
93+
response = client.datasets.assess_batch_prediction_resources(
94+
dataset_name=DATASET,
95+
model_name="gemini-2.5-flash-001",
96+
template_config=types.GeminiTemplateConfig(
97+
gemini_example=types.GeminiExample(
98+
contents=[
99+
{
100+
"role": "user",
101+
"parts": [{"text": "What is the capital of {name}?"}],
102+
},
103+
{
104+
"role": "model",
105+
"parts": [{"text": "{capital}"}],
106+
},
107+
],
108+
),
109+
),
110+
)
111+
assert isinstance(response, types.BatchPredictionResourceUsageAssessmentResult)
112+
113+
92114
pytestmark = pytest_helper.setup(
93115
file=__file__,
94116
globals_for_file=globals(),
@@ -161,3 +183,26 @@ async def test_assess_tuning_validity_async(client):
161183
),
162184
)
163185
assert isinstance(response, types.TuningValidationAssessmentResult)
186+
187+
188+
@pytest.mark.asyncio
189+
async def test_assess_batch_prediction_resources_async(client):
190+
response = await client.aio.datasets.assess_batch_prediction_resources(
191+
dataset_name=DATASET,
192+
model_name="gemini-2.5-flash-001",
193+
template_config=types.GeminiTemplateConfig(
194+
gemini_example=types.GeminiExample(
195+
contents=[
196+
{
197+
"role": "user",
198+
"parts": [{"text": "What is the capital of {name}?"}],
199+
},
200+
{
201+
"role": "model",
202+
"parts": [{"text": "{capital}"}],
203+
},
204+
],
205+
),
206+
),
207+
)
208+
assert isinstance(response, types.BatchPredictionResourceUsageAssessmentResult)

vertexai/_genai/datasets.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,70 @@ def assess_tuning_validity(
11161116
response["tuningValidationAssessmentResult"],
11171117
)
11181118

1119+
def assess_batch_prediction_resources(
1120+
self,
1121+
*,
1122+
dataset_name: str,
1123+
model_name: str,
1124+
template_config: Optional[types.GeminiTemplateConfigOrDict] = None,
1125+
config: Optional[types.AssessDatasetConfigOrDict] = None,
1126+
) -> types.BatchPredictionResourceUsageAssessmentResult:
1127+
"""Assess the batch prediction resources required for a given model.
1128+
1129+
Args:
1130+
dataset_name:
1131+
Required. The name of the dataset to assess the batch prediction
1132+
resources.
1133+
model_name:
1134+
Required. The name of the model to assess the batch prediction
1135+
resources.
1136+
template_config:
1137+
Optional. The template config used to assemble the dataset
1138+
before assessing the batch prediction resources. If not provided,
1139+
the template config attached to the dataset will be used. Required
1140+
if no template config is attached to the dataset.
1141+
template_config:
1142+
Optional. The template config used to assemble the dataset
1143+
before assessing the batch prediction resources. If not provided, the
1144+
template config attached to the dataset will be used. Required
1145+
if no template config is attached to the dataset.
1146+
config:
1147+
Optional. A configuration for assessing the batch prediction
1148+
resources. If not provided, the default configuration will be
1149+
used.
1150+
1151+
Returns:
1152+
A types.BatchPredictionResourceUsageAssessmentResult object
1153+
representing the batch prediction resource usage assessment result.
1154+
It contains the following keys:
1155+
- token_count: The number of tokens in the dataset.
1156+
- audio_token_count: The number of audio tokens in the dataset.
1157+
1158+
"""
1159+
if isinstance(config, dict):
1160+
config = types.AssessDatasetConfig(**config)
1161+
elif not config:
1162+
config = types.AssessDatasetConfig()
1163+
1164+
operation = self._assess_multimodal_dataset(
1165+
name=dataset_name,
1166+
batch_prediction_resource_usage_assessment_config=types.BatchPredictionResourceUsageAssessmentConfig(
1167+
model_name=model_name,
1168+
),
1169+
gemini_request_read_config=types.GeminiRequestReadConfig(
1170+
template_config=template_config,
1171+
),
1172+
config=config,
1173+
)
1174+
response = self._wait_for_operation(
1175+
operation=operation,
1176+
timeout_seconds=config.timeout,
1177+
)
1178+
result = response["batchPredictionResourceUsageAssessmentResult"]
1179+
return _datasets_utils.create_from_response(
1180+
types.BatchPredictionResourceUsageAssessmentResult, result
1181+
)
1182+
11191183

11201184
class AsyncDatasets(_api_module.BaseModule):
11211185

@@ -1999,3 +2063,67 @@ async def assess_tuning_validity(
19992063
types.TuningValidationAssessmentResult,
20002064
response["tuningValidationAssessmentResult"],
20012065
)
2066+
2067+
async def assess_batch_prediction_resources(
2068+
self,
2069+
*,
2070+
dataset_name: str,
2071+
model_name: str,
2072+
template_config: Optional[types.GeminiTemplateConfigOrDict] = None,
2073+
config: Optional[types.AssessDatasetConfigOrDict] = None,
2074+
) -> types.BatchPredictionResourceUsageAssessmentResult:
2075+
"""Assess the batch prediction resources required for a given model.
2076+
2077+
Args:
2078+
dataset_name:
2079+
Required. The name of the dataset to assess the batch prediction
2080+
resources.
2081+
model_name:
2082+
Required. The name of the model to assess the batch prediction
2083+
resources.
2084+
template_config:
2085+
Optional. The template config used to assemble the dataset
2086+
before assessing the batch prediction resources. If not provided,
2087+
the template config attached to the dataset will be used. Required
2088+
if no template config is attached to the dataset.
2089+
template_config:
2090+
Optional. The template config used to assemble the dataset
2091+
before assessing the batch prediction resources. If not provided, the
2092+
template config attached to the dataset will be used. Required
2093+
if no template config is attached to the dataset.
2094+
config:
2095+
Optional. A configuration for assessing the batch prediction
2096+
resources. If not provided, the default configuration will be
2097+
used.
2098+
2099+
Returns:
2100+
A types.BatchPredictionResourceUsageAssessmentResult object
2101+
representing the batch prediction resource usage assessment result.
2102+
It contains the following keys:
2103+
- token_count: The number of tokens in the dataset.
2104+
- audio_token_count: The number of audio tokens in the dataset.
2105+
2106+
"""
2107+
if isinstance(config, dict):
2108+
config = types.AssessDatasetConfig(**config)
2109+
elif not config:
2110+
config = types.AssessDatasetConfig()
2111+
2112+
operation = await self._assess_multimodal_dataset(
2113+
name=dataset_name,
2114+
batch_prediction_resource_usage_assessment_config=types.BatchPredictionResourceUsageAssessmentConfig(
2115+
model_name=model_name,
2116+
),
2117+
gemini_request_read_config=types.GeminiRequestReadConfig(
2118+
template_config=template_config,
2119+
),
2120+
config=config,
2121+
)
2122+
response = await self._wait_for_operation(
2123+
operation=operation,
2124+
timeout_seconds=config.timeout,
2125+
)
2126+
result = response["batchPredictionResourceUsageAssessmentResult"]
2127+
return _datasets_utils.create_from_response(
2128+
types.BatchPredictionResourceUsageAssessmentResult, result
2129+
)

0 commit comments

Comments
 (0)