Skip to content

Commit

Permalink
fixed ModelDeployment.from_id failed to construct properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkang111 committed Sep 8, 2023
1 parent a763f81 commit 6b559e2
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions ads/model/deployment/model_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,8 @@ def from_id(cls, id: str) -> "ModelDeployment":
ModelDeployment
The ModelDeployment instance (self).
"""
return cls()._update_from_oci_model(OCIDataScienceModelDeployment.from_id(id))
oci_model = OCIDataScienceModelDeployment.from_id(id)
return cls(properties=oci_model)._update_from_oci_model(oci_model)

@classmethod
def from_dict(cls, obj_dict: Dict) -> "ModelDeployment":
Expand Down Expand Up @@ -1503,7 +1504,9 @@ def _build_model_deployment_details(self) -> CreateModelDeploymentDetails:
**create_model_deployment_details
).to_oci_model(CreateModelDeploymentDetails)

def _update_model_deployment_details(self, **kwargs) -> UpdateModelDeploymentDetails:
def _update_model_deployment_details(
self, **kwargs
) -> UpdateModelDeploymentDetails:
"""Builds UpdateModelDeploymentDetails from model deployment instance.
Returns
Expand All @@ -1527,7 +1530,7 @@ def _update_model_deployment_details(self, **kwargs) -> UpdateModelDeploymentDet
return OCIDataScienceModelDeployment(
**update_model_deployment_details
).to_oci_model(UpdateModelDeploymentDetails)

def _update_spec(self, **kwargs) -> "ModelDeployment":
"""Updates model deployment specs from kwargs.
Expand All @@ -1542,7 +1545,7 @@ def _update_spec(self, **kwargs) -> "ModelDeployment":
Model deployment freeform tags
defined_tags: (dict)
Model deployment defined tags
Additional kwargs arguments.
Can be any attribute that `ads.model.deployment.ModelDeploymentCondaRuntime`, `ads.model.deployment.ModelDeploymentContainerRuntime`
and `ads.model.deployment.ModelDeploymentInfrastructure` accepts.
Expand All @@ -1559,20 +1562,22 @@ def _update_spec(self, **kwargs) -> "ModelDeployment":
specs = {
"self": self._spec,
"runtime": self.runtime._spec,
"infrastructure": self.infrastructure._spec
"infrastructure": self.infrastructure._spec,
}
sub_set = {
self.infrastructure.CONST_ACCESS_LOG,
self.infrastructure.CONST_PREDICT_LOG,
self.infrastructure.CONST_SHAPE_CONFIG_DETAILS
self.infrastructure.CONST_SHAPE_CONFIG_DETAILS,
}
for spec_value in specs.values():
for key in spec_value:
if key in converted_specs:
if key in sub_set:
for sub_key in converted_specs[key]:
converted_sub_key = ads_utils.snake_to_camel(sub_key)
spec_value[key][converted_sub_key] = converted_specs[key][sub_key]
spec_value[key][converted_sub_key] = converted_specs[key][
sub_key
]
else:
spec_value[key] = copy.deepcopy(converted_specs[key])
self = (
Expand Down Expand Up @@ -1616,14 +1621,14 @@ def _build_model_deployment_configuration_details(self) -> Dict:
infrastructure.CONST_MEMORY_IN_GBS: infrastructure.shape_config_details.get(
"memory_in_gbs", None
)
or infrastructure.shape_config_details.get(
"memoryInGBs", None
)
or infrastructure.shape_config_details.get("memoryInGBs", None)
or DEFAULT_MEMORY_IN_GBS,
}

if infrastructure.subnet_id:
instance_configuration[infrastructure.CONST_SUBNET_ID] = infrastructure.subnet_id
instance_configuration[
infrastructure.CONST_SUBNET_ID
] = infrastructure.subnet_id

scaling_policy = {
infrastructure.CONST_POLICY_TYPE: "FIXED_SIZE",
Expand All @@ -1638,13 +1643,11 @@ def _build_model_deployment_configuration_details(self) -> Dict:

model_id = runtime.model_uri
if not model_id.startswith("ocid"):

from ads.model.datascience_model import DataScienceModel

dsc_model = DataScienceModel(
name=self.display_name,
compartment_id=self.infrastructure.compartment_id
or COMPARTMENT_OCID,
compartment_id=self.infrastructure.compartment_id or COMPARTMENT_OCID,
project_id=self.infrastructure.project_id or PROJECT_OCID,
artifact=runtime.model_uri,
).create(
Expand All @@ -1653,7 +1656,7 @@ def _build_model_deployment_configuration_details(self) -> Dict:
region=runtime.region,
overwrite_existing_artifact=runtime.overwrite_existing_artifact,
remove_existing_artifact=runtime.remove_existing_artifact,
timeout=runtime.timeout
timeout=runtime.timeout,
)
model_id = dsc_model.id

Expand Down

0 comments on commit 6b559e2

Please sign in to comment.