Skip to content

Commit 7f167c9

Browse files
committed
Added custom egress for model deployment
1 parent 230cde6 commit 7f167c9

File tree

6 files changed

+74
-0
lines changed

6 files changed

+74
-0
lines changed

ads/model/deployment/model_deployment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,9 @@ def _build_model_deployment_configuration_details(self) -> Dict:
15201520
or MODEL_DEPLOYMENT_INSTANCE_MEMORY_IN_GBS,
15211521
}
15221522

1523+
if infrastructure.subnet_id:
1524+
instance_configuration[infrastructure.CONST_SUBNET_ID] = infrastructure.subnet_id
1525+
15231526
scaling_policy = {
15241527
infrastructure.CONST_POLICY_TYPE: "FIXED_SIZE",
15251528
infrastructure.CONST_INSTANCE_COUNT: infrastructure.replica

ads/model/deployment/model_deployment_infrastructure.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class ModelDeploymentInfrastructure(Builder):
3939
The access and predict log id of model deployment
4040
web_concurrency: int
4141
The web concurrency of model deployment
42+
subnet_id: str
43+
The subnet id of model deployment
4244
4345
Methods
4446
-------
@@ -64,6 +66,8 @@ class ModelDeploymentInfrastructure(Builder):
6466
Sets the access and predict log id of model deployment
6567
with_web_concurrency(web_concurrency)
6668
Sets the web concurrency of model deployment
69+
with_subnet_id(subnet_id)
70+
Sets the subnet id of model deployment
6771
6872
Example
6973
-------
@@ -79,6 +83,7 @@ class ModelDeploymentInfrastructure(Builder):
7983
... .with_replica(1)
8084
... .with_bandwidth_mbps(10)
8185
... .with_web_concurrency(10)
86+
... .with_subnet_id(<subnet_id>)
8287
... .with_access_log(
8388
... log_group_id=<log_group_id>,
8489
... log_id=<log_id>
@@ -121,6 +126,7 @@ class ModelDeploymentInfrastructure(Builder):
121126
CONST_LOG_GROUP_ID = "logGroupId"
122127
CONST_WEB_CONCURRENCY = "webConcurrency"
123128
CONST_STREAM_CONFIG_DETAILS = "streamConfigurationDetails"
129+
CONST_SUBNET_ID = "subnetId"
124130

125131
attribute_map = {
126132
CONST_PROJECT_ID: "project_id",
@@ -136,6 +142,7 @@ class ModelDeploymentInfrastructure(Builder):
136142
CONST_LOG_ID: "log_id",
137143
CONST_LOG_GROUP_ID: "log_group_id",
138144
CONST_WEB_CONCURRENCY: "web_concurrency",
145+
CONST_SUBNET_ID: "subnet_id"
139146
}
140147

141148
shape_config_details_attribute_map = {
@@ -162,6 +169,7 @@ class ModelDeploymentInfrastructure(Builder):
162169
CONST_COMPARTMENT_ID: "compartment_id",
163170
CONST_SHAPE_NAME: f"{MODEL_CONFIG_DETAILS_PATH}.instance_configuration.instance_shape_name",
164171
CONST_SHAPE_CONFIG_DETAILS: f"{MODEL_CONFIG_DETAILS_PATH}.instance_configuration.model_deployment_instance_shape_config_details",
172+
CONST_SUBNET_ID: f"{MODEL_CONFIG_DETAILS_PATH}.instance_configuration.subnet_id",
165173
CONST_REPLICA: f"{MODEL_CONFIG_DETAILS_PATH}.scaling_policy.instance_count",
166174
CONST_BANDWIDTH_MBPS: f"{MODEL_CONFIG_DETAILS_PATH}.bandwidth_mbps",
167175
CONST_ACCESS_LOG: "category_log_details.access",
@@ -518,3 +526,29 @@ def with_web_concurrency(
518526
The ModelDeploymentInfrastructure instance (self).
519527
"""
520528
return self.set_spec(self.CONST_WEB_CONCURRENCY, web_concurrency)
529+
530+
def with_subnet_id(self, subnet_id: str) -> "ModelDeploymentInfrastructure":
531+
"""Sets the subnet id of model deployment.
532+
533+
Parameters
534+
----------
535+
subnet_id : str
536+
The subnet id of model deployment.
537+
538+
Returns
539+
-------
540+
ModelDeploymentInfrastructure
541+
The ModelDeploymentInfrastructure instance (self).
542+
"""
543+
return self.set_spec(self.CONST_SUBNET_ID, subnet_id)
544+
545+
@property
546+
def subnet_id(self) -> str:
547+
"""The model deployment subnet id.
548+
549+
Returns
550+
-------
551+
str
552+
The model deployment subnet id.
553+
"""
554+
return self.get_spec(self.CONST_SUBNET_ID, None)

ads/model/generic_model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,7 @@ def deploy(
19021902
display_name: Optional[str] = None,
19031903
description: Optional[str] = None,
19041904
deployment_instance_shape: Optional[str] = None,
1905+
deployment_instance_subnet_id: Optional[str] = None,
19051906
deployment_instance_count: Optional[int] = None,
19061907
deployment_bandwidth_mbps: Optional[int] = None,
19071908
deployment_log_group_id: Optional[str] = None,
@@ -1950,6 +1951,8 @@ def deploy(
19501951
The description of the model.
19511952
deployment_instance_shape: (str, optional). Default to `VM.Standard2.1`.
19521953
The shape of the instance used for deployment.
1954+
deployment_instance_subnet_id: (str, optional). Default to None.
1955+
The subnet id of the instance used for deployment.
19531956
deployment_instance_count: (int, optional). Defaults to 1.
19541957
The number of instance used for deployment.
19551958
deployment_bandwidth_mbps: (int, optional). Defaults to 10.
@@ -2084,6 +2087,10 @@ def deploy(
20842087
self.properties.deployment_instance_shape
20852088
or existing_infrastructure.shape_name
20862089
)
2090+
.with_subnet_id(
2091+
self.properties.deployment_instance_subnet_id
2092+
or existing_infrastructure.subnet_id
2093+
)
20872094
.with_replica(
20882095
self.properties.deployment_instance_count
20892096
or existing_infrastructure.replica
@@ -2253,6 +2260,7 @@ def prepare_save_deploy(
22532260
deployment_display_name: Optional[str] = None,
22542261
deployment_description: Optional[str] = None,
22552262
deployment_instance_shape: Optional[str] = None,
2263+
deployment_instance_subnet_id: Optional[str] = None,
22562264
deployment_instance_count: Optional[int] = None,
22572265
deployment_bandwidth_mbps: Optional[int] = None,
22582266
deployment_log_group_id: Optional[str] = None,
@@ -2340,6 +2348,8 @@ def prepare_save_deploy(
23402348
The description of the model.
23412349
deployment_instance_shape: (str, optional). Default to `VM.Standard2.1`.
23422350
The shape of the instance used for deployment.
2351+
deployment_instance_subnet_id: (str, optional). Default to None.
2352+
The subnet id of the instance used for deployment.
23432353
deployment_instance_count: (int, optional). Defaults to 1.
23442354
The number of instance used for deployment.
23452355
deployment_bandwidth_mbps: (int, optional). Defaults to 10.
@@ -2481,6 +2491,7 @@ def prepare_save_deploy(
24812491
display_name=deployment_display_name,
24822492
description=deployment_description,
24832493
deployment_instance_shape=self.properties.deployment_instance_shape,
2494+
deployment_instance_subnet_id=self.properties.deployment_instance_subnet_id,
24842495
deployment_instance_count=self.properties.deployment_instance_count,
24852496
deployment_bandwidth_mbps=self.properties.deployment_bandwidth_mbps,
24862497
deployment_log_group_id=self.properties.deployment_log_group_id,

ads/model/model_properties.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ModelProperties(BaseProperties):
2828
remove_existing_artifact: bool = None
2929
overwrite_existing_artifact: bool = None
3030
deployment_instance_shape: str = None
31+
deployment_instance_subnet_id: str = None
3132
deployment_instance_count: int = None
3233
deployment_bandwidth_mbps: int = None
3334
deployment_log_group_id: str = None

tests/unitary/default_setup/model_deployment/test_model_deployment_v2.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
model_deployment_instance_shape_config_details=ModelDeploymentInstanceShapeConfigDetails(
8080
ocpus=10, memory_in_gbs=36
8181
),
82+
subnet_id="fakeid.subnet.oc1.iad.xxx"
8283
),
8384
scaling_policy=FixedSizeScalingPolicy(instance_count=5),
8485
bandwidth_mbps=5,
@@ -128,6 +129,7 @@
128129
"replica": 5,
129130
"shape_name": "VM.Standard.E4.Flex",
130131
"shape_config_details": {"ocpus": 10, "memoryInGBs": 36},
132+
"subnet_id": "fakeid.subnet.oc1.iad.xxx",
131133
"web_concurrency": 10,
132134
"access_log": {
133135
"logGroupId": "fakeid.loggroup.oc1.iad.xxx",
@@ -184,6 +186,7 @@
184186
shapeConfigDetails:
185187
memoryInGBs: 36
186188
ocpus: 10
189+
subnetId: fakeid.subnet.oc1.iad.xxx
187190
replica: 5
188191
bandwidthMbps: 5
189192
webConcurrency: 5
@@ -215,6 +218,7 @@ def initialize_model_deployment(self):
215218
.with_replica(5)
216219
.with_shape_name("VM.Standard.E4.Flex")
217220
.with_shape_config_details(ocpus=10, memory_in_gbs=36)
221+
.with_subnet_id("fakeid.subnet.oc1.iad.xxx")
218222
.with_web_concurrency(10)
219223
.with_access_log(
220224
log_group_id="fakeid.loggroup.oc1.iad.xxx",
@@ -267,6 +271,7 @@ def initialize_model_deployment_from_spec(self):
267271
.with_replica(5)
268272
.with_shape_name("VM.Standard.E4.Flex")
269273
.with_shape_config_details(ocpus=10, memory_in_gbs=36)
274+
.with_subnet_id("fakeid.subnet.oc1.iad.xxx")
270275
.with_web_concurrency(10)
271276
.with_access_log(
272277
log_group_id="fakeid.loggroup.oc1.iad.xxx",
@@ -318,6 +323,7 @@ def initialize_model_deployment_from_kwargs(self):
318323
.with_replica(5)
319324
.with_shape_name("VM.Standard.E4.Flex")
320325
.with_shape_config_details(ocpus=10, memory_in_gbs=36)
326+
.with_subnet_id("fakeid.subnet.oc1.iad.xxx")
321327
.with_web_concurrency(10)
322328
.with_access_log(
323329
log_group_id="fakeid.loggroup.oc1.iad.xxx",
@@ -404,6 +410,7 @@ def test_initialize_model_deployment(self):
404410
"ocpus": 10,
405411
"memoryInGBs": 36,
406412
}
413+
assert temp_infrastructure.subnet_id == "fakeid.subnet.oc1.iad.xxx"
407414
assert temp_infrastructure.replica == 5
408415
assert temp_infrastructure.access_log == {
409416
"logGroupId": "fakeid.loggroup.oc1.iad.xxx",
@@ -461,6 +468,7 @@ def test_model_deployment_to_dict(self):
461468
"replica": 5,
462469
"shapeName": "VM.Standard.E4.Flex",
463470
"shapeConfigDetails": {"ocpus": 10, "memoryInGBs": 36},
471+
"subnetId": "fakeid.subnet.oc1.iad.xxx",
464472
"webConcurrency": 10,
465473
"accessLog": {
466474
"logGroupId": "fakeid.loggroup.oc1.iad.xxx",
@@ -517,6 +525,7 @@ def test_build_model_deployment_configuration_details(self, mock_prepare_artifac
517525
"ocpus": 10,
518526
"memoryInGBs": 36,
519527
},
528+
"subnetId": "fakeid.subnet.oc1.iad.xxx",
520529
},
521530
"modelId": "fakeid.datasciencemodel.oc1.iad.xxx",
522531
"scalingPolicy": {"policyType": "FIXED_SIZE", "instanceCount": 5},
@@ -680,6 +689,7 @@ def test_build_model_deployment_details(self, mock_prepare_artifact):
680689
instance_configuration.model_deployment_instance_shape_config_details.memory_in_gbs
681690
== model_deployment.infrastructure.shape_config_details["memoryInGBs"]
682691
)
692+
assert instance_configuration.subnet_id == model_deployment.infrastructure.subnet_id
683693

684694
scaling_policy = model_configuration_details.scaling_policy
685695
assert isinstance(scaling_policy, FixedSizeScalingPolicy)
@@ -780,6 +790,7 @@ def test_update_from_oci_model(self):
780790
infrastructure.shape_config_details["memoryInGBs"]
781791
== instance_configuration.model_deployment_instance_shape_config_details.memory_in_gbs
782792
)
793+
assert infrastructure.subnet_id == instance_configuration.subnet_id
783794
assert infrastructure.replica == scaling_policy.instance_count
784795

785796
category_log_details = OCI_MODEL_DEPLOYMENT_RESPONSE.category_log_details
@@ -860,6 +871,7 @@ def test_model_deployment_from_yaml(self):
860871
"replica": 5,
861872
"shapeName": "VM.Standard.E4.Flex",
862873
"shapeConfigDetails": {"ocpus": 10, "memoryInGBs": 36},
874+
"subnetId": "fakeid.subnet.oc1.iad.xxx",
863875
"accessLog": {
864876
"logGroupId": "fakeid.loggroup.oc1.iad.xxx",
865877
"logId": "fakeid.log.oc1.iad.xxx",
@@ -1026,6 +1038,7 @@ def test_update_model_deployment_details(self, mock_prepare_artifact):
10261038
instance_configuration.model_deployment_instance_shape_config_details.memory_in_gbs
10271039
== model_deployment.infrastructure.shape_config_details["memoryInGBs"]
10281040
)
1041+
assert instance_configuration.subnet_id == model_deployment.infrastructure.subnet_id
10291042

10301043
scaling_policy = model_configuration_details.scaling_policy
10311044
assert isinstance(scaling_policy, FixedSizeScalingPolicy)
@@ -1077,6 +1090,7 @@ def test_extract_from_oci_model(self):
10771090
"replica": 5,
10781091
"shapeName": "VM.Standard.E4.Flex",
10791092
"shapeConfigDetails": {"ocpus": 10, "memoryInGBs": 36},
1093+
"subnetId": "fakeid.subnet.oc1.iad.xxx",
10801094
"accessLog": {
10811095
"logGroupId": "fakeid.loggroup.oc1.iad.xxx",
10821096
"logId": "fakeid.log.oc1.iad.xxx",

tests/unitary/with_extras/model/test_generic_model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ def test_deploy_success(self, mock_deploy):
520520
infrastructure = ModelDeploymentInfrastructure(
521521
**{
522522
"shape_name": "test_deployment_instance_shape",
523+
"subnet_id": "test_deployment_subnet_id",
523524
"replica": 10,
524525
"bandwidth_mbps": 100,
525526
"shape_config_details": {"memory_in_gbs": 10, "ocpus": 1},
@@ -560,6 +561,7 @@ def test_deploy_success(self, mock_deploy):
560561
"display_name": "test_display_name",
561562
"description": "test_description",
562563
"deployment_instance_shape": "test_deployment_instance_shape",
564+
"deployment_instance_subnet_id": "test_deployment_subnet_id",
563565
"deployment_instance_count": 10,
564566
"deployment_bandwidth_mbps": 100,
565567
"deployment_memory_in_gbs": 10,
@@ -604,6 +606,7 @@ def test_deploy_success(self, mock_deploy):
604606
"ocpus": input_dict["deployment_ocpus"],
605607
"memory_in_gbs": input_dict["deployment_memory_in_gbs"],
606608
}
609+
assert result.infrastructure.subnet_id == input_dict["deployment_instance_subnet_id"]
607610
assert result.runtime.image == input_dict["deployment_image"]
608611
assert result.runtime.entrypoint == input_dict["entrypoint"]
609612
assert result.runtime.server_port == input_dict["server_port"]
@@ -1328,6 +1331,7 @@ def test__to_yaml(self):
13281331
"display_name": "fake_deployment_display_name",
13291332
"description": None,
13301333
"deployment_instance_shape": None,
1334+
"deployment_instance_subnet_id": None,
13311335
"deployment_instance_count": None,
13321336
"deployment_bandwidth_mbps": None,
13331337
"deployment_log_group_id": None,
@@ -1367,6 +1371,7 @@ def test__to_yaml(self):
13671371
"deployment_display_name": "fake_deployment_display_name",
13681372
"deployment_description": None,
13691373
"deployment_instance_shape": None,
1374+
"deployment_instance_subnet_id": None,
13701375
"deployment_instance_count": None,
13711376
"deployment_bandwidth_mbps": None,
13721377
"deployment_log_group_id": None,
@@ -1417,6 +1422,7 @@ def test__to_yaml(self):
14171422
"display_name": "fake_deployment_display_name",
14181423
"description": None,
14191424
"deployment_instance_shape": None,
1425+
"deployment_instance_subnet_id": None,
14201426
"deployment_instance_count": None,
14211427
"deployment_bandwidth_mbps": None,
14221428
"deployment_log_group_id": None,
@@ -1456,6 +1462,7 @@ def test__to_yaml(self):
14561462
"deployment_display_name": "fake_deployment_display_name",
14571463
"deployment_description": "fake_deployment_description",
14581464
"deployment_instance_shape": "2.1",
1465+
"deployment_instance_subnet_id": "ocid1.subnet.oc1.iad.<unique_ocid>",
14591466
"deployment_instance_count": 1,
14601467
"deployment_bandwidth_mbps": 10,
14611468
"deployment_log_group_id": "ocid1.loggroup.oc1.iad.<unique_ocid>",
@@ -1512,6 +1519,7 @@ def test__to_yaml(self):
15121519
"deployment_instance_shape": "2.1",
15131520
"deployment_instance_count": 1,
15141521
"deployment_bandwidth_mbps": 10,
1522+
"deployment_instance_subnet_id": "ocid1.subnet.oc1.iad.<unique_ocid>",
15151523
"deployment_log_group_id": "ocid1.loggroup.oc1.iad.<unique_ocid>",
15161524
"deployment_access_log_id": "ocid1.log.oc1.iad.<unique_ocid>",
15171525
"deployment_predict_log_id": "ocid1.log.oc1.iad.<unique_ocid>",
@@ -1553,6 +1561,7 @@ def test__to_yaml(self):
15531561
"deployment_display_name": "fake_deployment_display_name",
15541562
"deployment_description": "fake_deployment_description",
15551563
"deployment_instance_shape": "2.1",
1564+
"deployment_instance_subnet_id": "ocid1.subnet.oc1.iad.<unique_ocid>",
15561565
"deployment_instance_count": 1,
15571566
"deployment_bandwidth_mbps": 10,
15581567
"deployment_log_group_id": "ocid",
@@ -1615,6 +1624,7 @@ def test__to_yaml(self):
16151624
"deployment_instance_shape": "2.1",
16161625
"deployment_instance_count": 1,
16171626
"deployment_bandwidth_mbps": 10,
1627+
"deployment_instance_subnet_id": "ocid1.subnet.oc1.iad.<unique_ocid>",
16181628
"deployment_log_group_id": "ocid",
16191629
"deployment_access_log_id": "ocid",
16201630
"deployment_predict_log_id": "ocid",
@@ -1685,6 +1695,7 @@ def test_prepare_save_deploy_with_default_display_name(
16851695
"display_name": utils.get_random_name_for_resource(),
16861696
"description": None,
16871697
"deployment_instance_shape": None,
1698+
"deployment_instance_subnet_id": None,
16881699
"deployment_instance_count": None,
16891700
"deployment_bandwidth_mbps": None,
16901701
"deployment_memory_in_gbs": None,

0 commit comments

Comments
 (0)