google-genai 1.45.0__py3-none-any.whl → 1.47.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/genai/_api_client.py +47 -17
- google/genai/_extra_utils.py +4 -0
- google/genai/_live_converters.py +66 -61
- google/genai/_tokens_converters.py +47 -47
- google/genai/_transformers.py +10 -1
- google/genai/batches.py +57 -57
- google/genai/caches.py +58 -58
- google/genai/client.py +4 -1
- google/genai/live.py +28 -18
- google/genai/models.py +129 -74
- google/genai/tunings.py +269 -124
- google/genai/types.py +1425 -981
- google/genai/version.py +1 -1
- {google_genai-1.45.0.dist-info → google_genai-1.47.0.dist-info}/METADATA +168 -157
- {google_genai-1.45.0.dist-info → google_genai-1.47.0.dist-info}/RECORD +18 -18
- {google_genai-1.45.0.dist-info → google_genai-1.47.0.dist-info}/WHEEL +0 -0
- {google_genai-1.45.0.dist-info → google_genai-1.47.0.dist-info}/licenses/LICENSE +0 -0
- {google_genai-1.45.0.dist-info → google_genai-1.47.0.dist-info}/top_level.txt +0 -0
google/genai/tunings.py
CHANGED
|
@@ -35,6 +35,7 @@ logger = logging.getLogger('google_genai.tunings')
|
|
|
35
35
|
def _CancelTuningJobParameters_to_mldev(
|
|
36
36
|
from_object: Union[dict[str, Any], object],
|
|
37
37
|
parent_object: Optional[dict[str, Any]] = None,
|
|
38
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
38
39
|
) -> dict[str, Any]:
|
|
39
40
|
to_object: dict[str, Any] = {}
|
|
40
41
|
if getv(from_object, ['name']) is not None:
|
|
@@ -46,6 +47,7 @@ def _CancelTuningJobParameters_to_mldev(
|
|
|
46
47
|
def _CancelTuningJobParameters_to_vertex(
|
|
47
48
|
from_object: Union[dict[str, Any], object],
|
|
48
49
|
parent_object: Optional[dict[str, Any]] = None,
|
|
50
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
49
51
|
) -> dict[str, Any]:
|
|
50
52
|
to_object: dict[str, Any] = {}
|
|
51
53
|
if getv(from_object, ['name']) is not None:
|
|
@@ -57,6 +59,7 @@ def _CancelTuningJobParameters_to_vertex(
|
|
|
57
59
|
def _CreateTuningJobConfig_to_mldev(
|
|
58
60
|
from_object: Union[dict[str, Any], object],
|
|
59
61
|
parent_object: Optional[dict[str, Any]] = None,
|
|
62
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
60
63
|
) -> dict[str, Any]:
|
|
61
64
|
to_object: dict[str, Any] = {}
|
|
62
65
|
|
|
@@ -125,23 +128,41 @@ def _CreateTuningJobConfig_to_mldev(
|
|
|
125
128
|
if getv(from_object, ['labels']) is not None:
|
|
126
129
|
raise ValueError('labels parameter is not supported in Gemini API.')
|
|
127
130
|
|
|
131
|
+
if getv(from_object, ['beta']) is not None:
|
|
132
|
+
raise ValueError('beta parameter is not supported in Gemini API.')
|
|
133
|
+
|
|
128
134
|
return to_object
|
|
129
135
|
|
|
130
136
|
|
|
131
137
|
def _CreateTuningJobConfig_to_vertex(
|
|
132
138
|
from_object: Union[dict[str, Any], object],
|
|
133
139
|
parent_object: Optional[dict[str, Any]] = None,
|
|
140
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
134
141
|
) -> dict[str, Any]:
|
|
135
142
|
to_object: dict[str, Any] = {}
|
|
136
143
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
discriminator = getv(root_object, ['config', 'method'])
|
|
145
|
+
if discriminator is None:
|
|
146
|
+
discriminator = 'SUPERVISED_FINE_TUNING'
|
|
147
|
+
if discriminator == 'SUPERVISED_FINE_TUNING':
|
|
148
|
+
if getv(from_object, ['validation_dataset']) is not None:
|
|
149
|
+
setv(
|
|
150
|
+
parent_object,
|
|
151
|
+
['supervisedTuningSpec'],
|
|
152
|
+
_TuningValidationDataset_to_vertex(
|
|
153
|
+
getv(from_object, ['validation_dataset']), to_object, root_object
|
|
154
|
+
),
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
elif discriminator == 'PREFERENCE_TUNING':
|
|
158
|
+
if getv(from_object, ['validation_dataset']) is not None:
|
|
159
|
+
setv(
|
|
160
|
+
parent_object,
|
|
161
|
+
['preferenceOptimizationSpec'],
|
|
162
|
+
_TuningValidationDataset_to_vertex(
|
|
163
|
+
getv(from_object, ['validation_dataset']), to_object, root_object
|
|
164
|
+
),
|
|
165
|
+
)
|
|
145
166
|
|
|
146
167
|
if getv(from_object, ['tuned_model_display_name']) is not None:
|
|
147
168
|
setv(
|
|
@@ -153,33 +174,85 @@ def _CreateTuningJobConfig_to_vertex(
|
|
|
153
174
|
if getv(from_object, ['description']) is not None:
|
|
154
175
|
setv(parent_object, ['description'], getv(from_object, ['description']))
|
|
155
176
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
177
|
+
discriminator = getv(root_object, ['config', 'method'])
|
|
178
|
+
if discriminator is None:
|
|
179
|
+
discriminator = 'SUPERVISED_FINE_TUNING'
|
|
180
|
+
if discriminator == 'SUPERVISED_FINE_TUNING':
|
|
181
|
+
if getv(from_object, ['epoch_count']) is not None:
|
|
182
|
+
setv(
|
|
183
|
+
parent_object,
|
|
184
|
+
['supervisedTuningSpec', 'hyperParameters', 'epochCount'],
|
|
185
|
+
getv(from_object, ['epoch_count']),
|
|
186
|
+
)
|
|
162
187
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
188
|
+
elif discriminator == 'PREFERENCE_TUNING':
|
|
189
|
+
if getv(from_object, ['epoch_count']) is not None:
|
|
190
|
+
setv(
|
|
191
|
+
parent_object,
|
|
192
|
+
['preferenceOptimizationSpec', 'hyperParameters', 'epochCount'],
|
|
193
|
+
getv(from_object, ['epoch_count']),
|
|
194
|
+
)
|
|
169
195
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
196
|
+
discriminator = getv(root_object, ['config', 'method'])
|
|
197
|
+
if discriminator is None:
|
|
198
|
+
discriminator = 'SUPERVISED_FINE_TUNING'
|
|
199
|
+
if discriminator == 'SUPERVISED_FINE_TUNING':
|
|
200
|
+
if getv(from_object, ['learning_rate_multiplier']) is not None:
|
|
201
|
+
setv(
|
|
202
|
+
parent_object,
|
|
203
|
+
['supervisedTuningSpec', 'hyperParameters', 'learningRateMultiplier'],
|
|
204
|
+
getv(from_object, ['learning_rate_multiplier']),
|
|
205
|
+
)
|
|
176
206
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
207
|
+
elif discriminator == 'PREFERENCE_TUNING':
|
|
208
|
+
if getv(from_object, ['learning_rate_multiplier']) is not None:
|
|
209
|
+
setv(
|
|
210
|
+
parent_object,
|
|
211
|
+
[
|
|
212
|
+
'preferenceOptimizationSpec',
|
|
213
|
+
'hyperParameters',
|
|
214
|
+
'learningRateMultiplier',
|
|
215
|
+
],
|
|
216
|
+
getv(from_object, ['learning_rate_multiplier']),
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
discriminator = getv(root_object, ['config', 'method'])
|
|
220
|
+
if discriminator is None:
|
|
221
|
+
discriminator = 'SUPERVISED_FINE_TUNING'
|
|
222
|
+
if discriminator == 'SUPERVISED_FINE_TUNING':
|
|
223
|
+
if getv(from_object, ['export_last_checkpoint_only']) is not None:
|
|
224
|
+
setv(
|
|
225
|
+
parent_object,
|
|
226
|
+
['supervisedTuningSpec', 'exportLastCheckpointOnly'],
|
|
227
|
+
getv(from_object, ['export_last_checkpoint_only']),
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
elif discriminator == 'PREFERENCE_TUNING':
|
|
231
|
+
if getv(from_object, ['export_last_checkpoint_only']) is not None:
|
|
232
|
+
setv(
|
|
233
|
+
parent_object,
|
|
234
|
+
['preferenceOptimizationSpec', 'exportLastCheckpointOnly'],
|
|
235
|
+
getv(from_object, ['export_last_checkpoint_only']),
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
discriminator = getv(root_object, ['config', 'method'])
|
|
239
|
+
if discriminator is None:
|
|
240
|
+
discriminator = 'SUPERVISED_FINE_TUNING'
|
|
241
|
+
if discriminator == 'SUPERVISED_FINE_TUNING':
|
|
242
|
+
if getv(from_object, ['adapter_size']) is not None:
|
|
243
|
+
setv(
|
|
244
|
+
parent_object,
|
|
245
|
+
['supervisedTuningSpec', 'hyperParameters', 'adapterSize'],
|
|
246
|
+
getv(from_object, ['adapter_size']),
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
elif discriminator == 'PREFERENCE_TUNING':
|
|
250
|
+
if getv(from_object, ['adapter_size']) is not None:
|
|
251
|
+
setv(
|
|
252
|
+
parent_object,
|
|
253
|
+
['preferenceOptimizationSpec', 'hyperParameters', 'adapterSize'],
|
|
254
|
+
getv(from_object, ['adapter_size']),
|
|
255
|
+
)
|
|
183
256
|
|
|
184
257
|
if getv(from_object, ['batch_size']) is not None:
|
|
185
258
|
raise ValueError('batch_size parameter is not supported in Vertex AI.')
|
|
@@ -187,24 +260,46 @@ def _CreateTuningJobConfig_to_vertex(
|
|
|
187
260
|
if getv(from_object, ['learning_rate']) is not None:
|
|
188
261
|
raise ValueError('learning_rate parameter is not supported in Vertex AI.')
|
|
189
262
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
263
|
+
discriminator = getv(root_object, ['config', 'method'])
|
|
264
|
+
if discriminator is None:
|
|
265
|
+
discriminator = 'SUPERVISED_FINE_TUNING'
|
|
266
|
+
if discriminator == 'SUPERVISED_FINE_TUNING':
|
|
267
|
+
if getv(from_object, ['evaluation_config']) is not None:
|
|
268
|
+
setv(
|
|
269
|
+
parent_object,
|
|
270
|
+
['supervisedTuningSpec', 'evaluationConfig'],
|
|
271
|
+
_EvaluationConfig_to_vertex(
|
|
272
|
+
getv(from_object, ['evaluation_config']), to_object, root_object
|
|
273
|
+
),
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
elif discriminator == 'PREFERENCE_TUNING':
|
|
277
|
+
if getv(from_object, ['evaluation_config']) is not None:
|
|
278
|
+
setv(
|
|
279
|
+
parent_object,
|
|
280
|
+
['preferenceOptimizationSpec', 'evaluationConfig'],
|
|
281
|
+
_EvaluationConfig_to_vertex(
|
|
282
|
+
getv(from_object, ['evaluation_config']), to_object, root_object
|
|
283
|
+
),
|
|
284
|
+
)
|
|
198
285
|
|
|
199
286
|
if getv(from_object, ['labels']) is not None:
|
|
200
287
|
setv(parent_object, ['labels'], getv(from_object, ['labels']))
|
|
201
288
|
|
|
289
|
+
if getv(from_object, ['beta']) is not None:
|
|
290
|
+
setv(
|
|
291
|
+
parent_object,
|
|
292
|
+
['preferenceOptimizationSpec', 'hyperParameters', 'beta'],
|
|
293
|
+
getv(from_object, ['beta']),
|
|
294
|
+
)
|
|
295
|
+
|
|
202
296
|
return to_object
|
|
203
297
|
|
|
204
298
|
|
|
205
299
|
def _CreateTuningJobParametersPrivate_to_mldev(
|
|
206
300
|
from_object: Union[dict[str, Any], object],
|
|
207
301
|
parent_object: Optional[dict[str, Any]] = None,
|
|
302
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
208
303
|
) -> dict[str, Any]:
|
|
209
304
|
to_object: dict[str, Any] = {}
|
|
210
305
|
if getv(from_object, ['base_model']) is not None:
|
|
@@ -214,16 +309,14 @@ def _CreateTuningJobParametersPrivate_to_mldev(
|
|
|
214
309
|
setv(to_object, ['preTunedModel'], getv(from_object, ['pre_tuned_model']))
|
|
215
310
|
|
|
216
311
|
if getv(from_object, ['training_dataset']) is not None:
|
|
217
|
-
|
|
218
|
-
to_object,
|
|
219
|
-
['tuningTask', 'trainingData'],
|
|
220
|
-
_TuningDataset_to_mldev(
|
|
221
|
-
getv(from_object, ['training_dataset']), to_object
|
|
222
|
-
),
|
|
312
|
+
_TuningDataset_to_mldev(
|
|
313
|
+
getv(from_object, ['training_dataset']), to_object, root_object
|
|
223
314
|
)
|
|
224
315
|
|
|
225
316
|
if getv(from_object, ['config']) is not None:
|
|
226
|
-
_CreateTuningJobConfig_to_mldev(
|
|
317
|
+
_CreateTuningJobConfig_to_mldev(
|
|
318
|
+
getv(from_object, ['config']), to_object, root_object
|
|
319
|
+
)
|
|
227
320
|
|
|
228
321
|
return to_object
|
|
229
322
|
|
|
@@ -231,6 +324,7 @@ def _CreateTuningJobParametersPrivate_to_mldev(
|
|
|
231
324
|
def _CreateTuningJobParametersPrivate_to_vertex(
|
|
232
325
|
from_object: Union[dict[str, Any], object],
|
|
233
326
|
parent_object: Optional[dict[str, Any]] = None,
|
|
327
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
234
328
|
) -> dict[str, Any]:
|
|
235
329
|
to_object: dict[str, Any] = {}
|
|
236
330
|
if getv(from_object, ['base_model']) is not None:
|
|
@@ -240,16 +334,14 @@ def _CreateTuningJobParametersPrivate_to_vertex(
|
|
|
240
334
|
setv(to_object, ['preTunedModel'], getv(from_object, ['pre_tuned_model']))
|
|
241
335
|
|
|
242
336
|
if getv(from_object, ['training_dataset']) is not None:
|
|
243
|
-
|
|
244
|
-
to_object,
|
|
245
|
-
['supervisedTuningSpec', 'trainingDatasetUri'],
|
|
246
|
-
_TuningDataset_to_vertex(
|
|
247
|
-
getv(from_object, ['training_dataset']), to_object
|
|
248
|
-
),
|
|
337
|
+
_TuningDataset_to_vertex(
|
|
338
|
+
getv(from_object, ['training_dataset']), to_object, root_object
|
|
249
339
|
)
|
|
250
340
|
|
|
251
341
|
if getv(from_object, ['config']) is not None:
|
|
252
|
-
_CreateTuningJobConfig_to_vertex(
|
|
342
|
+
_CreateTuningJobConfig_to_vertex(
|
|
343
|
+
getv(from_object, ['config']), to_object, root_object
|
|
344
|
+
)
|
|
253
345
|
|
|
254
346
|
return to_object
|
|
255
347
|
|
|
@@ -257,6 +349,7 @@ def _CreateTuningJobParametersPrivate_to_vertex(
|
|
|
257
349
|
def _EvaluationConfig_from_vertex(
|
|
258
350
|
from_object: Union[dict[str, Any], object],
|
|
259
351
|
parent_object: Optional[dict[str, Any]] = None,
|
|
352
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
260
353
|
) -> dict[str, Any]:
|
|
261
354
|
to_object: dict[str, Any] = {}
|
|
262
355
|
if getv(from_object, ['metrics']) is not None:
|
|
@@ -276,6 +369,7 @@ def _EvaluationConfig_from_vertex(
|
|
|
276
369
|
def _EvaluationConfig_to_vertex(
|
|
277
370
|
from_object: Union[dict[str, Any], object],
|
|
278
371
|
parent_object: Optional[dict[str, Any]] = None,
|
|
372
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
279
373
|
) -> dict[str, Any]:
|
|
280
374
|
to_object: dict[str, Any] = {}
|
|
281
375
|
if getv(from_object, ['metrics']) is not None:
|
|
@@ -295,6 +389,7 @@ def _EvaluationConfig_to_vertex(
|
|
|
295
389
|
def _GetTuningJobParameters_to_mldev(
|
|
296
390
|
from_object: Union[dict[str, Any], object],
|
|
297
391
|
parent_object: Optional[dict[str, Any]] = None,
|
|
392
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
298
393
|
) -> dict[str, Any]:
|
|
299
394
|
to_object: dict[str, Any] = {}
|
|
300
395
|
if getv(from_object, ['name']) is not None:
|
|
@@ -306,6 +401,7 @@ def _GetTuningJobParameters_to_mldev(
|
|
|
306
401
|
def _GetTuningJobParameters_to_vertex(
|
|
307
402
|
from_object: Union[dict[str, Any], object],
|
|
308
403
|
parent_object: Optional[dict[str, Any]] = None,
|
|
404
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
309
405
|
) -> dict[str, Any]:
|
|
310
406
|
to_object: dict[str, Any] = {}
|
|
311
407
|
if getv(from_object, ['name']) is not None:
|
|
@@ -317,6 +413,7 @@ def _GetTuningJobParameters_to_vertex(
|
|
|
317
413
|
def _ListTuningJobsConfig_to_mldev(
|
|
318
414
|
from_object: Union[dict[str, Any], object],
|
|
319
415
|
parent_object: Optional[dict[str, Any]] = None,
|
|
416
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
320
417
|
) -> dict[str, Any]:
|
|
321
418
|
to_object: dict[str, Any] = {}
|
|
322
419
|
|
|
@@ -341,6 +438,7 @@ def _ListTuningJobsConfig_to_mldev(
|
|
|
341
438
|
def _ListTuningJobsConfig_to_vertex(
|
|
342
439
|
from_object: Union[dict[str, Any], object],
|
|
343
440
|
parent_object: Optional[dict[str, Any]] = None,
|
|
441
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
344
442
|
) -> dict[str, Any]:
|
|
345
443
|
to_object: dict[str, Any] = {}
|
|
346
444
|
|
|
@@ -365,10 +463,13 @@ def _ListTuningJobsConfig_to_vertex(
|
|
|
365
463
|
def _ListTuningJobsParameters_to_mldev(
|
|
366
464
|
from_object: Union[dict[str, Any], object],
|
|
367
465
|
parent_object: Optional[dict[str, Any]] = None,
|
|
466
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
368
467
|
) -> dict[str, Any]:
|
|
369
468
|
to_object: dict[str, Any] = {}
|
|
370
469
|
if getv(from_object, ['config']) is not None:
|
|
371
|
-
_ListTuningJobsConfig_to_mldev(
|
|
470
|
+
_ListTuningJobsConfig_to_mldev(
|
|
471
|
+
getv(from_object, ['config']), to_object, root_object
|
|
472
|
+
)
|
|
372
473
|
|
|
373
474
|
return to_object
|
|
374
475
|
|
|
@@ -376,10 +477,13 @@ def _ListTuningJobsParameters_to_mldev(
|
|
|
376
477
|
def _ListTuningJobsParameters_to_vertex(
|
|
377
478
|
from_object: Union[dict[str, Any], object],
|
|
378
479
|
parent_object: Optional[dict[str, Any]] = None,
|
|
480
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
379
481
|
) -> dict[str, Any]:
|
|
380
482
|
to_object: dict[str, Any] = {}
|
|
381
483
|
if getv(from_object, ['config']) is not None:
|
|
382
|
-
_ListTuningJobsConfig_to_vertex(
|
|
484
|
+
_ListTuningJobsConfig_to_vertex(
|
|
485
|
+
getv(from_object, ['config']), to_object, root_object
|
|
486
|
+
)
|
|
383
487
|
|
|
384
488
|
return to_object
|
|
385
489
|
|
|
@@ -387,6 +491,7 @@ def _ListTuningJobsParameters_to_vertex(
|
|
|
387
491
|
def _ListTuningJobsResponse_from_mldev(
|
|
388
492
|
from_object: Union[dict[str, Any], object],
|
|
389
493
|
parent_object: Optional[dict[str, Any]] = None,
|
|
494
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
390
495
|
) -> dict[str, Any]:
|
|
391
496
|
to_object: dict[str, Any] = {}
|
|
392
497
|
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
@@ -402,7 +507,7 @@ def _ListTuningJobsResponse_from_mldev(
|
|
|
402
507
|
to_object,
|
|
403
508
|
['tuning_jobs'],
|
|
404
509
|
[
|
|
405
|
-
_TuningJob_from_mldev(item, to_object)
|
|
510
|
+
_TuningJob_from_mldev(item, to_object, root_object)
|
|
406
511
|
for item in getv(from_object, ['tunedModels'])
|
|
407
512
|
],
|
|
408
513
|
)
|
|
@@ -413,6 +518,7 @@ def _ListTuningJobsResponse_from_mldev(
|
|
|
413
518
|
def _ListTuningJobsResponse_from_vertex(
|
|
414
519
|
from_object: Union[dict[str, Any], object],
|
|
415
520
|
parent_object: Optional[dict[str, Any]] = None,
|
|
521
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
416
522
|
) -> dict[str, Any]:
|
|
417
523
|
to_object: dict[str, Any] = {}
|
|
418
524
|
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
@@ -428,7 +534,7 @@ def _ListTuningJobsResponse_from_vertex(
|
|
|
428
534
|
to_object,
|
|
429
535
|
['tuning_jobs'],
|
|
430
536
|
[
|
|
431
|
-
_TuningJob_from_vertex(item, to_object)
|
|
537
|
+
_TuningJob_from_vertex(item, to_object, root_object)
|
|
432
538
|
for item in getv(from_object, ['tuningJobs'])
|
|
433
539
|
],
|
|
434
540
|
)
|
|
@@ -439,6 +545,7 @@ def _ListTuningJobsResponse_from_vertex(
|
|
|
439
545
|
def _TunedModel_from_mldev(
|
|
440
546
|
from_object: Union[dict[str, Any], object],
|
|
441
547
|
parent_object: Optional[dict[str, Any]] = None,
|
|
548
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
442
549
|
) -> dict[str, Any]:
|
|
443
550
|
to_object: dict[str, Any] = {}
|
|
444
551
|
if getv(from_object, ['name']) is not None:
|
|
@@ -453,6 +560,7 @@ def _TunedModel_from_mldev(
|
|
|
453
560
|
def _TuningDataset_to_mldev(
|
|
454
561
|
from_object: Union[dict[str, Any], object],
|
|
455
562
|
parent_object: Optional[dict[str, Any]] = None,
|
|
563
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
456
564
|
) -> dict[str, Any]:
|
|
457
565
|
to_object: dict[str, Any] = {}
|
|
458
566
|
if getv(from_object, ['gcs_uri']) is not None:
|
|
@@ -476,21 +584,47 @@ def _TuningDataset_to_mldev(
|
|
|
476
584
|
def _TuningDataset_to_vertex(
|
|
477
585
|
from_object: Union[dict[str, Any], object],
|
|
478
586
|
parent_object: Optional[dict[str, Any]] = None,
|
|
587
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
479
588
|
) -> dict[str, Any]:
|
|
480
589
|
to_object: dict[str, Any] = {}
|
|
481
|
-
if getv(from_object, ['gcs_uri']) is not None:
|
|
482
|
-
setv(
|
|
483
|
-
parent_object,
|
|
484
|
-
['supervisedTuningSpec', 'trainingDatasetUri'],
|
|
485
|
-
getv(from_object, ['gcs_uri']),
|
|
486
|
-
)
|
|
487
590
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
591
|
+
discriminator = getv(root_object, ['config', 'method'])
|
|
592
|
+
if discriminator is None:
|
|
593
|
+
discriminator = 'SUPERVISED_FINE_TUNING'
|
|
594
|
+
if discriminator == 'SUPERVISED_FINE_TUNING':
|
|
595
|
+
if getv(from_object, ['gcs_uri']) is not None:
|
|
596
|
+
setv(
|
|
597
|
+
parent_object,
|
|
598
|
+
['supervisedTuningSpec', 'trainingDatasetUri'],
|
|
599
|
+
getv(from_object, ['gcs_uri']),
|
|
600
|
+
)
|
|
601
|
+
|
|
602
|
+
elif discriminator == 'PREFERENCE_TUNING':
|
|
603
|
+
if getv(from_object, ['gcs_uri']) is not None:
|
|
604
|
+
setv(
|
|
605
|
+
parent_object,
|
|
606
|
+
['preferenceOptimizationSpec', 'trainingDatasetUri'],
|
|
607
|
+
getv(from_object, ['gcs_uri']),
|
|
608
|
+
)
|
|
609
|
+
|
|
610
|
+
discriminator = getv(root_object, ['config', 'method'])
|
|
611
|
+
if discriminator is None:
|
|
612
|
+
discriminator = 'SUPERVISED_FINE_TUNING'
|
|
613
|
+
if discriminator == 'SUPERVISED_FINE_TUNING':
|
|
614
|
+
if getv(from_object, ['vertex_dataset_resource']) is not None:
|
|
615
|
+
setv(
|
|
616
|
+
parent_object,
|
|
617
|
+
['supervisedTuningSpec', 'trainingDatasetUri'],
|
|
618
|
+
getv(from_object, ['vertex_dataset_resource']),
|
|
619
|
+
)
|
|
620
|
+
|
|
621
|
+
elif discriminator == 'PREFERENCE_TUNING':
|
|
622
|
+
if getv(from_object, ['vertex_dataset_resource']) is not None:
|
|
623
|
+
setv(
|
|
624
|
+
parent_object,
|
|
625
|
+
['preferenceOptimizationSpec', 'trainingDatasetUri'],
|
|
626
|
+
getv(from_object, ['vertex_dataset_resource']),
|
|
627
|
+
)
|
|
494
628
|
|
|
495
629
|
if getv(from_object, ['examples']) is not None:
|
|
496
630
|
raise ValueError('examples parameter is not supported in Vertex AI.')
|
|
@@ -501,6 +635,7 @@ def _TuningDataset_to_vertex(
|
|
|
501
635
|
def _TuningJob_from_mldev(
|
|
502
636
|
from_object: Union[dict[str, Any], object],
|
|
503
637
|
parent_object: Optional[dict[str, Any]] = None,
|
|
638
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
504
639
|
) -> dict[str, Any]:
|
|
505
640
|
to_object: dict[str, Any] = {}
|
|
506
641
|
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
@@ -548,45 +683,18 @@ def _TuningJob_from_mldev(
|
|
|
548
683
|
setv(
|
|
549
684
|
to_object,
|
|
550
685
|
['tuned_model'],
|
|
551
|
-
_TunedModel_from_mldev(
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
if getv(from_object, ['customBaseModel']) is not None:
|
|
555
|
-
setv(
|
|
556
|
-
to_object, ['custom_base_model'], getv(from_object, ['customBaseModel'])
|
|
557
|
-
)
|
|
558
|
-
|
|
559
|
-
if getv(from_object, ['experiment']) is not None:
|
|
560
|
-
setv(to_object, ['experiment'], getv(from_object, ['experiment']))
|
|
561
|
-
|
|
562
|
-
if getv(from_object, ['labels']) is not None:
|
|
563
|
-
setv(to_object, ['labels'], getv(from_object, ['labels']))
|
|
564
|
-
|
|
565
|
-
if getv(from_object, ['outputUri']) is not None:
|
|
566
|
-
setv(to_object, ['output_uri'], getv(from_object, ['outputUri']))
|
|
567
|
-
|
|
568
|
-
if getv(from_object, ['pipelineJob']) is not None:
|
|
569
|
-
setv(to_object, ['pipeline_job'], getv(from_object, ['pipelineJob']))
|
|
570
|
-
|
|
571
|
-
if getv(from_object, ['serviceAccount']) is not None:
|
|
572
|
-
setv(to_object, ['service_account'], getv(from_object, ['serviceAccount']))
|
|
573
|
-
|
|
574
|
-
if getv(from_object, ['tunedModelDisplayName']) is not None:
|
|
575
|
-
setv(
|
|
576
|
-
to_object,
|
|
577
|
-
['tuned_model_display_name'],
|
|
578
|
-
getv(from_object, ['tunedModelDisplayName']),
|
|
686
|
+
_TunedModel_from_mldev(
|
|
687
|
+
getv(from_object, ['_self']), to_object, root_object
|
|
688
|
+
),
|
|
579
689
|
)
|
|
580
690
|
|
|
581
|
-
if getv(from_object, ['veoTuningSpec']) is not None:
|
|
582
|
-
setv(to_object, ['veo_tuning_spec'], getv(from_object, ['veoTuningSpec']))
|
|
583
|
-
|
|
584
691
|
return to_object
|
|
585
692
|
|
|
586
693
|
|
|
587
694
|
def _TuningJob_from_vertex(
|
|
588
695
|
from_object: Union[dict[str, Any], object],
|
|
589
696
|
parent_object: Optional[dict[str, Any]] = None,
|
|
697
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
590
698
|
) -> dict[str, Any]:
|
|
591
699
|
to_object: dict[str, Any] = {}
|
|
592
700
|
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
@@ -638,6 +746,13 @@ def _TuningJob_from_vertex(
|
|
|
638
746
|
getv(from_object, ['supervisedTuningSpec']),
|
|
639
747
|
)
|
|
640
748
|
|
|
749
|
+
if getv(from_object, ['preferenceOptimizationSpec']) is not None:
|
|
750
|
+
setv(
|
|
751
|
+
to_object,
|
|
752
|
+
['preference_optimization_spec'],
|
|
753
|
+
getv(from_object, ['preferenceOptimizationSpec']),
|
|
754
|
+
)
|
|
755
|
+
|
|
641
756
|
if getv(from_object, ['tuningDataStats']) is not None:
|
|
642
757
|
setv(
|
|
643
758
|
to_object, ['tuning_data_stats'], getv(from_object, ['tuningDataStats'])
|
|
@@ -658,7 +773,7 @@ def _TuningJob_from_vertex(
|
|
|
658
773
|
to_object,
|
|
659
774
|
['evaluation_config'],
|
|
660
775
|
_EvaluationConfig_from_vertex(
|
|
661
|
-
getv(from_object, ['evaluationConfig']), to_object
|
|
776
|
+
getv(from_object, ['evaluationConfig']), to_object, root_object
|
|
662
777
|
),
|
|
663
778
|
)
|
|
664
779
|
|
|
@@ -698,6 +813,7 @@ def _TuningJob_from_vertex(
|
|
|
698
813
|
def _TuningOperation_from_mldev(
|
|
699
814
|
from_object: Union[dict[str, Any], object],
|
|
700
815
|
parent_object: Optional[dict[str, Any]] = None,
|
|
816
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
701
817
|
) -> dict[str, Any]:
|
|
702
818
|
to_object: dict[str, Any] = {}
|
|
703
819
|
if getv(from_object, ['sdkHttpResponse']) is not None:
|
|
@@ -723,6 +839,7 @@ def _TuningOperation_from_mldev(
|
|
|
723
839
|
def _TuningValidationDataset_to_vertex(
|
|
724
840
|
from_object: Union[dict[str, Any], object],
|
|
725
841
|
parent_object: Optional[dict[str, Any]] = None,
|
|
842
|
+
root_object: Optional[Union[dict[str, Any], object]] = None,
|
|
726
843
|
) -> dict[str, Any]:
|
|
727
844
|
to_object: dict[str, Any] = {}
|
|
728
845
|
if getv(from_object, ['gcs_uri']) is not None:
|
|
@@ -730,8 +847,8 @@ def _TuningValidationDataset_to_vertex(
|
|
|
730
847
|
|
|
731
848
|
if getv(from_object, ['vertex_dataset_resource']) is not None:
|
|
732
849
|
setv(
|
|
733
|
-
|
|
734
|
-
['
|
|
850
|
+
to_object,
|
|
851
|
+
['validationDatasetUri'],
|
|
735
852
|
getv(from_object, ['vertex_dataset_resource']),
|
|
736
853
|
)
|
|
737
854
|
|
|
@@ -763,14 +880,18 @@ class Tunings(_api_module.BaseModule):
|
|
|
763
880
|
request_url_dict: Optional[dict[str, str]]
|
|
764
881
|
|
|
765
882
|
if self._api_client.vertexai:
|
|
766
|
-
request_dict = _GetTuningJobParameters_to_vertex(
|
|
883
|
+
request_dict = _GetTuningJobParameters_to_vertex(
|
|
884
|
+
parameter_model, None, parameter_model
|
|
885
|
+
)
|
|
767
886
|
request_url_dict = request_dict.get('_url')
|
|
768
887
|
if request_url_dict:
|
|
769
888
|
path = '{name}'.format_map(request_url_dict)
|
|
770
889
|
else:
|
|
771
890
|
path = '{name}'
|
|
772
891
|
else:
|
|
773
|
-
request_dict = _GetTuningJobParameters_to_mldev(
|
|
892
|
+
request_dict = _GetTuningJobParameters_to_mldev(
|
|
893
|
+
parameter_model, None, parameter_model
|
|
894
|
+
)
|
|
774
895
|
request_url_dict = request_dict.get('_url')
|
|
775
896
|
if request_url_dict:
|
|
776
897
|
path = '{name}'.format_map(request_url_dict)
|
|
@@ -830,14 +951,18 @@ class Tunings(_api_module.BaseModule):
|
|
|
830
951
|
request_url_dict: Optional[dict[str, str]]
|
|
831
952
|
|
|
832
953
|
if self._api_client.vertexai:
|
|
833
|
-
request_dict = _ListTuningJobsParameters_to_vertex(
|
|
954
|
+
request_dict = _ListTuningJobsParameters_to_vertex(
|
|
955
|
+
parameter_model, None, parameter_model
|
|
956
|
+
)
|
|
834
957
|
request_url_dict = request_dict.get('_url')
|
|
835
958
|
if request_url_dict:
|
|
836
959
|
path = 'tuningJobs'.format_map(request_url_dict)
|
|
837
960
|
else:
|
|
838
961
|
path = 'tuningJobs'
|
|
839
962
|
else:
|
|
840
|
-
request_dict = _ListTuningJobsParameters_to_mldev(
|
|
963
|
+
request_dict = _ListTuningJobsParameters_to_mldev(
|
|
964
|
+
parameter_model, None, parameter_model
|
|
965
|
+
)
|
|
841
966
|
request_url_dict = request_dict.get('_url')
|
|
842
967
|
if request_url_dict:
|
|
843
968
|
path = 'tunedModels'.format_map(request_url_dict)
|
|
@@ -898,14 +1023,18 @@ class Tunings(_api_module.BaseModule):
|
|
|
898
1023
|
request_url_dict: Optional[dict[str, str]]
|
|
899
1024
|
|
|
900
1025
|
if self._api_client.vertexai:
|
|
901
|
-
request_dict = _CancelTuningJobParameters_to_vertex(
|
|
1026
|
+
request_dict = _CancelTuningJobParameters_to_vertex(
|
|
1027
|
+
parameter_model, None, parameter_model
|
|
1028
|
+
)
|
|
902
1029
|
request_url_dict = request_dict.get('_url')
|
|
903
1030
|
if request_url_dict:
|
|
904
1031
|
path = '{name}:cancel'.format_map(request_url_dict)
|
|
905
1032
|
else:
|
|
906
1033
|
path = '{name}:cancel'
|
|
907
1034
|
else:
|
|
908
|
-
request_dict = _CancelTuningJobParameters_to_mldev(
|
|
1035
|
+
request_dict = _CancelTuningJobParameters_to_mldev(
|
|
1036
|
+
parameter_model, None, parameter_model
|
|
1037
|
+
)
|
|
909
1038
|
request_url_dict = request_dict.get('_url')
|
|
910
1039
|
if request_url_dict:
|
|
911
1040
|
path = '{name}:cancel'.format_map(request_url_dict)
|
|
@@ -939,7 +1068,7 @@ class Tunings(_api_module.BaseModule):
|
|
|
939
1068
|
training_dataset: types.TuningDatasetOrDict,
|
|
940
1069
|
config: Optional[types.CreateTuningJobConfigOrDict] = None,
|
|
941
1070
|
) -> types.TuningJob:
|
|
942
|
-
"""Creates a
|
|
1071
|
+
"""Creates a tuning job and returns the TuningJob object.
|
|
943
1072
|
|
|
944
1073
|
Args:
|
|
945
1074
|
base_model: The name of the model to tune.
|
|
@@ -962,7 +1091,7 @@ class Tunings(_api_module.BaseModule):
|
|
|
962
1091
|
raise ValueError('This method is only supported in the Vertex AI client.')
|
|
963
1092
|
else:
|
|
964
1093
|
request_dict = _CreateTuningJobParametersPrivate_to_vertex(
|
|
965
|
-
parameter_model
|
|
1094
|
+
parameter_model, None, parameter_model
|
|
966
1095
|
)
|
|
967
1096
|
request_url_dict = request_dict.get('_url')
|
|
968
1097
|
if request_url_dict:
|
|
@@ -1012,7 +1141,7 @@ class Tunings(_api_module.BaseModule):
|
|
|
1012
1141
|
training_dataset: types.TuningDatasetOrDict,
|
|
1013
1142
|
config: Optional[types.CreateTuningJobConfigOrDict] = None,
|
|
1014
1143
|
) -> types.TuningOperation:
|
|
1015
|
-
"""Creates a
|
|
1144
|
+
"""Creates a tuning job and returns the TuningJob object.
|
|
1016
1145
|
|
|
1017
1146
|
Args:
|
|
1018
1147
|
base_model: The name of the model to tune.
|
|
@@ -1036,7 +1165,9 @@ class Tunings(_api_module.BaseModule):
|
|
|
1036
1165
|
'This method is only supported in the Gemini Developer client.'
|
|
1037
1166
|
)
|
|
1038
1167
|
else:
|
|
1039
|
-
request_dict = _CreateTuningJobParametersPrivate_to_mldev(
|
|
1168
|
+
request_dict = _CreateTuningJobParametersPrivate_to_mldev(
|
|
1169
|
+
parameter_model, None, parameter_model
|
|
1170
|
+
)
|
|
1040
1171
|
request_url_dict = request_dict.get('_url')
|
|
1041
1172
|
if request_url_dict:
|
|
1042
1173
|
path = 'tunedModels'.format_map(request_url_dict)
|
|
@@ -1214,14 +1345,18 @@ class AsyncTunings(_api_module.BaseModule):
|
|
|
1214
1345
|
request_url_dict: Optional[dict[str, str]]
|
|
1215
1346
|
|
|
1216
1347
|
if self._api_client.vertexai:
|
|
1217
|
-
request_dict = _GetTuningJobParameters_to_vertex(
|
|
1348
|
+
request_dict = _GetTuningJobParameters_to_vertex(
|
|
1349
|
+
parameter_model, None, parameter_model
|
|
1350
|
+
)
|
|
1218
1351
|
request_url_dict = request_dict.get('_url')
|
|
1219
1352
|
if request_url_dict:
|
|
1220
1353
|
path = '{name}'.format_map(request_url_dict)
|
|
1221
1354
|
else:
|
|
1222
1355
|
path = '{name}'
|
|
1223
1356
|
else:
|
|
1224
|
-
request_dict = _GetTuningJobParameters_to_mldev(
|
|
1357
|
+
request_dict = _GetTuningJobParameters_to_mldev(
|
|
1358
|
+
parameter_model, None, parameter_model
|
|
1359
|
+
)
|
|
1225
1360
|
request_url_dict = request_dict.get('_url')
|
|
1226
1361
|
if request_url_dict:
|
|
1227
1362
|
path = '{name}'.format_map(request_url_dict)
|
|
@@ -1283,14 +1418,18 @@ class AsyncTunings(_api_module.BaseModule):
|
|
|
1283
1418
|
request_url_dict: Optional[dict[str, str]]
|
|
1284
1419
|
|
|
1285
1420
|
if self._api_client.vertexai:
|
|
1286
|
-
request_dict = _ListTuningJobsParameters_to_vertex(
|
|
1421
|
+
request_dict = _ListTuningJobsParameters_to_vertex(
|
|
1422
|
+
parameter_model, None, parameter_model
|
|
1423
|
+
)
|
|
1287
1424
|
request_url_dict = request_dict.get('_url')
|
|
1288
1425
|
if request_url_dict:
|
|
1289
1426
|
path = 'tuningJobs'.format_map(request_url_dict)
|
|
1290
1427
|
else:
|
|
1291
1428
|
path = 'tuningJobs'
|
|
1292
1429
|
else:
|
|
1293
|
-
request_dict = _ListTuningJobsParameters_to_mldev(
|
|
1430
|
+
request_dict = _ListTuningJobsParameters_to_mldev(
|
|
1431
|
+
parameter_model, None, parameter_model
|
|
1432
|
+
)
|
|
1294
1433
|
request_url_dict = request_dict.get('_url')
|
|
1295
1434
|
if request_url_dict:
|
|
1296
1435
|
path = 'tunedModels'.format_map(request_url_dict)
|
|
@@ -1353,14 +1492,18 @@ class AsyncTunings(_api_module.BaseModule):
|
|
|
1353
1492
|
request_url_dict: Optional[dict[str, str]]
|
|
1354
1493
|
|
|
1355
1494
|
if self._api_client.vertexai:
|
|
1356
|
-
request_dict = _CancelTuningJobParameters_to_vertex(
|
|
1495
|
+
request_dict = _CancelTuningJobParameters_to_vertex(
|
|
1496
|
+
parameter_model, None, parameter_model
|
|
1497
|
+
)
|
|
1357
1498
|
request_url_dict = request_dict.get('_url')
|
|
1358
1499
|
if request_url_dict:
|
|
1359
1500
|
path = '{name}:cancel'.format_map(request_url_dict)
|
|
1360
1501
|
else:
|
|
1361
1502
|
path = '{name}:cancel'
|
|
1362
1503
|
else:
|
|
1363
|
-
request_dict = _CancelTuningJobParameters_to_mldev(
|
|
1504
|
+
request_dict = _CancelTuningJobParameters_to_mldev(
|
|
1505
|
+
parameter_model, None, parameter_model
|
|
1506
|
+
)
|
|
1364
1507
|
request_url_dict = request_dict.get('_url')
|
|
1365
1508
|
if request_url_dict:
|
|
1366
1509
|
path = '{name}:cancel'.format_map(request_url_dict)
|
|
@@ -1394,7 +1537,7 @@ class AsyncTunings(_api_module.BaseModule):
|
|
|
1394
1537
|
training_dataset: types.TuningDatasetOrDict,
|
|
1395
1538
|
config: Optional[types.CreateTuningJobConfigOrDict] = None,
|
|
1396
1539
|
) -> types.TuningJob:
|
|
1397
|
-
"""Creates a
|
|
1540
|
+
"""Creates a tuning job and returns the TuningJob object.
|
|
1398
1541
|
|
|
1399
1542
|
Args:
|
|
1400
1543
|
base_model: The name of the model to tune.
|
|
@@ -1417,7 +1560,7 @@ class AsyncTunings(_api_module.BaseModule):
|
|
|
1417
1560
|
raise ValueError('This method is only supported in the Vertex AI client.')
|
|
1418
1561
|
else:
|
|
1419
1562
|
request_dict = _CreateTuningJobParametersPrivate_to_vertex(
|
|
1420
|
-
parameter_model
|
|
1563
|
+
parameter_model, None, parameter_model
|
|
1421
1564
|
)
|
|
1422
1565
|
request_url_dict = request_dict.get('_url')
|
|
1423
1566
|
if request_url_dict:
|
|
@@ -1467,7 +1610,7 @@ class AsyncTunings(_api_module.BaseModule):
|
|
|
1467
1610
|
training_dataset: types.TuningDatasetOrDict,
|
|
1468
1611
|
config: Optional[types.CreateTuningJobConfigOrDict] = None,
|
|
1469
1612
|
) -> types.TuningOperation:
|
|
1470
|
-
"""Creates a
|
|
1613
|
+
"""Creates a tuning job and returns the TuningJob object.
|
|
1471
1614
|
|
|
1472
1615
|
Args:
|
|
1473
1616
|
base_model: The name of the model to tune.
|
|
@@ -1491,7 +1634,9 @@ class AsyncTunings(_api_module.BaseModule):
|
|
|
1491
1634
|
'This method is only supported in the Gemini Developer client.'
|
|
1492
1635
|
)
|
|
1493
1636
|
else:
|
|
1494
|
-
request_dict = _CreateTuningJobParametersPrivate_to_mldev(
|
|
1637
|
+
request_dict = _CreateTuningJobParametersPrivate_to_mldev(
|
|
1638
|
+
parameter_model, None, parameter_model
|
|
1639
|
+
)
|
|
1495
1640
|
request_url_dict = request_dict.get('_url')
|
|
1496
1641
|
if request_url_dict:
|
|
1497
1642
|
path = 'tunedModels'.format_map(request_url_dict)
|