2828from google .cloud .aiplatform import models
2929from google .cloud .aiplatform import utils
3030from google .cloud .aiplatform .utils import _explanation_utils
31+ from google .cloud .aiplatform .utils import prediction_utils
3132from google .cloud .aiplatform .compat .services import (
3233 deployment_resource_pool_service_client_v1beta1 ,
3334 endpoint_service_client ,
@@ -140,6 +141,7 @@ def create(
140141 create_request_timeout : Optional [float ] = None ,
141142 required_replica_count : Optional [int ] = 0 ,
142143 multihost_gpu_node_count : Optional [int ] = None ,
144+ max_runtime_duration : Optional [int ] = None ,
143145 ) -> "DeploymentResourcePool" :
144146 """Creates a new DeploymentResourcePool.
145147
@@ -209,6 +211,13 @@ def create(
209211 multihost_gpu_node_count (int):
210212 Optional. The number of nodes per replica for multihost GPU
211213 deployments. Required for multihost GPU deployments.
214+ max_runtime_duration (int):
215+ Optional. Immutable. If set, use FlexStart VM powered by
216+ Dynamic Workload Scheduler to schedule the deployment workload.
217+ The FlexStart VM will be available for a maximum of 7 days or up
218+ to the max_runtime_duration specified, whichever is shorter.
219+ After this period, the model will be automatically undeployed.
220+ The value is in seconds.
212221
213222 Returns:
214223 DeploymentResourcePool
@@ -237,6 +246,7 @@ def create(
237246 create_request_timeout = create_request_timeout ,
238247 required_replica_count = required_replica_count ,
239248 multihost_gpu_node_count = multihost_gpu_node_count ,
249+ max_runtime_duration = max_runtime_duration ,
240250 )
241251
242252 @classmethod
@@ -260,6 +270,7 @@ def _create(
260270 create_request_timeout : Optional [float ] = None ,
261271 required_replica_count : Optional [int ] = 0 ,
262272 multihost_gpu_node_count : Optional [int ] = None ,
273+ max_runtime_duration : Optional [int ] = None ,
263274 ) -> "DeploymentResourcePool" :
264275 """Creates a new DeploymentResourcePool.
265276
@@ -332,7 +343,13 @@ def _create(
332343 multihost_gpu_node_count (int):
333344 Optional. The number of nodes per replica for multihost GPU
334345 deployments. Required for multihost GPU deployments.
335-
346+ max_runtime_duration (int):
347+ Optional. Immutable. If set, use FlexStart VM powered by Dynamic
348+ Workload Scheduler to schedule the deployment workload. The DWS
349+ resource will be available for a maximum of 7 days or up to the
350+ max_runtime_duration specified, whichever is shorter. After this
351+ period, the model will be automatically undeployed. The value is
352+ in seconds.
336353 Returns:
337354 DeploymentResourcePool
338355 """
@@ -347,6 +364,10 @@ def _create(
347364 required_replica_count = required_replica_count ,
348365 )
349366
367+ prediction_utils .add_flex_start_to_dedicated_resources (
368+ dedicated_resources , max_runtime_duration
369+ )
370+
350371 machine_spec = gca_machine_resources_compat .MachineSpec (
351372 machine_type = machine_type ,
352373 multihost_gpu_node_count = multihost_gpu_node_count ,
@@ -706,6 +727,7 @@ def deploy(
706727 required_replica_count : Optional [int ] = 0 ,
707728 rollout_options : Optional [RolloutOptions ] = None ,
708729 multihost_gpu_node_count : Optional [int ] = None ,
730+ max_runtime_duration : Optional [int ] = None ,
709731 ) -> None :
710732 """Deploys a Model to the Endpoint.
711733
@@ -809,6 +831,12 @@ def deploy(
809831 multihost_gpu_node_count (int): Optional. The number of nodes per
810832 replica for multihost GPU deployments. Required for multihost GPU
811833 deployments.
834+ max_runtime_duration (int):
835+ Optional. Immutable. If set, use DWS resource
836+ to schedule the deployment workload. The DWS resource will be available
837+ for a maximum of 7 days or up to the max_runtime_duration specified,
838+ whichever is shorter. After this period, the model will be
839+ automatically undeployed. The value is in seconds.
812840 """
813841 self ._sync_gca_resource_if_skipped ()
814842
@@ -853,6 +881,7 @@ def deploy(
853881 required_replica_count = required_replica_count ,
854882 rollout_options = rollout_options ,
855883 multihost_gpu_node_count = multihost_gpu_node_count ,
884+ max_runtime_duration = max_runtime_duration ,
856885 )
857886
858887 @base .optional_sync ()
@@ -882,6 +911,7 @@ def _deploy(
882911 required_replica_count : Optional [int ] = 0 ,
883912 rollout_options : Optional [RolloutOptions ] = None ,
884913 multihost_gpu_node_count : Optional [int ] = None ,
914+ max_runtime_duration : Optional [int ] = None ,
885915 ) -> None :
886916 """Deploys a Model to the Endpoint.
887917
@@ -979,7 +1009,12 @@ def _deploy(
9791009 multihost_gpu_node_count (int): Optional. The number of nodes per
9801010 replica for multihost GPU deployments. Required for multihost
9811011 GPU deployments.
982-
1012+ max_runtime_duration (int):
1013+ Optional. Immutable. If set, use DWS resource
1014+ to schedule the deployment workload. The DWS resource will be available
1015+ for a maximum of 7 days or up to the max_runtime_duration specified,
1016+ whichever is shorter. After this period, the model will be
1017+ automatically undeployed. The value is in seconds.
9831018 """
9841019 _LOGGER .log_action_start_against_resource (
9851020 f"Deploying Model { model .resource_name } to" , "" , self
@@ -1013,6 +1048,7 @@ def _deploy(
10131048 required_replica_count = required_replica_count ,
10141049 rollout_options = rollout_options ,
10151050 multihost_gpu_node_count = multihost_gpu_node_count ,
1051+ max_runtime_duration = max_runtime_duration ,
10161052 )
10171053
10181054 _LOGGER .log_action_completed_against_resource ("model" , "deployed" , self )
@@ -1049,6 +1085,7 @@ def _deploy_call(
10491085 required_replica_count : Optional [int ] = 0 ,
10501086 rollout_options : Optional [RolloutOptions ] = None ,
10511087 multihost_gpu_node_count : Optional [int ] = None ,
1088+ max_runtime_duration : Optional [int ] = None ,
10521089 ) -> None :
10531090 """Helper method to deploy model to endpoint.
10541091
@@ -1153,6 +1190,12 @@ def _deploy_call(
11531190 multihost_gpu_node_count (int):
11541191 Optional. The number of nodes per replica for multihost GPU
11551192 deployments. Required for multihost GPU deployments.
1193+ max_runtime_duration (int):
1194+ Optional. Immutable. If set, use DWS resource
1195+ to schedule the deployment workload. The DWS resource will be available
1196+ for a maximum of 7 days or up to the max_runtime_duration specified,
1197+ whichever is shorter. After this period, the model will be
1198+ automatically undeployed. The value is in seconds.
11561199
11571200 Raises:
11581201 ValueError: If only `accelerator_type` or `accelerator_count` is
@@ -1235,6 +1278,10 @@ def _deploy_call(
12351278 required_replica_count = required_replica_count ,
12361279 )
12371280
1281+ prediction_utils .add_flex_start_to_dedicated_resources (
1282+ dedicated_resources , max_runtime_duration
1283+ )
1284+
12381285 machine_spec = gca_machine_resources_compat .MachineSpec (
12391286 machine_type = machine_type ,
12401287 multihost_gpu_node_count = multihost_gpu_node_count ,
@@ -1599,6 +1646,7 @@ def deploy(
15991646 required_replica_count : Optional [int ] = 0 ,
16001647 rollout_options : Optional [RolloutOptions ] = None ,
16011648 multihost_gpu_node_count : Optional [int ] = None ,
1649+ max_runtime_duration : Optional [int ] = None ,
16021650 ) -> Union [Endpoint , models .PrivateEndpoint ]:
16031651 """Deploys model to endpoint.
16041652
@@ -1723,7 +1771,12 @@ def deploy(
17231771 multihost_gpu_node_count (int):
17241772 Optional. The number of nodes per replica for multihost GPU
17251773 deployments. Required for multihost GPU deployments.
1726-
1774+ max_runtime_duration (int):
1775+ Optional. Immutable. If set, use DWS resource
1776+ to schedule the deployment workload. The DWS resource will be available
1777+ for a maximum of 7 days or up to the max_runtime_duration specified,
1778+ whichever is shorter. After this period, the model will be
1779+ automatically undeployed. The value is in seconds.
17271780 Returns:
17281781 endpoint (Union[Endpoint, models.PrivateEndpoint]):
17291782 Endpoint with the deployed model.
@@ -1785,6 +1838,7 @@ def deploy(
17851838 required_replica_count = required_replica_count ,
17861839 rollout_options = rollout_options ,
17871840 multihost_gpu_node_count = multihost_gpu_node_count ,
1841+ max_runtime_duration = max_runtime_duration ,
17881842 )
17891843
17901844 def _should_enable_dedicated_endpoint (self , fast_tryout_enabled : bool ) -> bool :
@@ -1823,6 +1877,7 @@ def _deploy(
18231877 required_replica_count : Optional [int ] = 0 ,
18241878 rollout_options : Optional [RolloutOptions ] = None ,
18251879 multihost_gpu_node_count : Optional [int ] = None ,
1880+ max_runtime_duration : Optional [int ] = None ,
18261881 ) -> Union [Endpoint , models .PrivateEndpoint ]:
18271882 """Deploys model to endpoint.
18281883
@@ -1938,6 +1993,12 @@ def _deploy(
19381993 multihost_gpu_node_count (int):
19391994 Optional. The number of nodes per replica for multihost GPU
19401995 deployments. Required for multihost GPU deployments.
1996+ max_runtime_duration (int):
1997+ Optional. Immutable. If set, use DWS resource
1998+ to schedule the deployment workload. The DWS resource will be available
1999+ for a maximum of 7 days or up to the max_runtime_duration specified,
2000+ whichever is shorter. After this period, the model will be
2001+ automatically undeployed. The value is in seconds.
19412002 Returns:
19422003 endpoint (Union[Endpoint, models.PrivateEndpoint]):
19432004 Endpoint with the deployed model.
@@ -2004,6 +2065,7 @@ def _deploy(
20042065 system_labels = system_labels ,
20052066 required_replica_count = required_replica_count ,
20062067 multihost_gpu_node_count = multihost_gpu_node_count ,
2068+ max_runtime_duration = max_runtime_duration ,
20072069 ** preview_kwargs ,
20082070 )
20092071
0 commit comments