@@ -1923,6 +1923,7 @@ def from_local_script(
1923
1923
labels : Optional [Dict [str , str ]] = None ,
1924
1924
encryption_spec_key_name : Optional [str ] = None ,
1925
1925
staging_bucket : Optional [str ] = None ,
1926
+ persistent_resource_id : Optional [str ] = None ,
1926
1927
) -> "CustomJob" :
1927
1928
"""Configures a custom job from a local script.
1928
1929
@@ -2026,6 +2027,13 @@ def from_local_script(
2026
2027
staging_bucket (str):
2027
2028
Optional. Bucket for produced custom job artifacts. Overrides
2028
2029
staging_bucket set in aiplatform.init.
2030
+ persistent_resource_id (str):
2031
+ Optional. The ID of the PersistentResource in the same Project
2032
+ and Location. If this is specified, the job will be run on
2033
+ existing machines held by the PersistentResource instead of
2034
+ on-demand short-live machines. The network, CMEK, and node pool
2035
+ configs on the job should be consistent with those on the
2036
+ PersistentResource, otherwise, the job will be rejected.
2029
2037
2030
2038
Raises:
2031
2039
RuntimeError: If staging bucket was not set using aiplatform.init
@@ -2171,6 +2179,7 @@ def from_local_script(
2171
2179
labels = labels ,
2172
2180
encryption_spec_key_name = encryption_spec_key_name ,
2173
2181
staging_bucket = staging_bucket ,
2182
+ persistent_resource_id = persistent_resource_id ,
2174
2183
)
2175
2184
2176
2185
if enable_autolog :
@@ -2191,6 +2200,7 @@ def run(
2191
2200
sync : bool = True ,
2192
2201
create_request_timeout : Optional [float ] = None ,
2193
2202
disable_retries : bool = False ,
2203
+ persistent_resource_id : Optional [str ] = None ,
2194
2204
) -> None :
2195
2205
"""Run this configured CustomJob.
2196
2206
@@ -2252,6 +2262,13 @@ def run(
2252
2262
Indicates if the job should retry for internal errors after the
2253
2263
job starts running. If True, overrides
2254
2264
`restart_job_on_worker_restart` to False.
2265
+ persistent_resource_id (str):
2266
+ Optional. The ID of the PersistentResource in the same Project
2267
+ and Location. If this is specified, the job will be run on
2268
+ existing machines held by the PersistentResource instead of
2269
+ on-demand short-live machines. The network, CMEK, and node pool
2270
+ configs on the job should be consistent with those on the
2271
+ PersistentResource, otherwise, the job will be rejected.
2255
2272
"""
2256
2273
network = network or initializer .global_config .network
2257
2274
service_account = service_account or initializer .global_config .service_account
@@ -2268,6 +2285,7 @@ def run(
2268
2285
sync = sync ,
2269
2286
create_request_timeout = create_request_timeout ,
2270
2287
disable_retries = disable_retries ,
2288
+ persistent_resource_id = persistent_resource_id ,
2271
2289
)
2272
2290
2273
2291
@base .optional_sync ()
@@ -2284,6 +2302,7 @@ def _run(
2284
2302
sync : bool = True ,
2285
2303
create_request_timeout : Optional [float ] = None ,
2286
2304
disable_retries : bool = False ,
2305
+ persistent_resource_id : Optional [str ] = None ,
2287
2306
) -> None :
2288
2307
"""Helper method to ensure network synchronization and to run the configured CustomJob.
2289
2308
@@ -2343,6 +2362,13 @@ def _run(
2343
2362
Indicates if the job should retry for internal errors after the
2344
2363
job starts running. If True, overrides
2345
2364
`restart_job_on_worker_restart` to False.
2365
+ persistent_resource_id (str):
2366
+ Optional. The ID of the PersistentResource in the same Project
2367
+ and Location. If this is specified, the job will be run on
2368
+ existing machines held by the PersistentResource instead of
2369
+ on-demand short-live machines. The network, CMEK, and node pool
2370
+ configs on the job should be consistent with those on the
2371
+ PersistentResource, otherwise, the job will be rejected.
2346
2372
"""
2347
2373
self .submit (
2348
2374
service_account = service_account ,
@@ -2355,6 +2381,7 @@ def _run(
2355
2381
tensorboard = tensorboard ,
2356
2382
create_request_timeout = create_request_timeout ,
2357
2383
disable_retries = disable_retries ,
2384
+ persistent_resource_id = persistent_resource_id ,
2358
2385
)
2359
2386
2360
2387
self ._block_until_complete ()
@@ -2372,6 +2399,7 @@ def submit(
2372
2399
tensorboard : Optional [str ] = None ,
2373
2400
create_request_timeout : Optional [float ] = None ,
2374
2401
disable_retries : bool = False ,
2402
+ persistent_resource_id : Optional [str ] = None ,
2375
2403
) -> None :
2376
2404
"""Submit the configured CustomJob.
2377
2405
@@ -2428,6 +2456,13 @@ def submit(
2428
2456
Indicates if the job should retry for internal errors after the
2429
2457
job starts running. If True, overrides
2430
2458
`restart_job_on_worker_restart` to False.
2459
+ persistent_resource_id (str):
2460
+ Optional. The ID of the PersistentResource in the same Project
2461
+ and Location. If this is specified, the job will be run on
2462
+ existing machines held by the PersistentResource instead of
2463
+ on-demand short-live machines. The network, CMEK, and node pool
2464
+ configs on the job should be consistent with those on the
2465
+ PersistentResource, otherwise, the job will be rejected.
2431
2466
2432
2467
Raises:
2433
2468
ValueError:
@@ -2464,6 +2499,9 @@ def submit(
2464
2499
if tensorboard :
2465
2500
self ._gca_resource .job_spec .tensorboard = tensorboard
2466
2501
2502
+ if persistent_resource_id :
2503
+ self ._gca_resource .job_spec .persistent_resource_id = persistent_resource_id
2504
+
2467
2505
# TODO(b/275105711) Update implementation after experiment/run in the proto
2468
2506
if experiment :
2469
2507
# short-term solution to set experiment/experimentRun in SDK
0 commit comments