@@ -471,6 +471,80 @@ def list(
471
471
)
472
472
473
473
474
+ class RolloutOptions (object ):
475
+ """RolloutOptions contains configurations for rolling deployments.
476
+
477
+ Attributes:
478
+ previous_deployed_model:
479
+ The ID of the previous deployed model.
480
+ max_surge_percentage:
481
+ Maximum additional replicas to create during the deployment,
482
+ specified as a percentage of the current replica count.
483
+ max_surge_replicas:
484
+ Maximum number of additional replicas to create during the
485
+ deployment.
486
+ max_unavailable_percentage:
487
+ Maximum amount of replicas that can be unavailable during the
488
+ deployment, specified as a percentage of the current replica count.
489
+ max_unavailable_replicas:
490
+ Maximum number of replicas that can be unavailable during the
491
+ deployment.
492
+ """
493
+
494
+ def __init__ (
495
+ self ,
496
+ previous_deployed_model : int ,
497
+ max_surge_percentage : Optional [int ] = None ,
498
+ max_surge_replicas : Optional [int ] = None ,
499
+ max_unavailable_percentage : Optional [int ] = None ,
500
+ max_unavailable_replicas : Optional [int ] = None ,
501
+ ):
502
+ self .previous_deployed_model = previous_deployed_model
503
+ self .max_surge_percentage = max_surge_percentage
504
+ self .max_surge_replicas = max_surge_replicas
505
+ self .max_unavailable_percentage = max_unavailable_percentage
506
+ self .max_unavailable_replicas = max_unavailable_replicas
507
+
508
+ @classmethod
509
+ def from_gapic (cls , opts : gca_endpoint_compat .RolloutOptions ) -> "RolloutOptions" :
510
+ return cls (
511
+ previous_deployed_model = int (opts .previous_deployed_model ),
512
+ max_surge_percentage = opts .max_surge_percentage ,
513
+ max_surge_replicas = opts .max_surge_replicas ,
514
+ max_unavailable_percentage = opts .max_unavailable_percentage ,
515
+ max_unavailable_replicas = opts .max_unavailable_replicas ,
516
+ )
517
+
518
+ def to_gapic (self ) -> gca_endpoint_compat .RolloutOptions :
519
+ """Converts RolloutOptions class to gapic RolloutOptions proto."""
520
+ result = gca_endpoint_compat .RolloutOptions (
521
+ previous_deployed_model = str (self .previous_deployed_model ),
522
+ )
523
+ if self .max_surge_percentage :
524
+ if self .max_surge_replicas :
525
+ raise ValueError (
526
+ "max_surge_percentage and max_surge_replicas cannot both be" " set."
527
+ )
528
+ result .max_surge_percentage = self .max_surge_percentage
529
+ elif self .max_surge_replicas :
530
+ result .max_surge_replicas = self .max_surge_replicas
531
+ else :
532
+ result .max_surge_replicas = 0
533
+ if self .max_unavailable_percentage :
534
+ if self .max_unavailable_replicas :
535
+ raise ValueError (
536
+ "max_unavailable_percentage and max_unavailable_replicas"
537
+ " cannot both be set."
538
+ )
539
+ result .max_unavailable_percentage = self .max_unavailable_percentage
540
+ elif self .max_unavailable_replicas :
541
+ result .max_unavailable_replicas = self .max_unavailable_replicas
542
+ else :
543
+ result .max_unavailable_replicas = 0
544
+
545
+ return result
546
+
547
+
474
548
class Endpoint (aiplatform .Endpoint ):
475
549
@staticmethod
476
550
def _validate_deploy_args (
@@ -616,6 +690,7 @@ def deploy(
616
690
fast_tryout_enabled : bool = False ,
617
691
system_labels : Optional [Dict [str , str ]] = None ,
618
692
required_replica_count : Optional [int ] = 0 ,
693
+ rollout_options : Optional [RolloutOptions ] = None ,
619
694
) -> None :
620
695
"""Deploys a Model to the Endpoint.
621
696
@@ -712,6 +787,8 @@ def deploy(
712
787
set, the model deploy/mutate operation will succeed once
713
788
available_replica_count reaches required_replica_count, and the
714
789
rest of the replicas will be retried.
790
+ rollout_options (RolloutOptions):
791
+ Optional. Options to configure a rolling deployment.
715
792
716
793
"""
717
794
self ._sync_gca_resource_if_skipped ()
@@ -754,6 +831,7 @@ def deploy(
754
831
fast_tryout_enabled = fast_tryout_enabled ,
755
832
system_labels = system_labels ,
756
833
required_replica_count = required_replica_count ,
834
+ rollout_options = rollout_options ,
757
835
)
758
836
759
837
@base .optional_sync ()
@@ -780,6 +858,7 @@ def _deploy(
780
858
fast_tryout_enabled : bool = False ,
781
859
system_labels : Optional [Dict [str , str ]] = None ,
782
860
required_replica_count : Optional [int ] = 0 ,
861
+ rollout_options : Optional [RolloutOptions ] = None ,
783
862
) -> None :
784
863
"""Deploys a Model to the Endpoint.
785
864
@@ -870,7 +949,8 @@ def _deploy(
870
949
set, the model deploy/mutate operation will succeed once
871
950
available_replica_count reaches required_replica_count, and the
872
951
rest of the replicas will be retried.
873
-
952
+ rollout_options (RolloutOptions): Optional.
953
+ Options to configure a rolling deployment.
874
954
"""
875
955
_LOGGER .log_action_start_against_resource (
876
956
f"Deploying Model { model .resource_name } to" , "" , self
@@ -901,6 +981,7 @@ def _deploy(
901
981
fast_tryout_enabled = fast_tryout_enabled ,
902
982
system_labels = system_labels ,
903
983
required_replica_count = required_replica_count ,
984
+ rollout_options = rollout_options ,
904
985
)
905
986
906
987
_LOGGER .log_action_completed_against_resource ("model" , "deployed" , self )
@@ -934,6 +1015,7 @@ def _deploy_call(
934
1015
fast_tryout_enabled : bool = False ,
935
1016
system_labels : Optional [Dict [str , str ]] = None ,
936
1017
required_replica_count : Optional [int ] = 0 ,
1018
+ rollout_options : Optional [RolloutOptions ] = None ,
937
1019
) -> None :
938
1020
"""Helper method to deploy model to endpoint.
939
1021
@@ -1031,6 +1113,8 @@ def _deploy_call(
1031
1113
set, the model deploy/mutate operation will succeed once
1032
1114
available_replica_count reaches required_replica_count, and the
1033
1115
rest of the replicas will be retried.
1116
+ rollout_options (RolloutOptions): Optional. Options to configure a
1117
+ rolling deployment.
1034
1118
1035
1119
Raises:
1036
1120
ValueError: If only `accelerator_type` or `accelerator_count` is
@@ -1103,7 +1187,7 @@ def _deploy_call(
1103
1187
machine_type = _DEFAULT_MACHINE_TYPE
1104
1188
_LOGGER .info (f"Using default machine_type: { machine_type } " )
1105
1189
1106
- if use_dedicated_resources :
1190
+ if use_dedicated_resources and not rollout_options :
1107
1191
dedicated_resources = gca_machine_resources_compat .DedicatedResources (
1108
1192
min_replica_count = min_replica_count ,
1109
1193
max_replica_count = max_replica_count ,
@@ -1146,6 +1230,15 @@ def _deploy_call(
1146
1230
)
1147
1231
)
1148
1232
deployed_model .dedicated_resources = dedicated_resources
1233
+ elif rollout_options :
1234
+ deployed_model .rollout_options = rollout_options .to_gapic ()
1235
+ elif supports_automatic_resources :
1236
+ deployed_model .automatic_resources = (
1237
+ gca_machine_resources_compat .AutomaticResources (
1238
+ min_replica_count = min_replica_count ,
1239
+ max_replica_count = max_replica_count ,
1240
+ )
1241
+ )
1149
1242
else :
1150
1243
deployed_model = gca_endpoint_compat .DeployedModel (
1151
1244
model = model .versioned_resource_name ,
@@ -1444,6 +1537,7 @@ def deploy(
1444
1537
fast_tryout_enabled : bool = False ,
1445
1538
system_labels : Optional [Dict [str , str ]] = None ,
1446
1539
required_replica_count : Optional [int ] = 0 ,
1540
+ rollout_options : Optional [RolloutOptions ] = None ,
1447
1541
) -> Union [Endpoint , models .PrivateEndpoint ]:
1448
1542
"""Deploys model to endpoint.
1449
1543
@@ -1561,6 +1655,8 @@ def deploy(
1561
1655
set, the model deploy/mutate operation will succeed once
1562
1656
available_replica_count reaches required_replica_count, and the
1563
1657
rest of the replicas will be retried.
1658
+ rollout_options (RolloutOptions):
1659
+ Optional. Options to configure a rolling deployment.
1564
1660
1565
1661
Returns:
1566
1662
endpoint (Union[Endpoint, models.PrivateEndpoint]):
@@ -1620,6 +1716,7 @@ def deploy(
1620
1716
fast_tryout_enabled = fast_tryout_enabled ,
1621
1717
system_labels = system_labels ,
1622
1718
required_replica_count = required_replica_count ,
1719
+ rollout_options = rollout_options ,
1623
1720
)
1624
1721
1625
1722
def _should_enable_dedicated_endpoint (self , fast_tryout_enabled : bool ) -> bool :
@@ -1655,6 +1752,7 @@ def _deploy(
1655
1752
fast_tryout_enabled : bool = False ,
1656
1753
system_labels : Optional [Dict [str , str ]] = None ,
1657
1754
required_replica_count : Optional [int ] = 0 ,
1755
+ rollout_options : Optional [RolloutOptions ] = None ,
1658
1756
) -> Union [Endpoint , models .PrivateEndpoint ]:
1659
1757
"""Deploys model to endpoint.
1660
1758
@@ -1763,6 +1861,8 @@ def _deploy(
1763
1861
set, the model deploy/mutate operation will succeed once
1764
1862
available_replica_count reaches required_replica_count, and the
1765
1863
rest of the replicas will be retried.
1864
+ rollout_options (RolloutOptions):
1865
+ Optional. Options to configure a rolling deployment.
1766
1866
1767
1867
Returns:
1768
1868
endpoint (Union[Endpoint, models.PrivateEndpoint]):
@@ -1771,6 +1871,10 @@ def _deploy(
1771
1871
1772
1872
if endpoint is None :
1773
1873
display_name = self .display_name [:118 ] + "_endpoint"
1874
+ if rollout_options is not None :
1875
+ raise ValueError (
1876
+ "Rollout options may only be used when deploying to an existing endpoint."
1877
+ )
1774
1878
1775
1879
if not network :
1776
1880
endpoint = Endpoint .create (
@@ -1792,6 +1896,10 @@ def _deploy(
1792
1896
credentials = self .credentials ,
1793
1897
encryption_spec_key_name = encryption_spec_key_name ,
1794
1898
)
1899
+ if isinstance (endpoint , Endpoint ):
1900
+ preview_kwargs = {"rollout_options" : rollout_options }
1901
+ else :
1902
+ preview_kwargs = {}
1795
1903
1796
1904
_LOGGER .log_action_start_against_resource ("Deploying model to" , "" , endpoint )
1797
1905
@@ -1820,6 +1928,7 @@ def _deploy(
1820
1928
fast_tryout_enabled = fast_tryout_enabled ,
1821
1929
system_labels = system_labels ,
1822
1930
required_replica_count = required_replica_count ,
1931
+ ** preview_kwargs ,
1823
1932
)
1824
1933
1825
1934
_LOGGER .log_action_completed_against_resource ("model" , "deployed" , endpoint )
0 commit comments