Skip to content

Commit 45e9014

Browse files
Addressing review comments
1 parent 40456fe commit 45e9014

File tree

4 files changed

+41
-36
lines changed

4 files changed

+41
-36
lines changed

ads/common/utils.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
OptionalDependency,
4444
runtime_dependency,
4545
)
46-
from ads.common.extended_enum import ExtendedEnum
4746
from ads.common.object_storage_details import ObjectStorageDetails
4847
from ads.common.oci_client import OCIClientFactory
4948
from ads.common.word_lists import adjectives, animals
@@ -86,13 +85,6 @@
8685
)
8786

8887

89-
# Metadata artifact path type can be either local path or OSS path. It can also be the content itself.
90-
class MetadataArtifactPathType(ExtendedEnum):
91-
LOCAL = "local"
92-
OSS = "oss"
93-
CONTENT = "content"
94-
95-
9688
# sqlalchemy engines
9789
_engines = {}
9890

ads/model/common/utils.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*--
32

43
# Copyright (c) 2022, 2023 Oracle and/or its affiliates.
54
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
65

76
import json
87
import os
98
import tempfile
10-
import yaml
119
from typing import Any, Dict, Optional
1210
from zipfile import ZipFile
13-
from ads.common import utils
1411

12+
import yaml
13+
14+
from ads.common import utils
15+
from ads.common.extended_enum import ExtendedEnum
1516

1617
DEPRECATE_AS_ONNX_WARNING = "This attribute `as_onnx` will be deprecated in the future. You can choose specific format by setting `model_save_serializer`."
1718
DEPRECATE_USE_TORCH_SCRIPT_WARNING = "This attribute `use_torch_script` will be deprecated in the future. You can choose specific format by setting `model_save_serializer`."
1819

1920

21+
class MetadataArtifactPathType(ExtendedEnum):
22+
"""
23+
Enum for defining metadata artifact path type.
24+
Can be either local path or OSS path. It can also be the content itself.
25+
"""
26+
27+
LOCAL = "local"
28+
OSS = "oss"
29+
CONTENT = "content"
30+
31+
2032
def _extract_locals(
2133
locals: Dict[str, Any], filter_out_nulls: Optional[bool] = True
2234
) -> Dict[str, Any]:

ads/model/datascience_model.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
SmallArtifactDownloader,
3535
)
3636
from ads.model.artifact_uploader import LargeArtifactUploader, SmallArtifactUploader
37+
from ads.model.common.utils import MetadataArtifactPathType
3738
from ads.model.model_metadata import (
3839
MetadataCustomCategory,
3940
ModelCustomMetadata,
@@ -2232,7 +2233,7 @@ def create_custom_metadata_artifact(
22322233
self,
22332234
metadata_key_name: str,
22342235
artifact_path_or_content: str,
2235-
path_type: utils.MetadataArtifactPathType = utils.MetadataArtifactPathType.LOCAL,
2236+
path_type: MetadataArtifactPathType = MetadataArtifactPathType.LOCAL,
22362237
) -> ModelMetadataArtifactDetails:
22372238
"""Creates model custom metadata artifact for specified model.
22382239
@@ -2244,8 +2245,8 @@ def create_custom_metadata_artifact(
22442245
artifact_path_or_content: str
22452246
The model custom metadata artifact path to be upload. It can also be the actual content of the custom metadata
22462247
2247-
path_type: utils.MetadataArtifactPathType
2248-
Can be either of utils.MetadataArtifactPathType.LOCAL , utils.MetadataArtifactPathType.OSS , utils.MetadataArtifactPathType.CONTENT
2248+
path_type: MetadataArtifactPathType
2249+
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
22492250
Specifies what type of path is to be provided for metadata artifact.
22502251
Can be either local , oss or the actual content itself
22512252
@@ -2276,7 +2277,7 @@ def create_defined_metadata_artifact(
22762277
self,
22772278
metadata_key_name: str,
22782279
artifact_path_or_content: str,
2279-
path_type: utils.MetadataArtifactPathType = utils.MetadataArtifactPathType.LOCAL,
2280+
path_type: MetadataArtifactPathType = MetadataArtifactPathType.LOCAL,
22802281
) -> ModelMetadataArtifactDetails:
22812282
"""Creates model defined metadata artifact for specified model.
22822283
@@ -2288,8 +2289,8 @@ def create_defined_metadata_artifact(
22882289
artifact_path_or_content: str
22892290
The model defined metadata artifact path to be upload. It can also be the actual content of the defined metadata
22902291
2291-
path_type: utils.MetadataArtifactPathType
2292-
Can be either of utils.MetadataArtifactPathType.LOCAL , utils.MetadataArtifactPathType.OSS , utils.MetadataArtifactPathType.CONTENT
2292+
path_type: MetadataArtifactPathType
2293+
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
22932294
Specifies what type of path is to be provided for metadata artifact.
22942295
Can be either local , oss or the actual content itself
22952296
@@ -2319,7 +2320,7 @@ def update_custom_metadata_artifact(
23192320
self,
23202321
metadata_key_name: str,
23212322
artifact_path_or_content: str,
2322-
path_type: utils.MetadataArtifactPathType = utils.MetadataArtifactPathType.LOCAL,
2323+
path_type: MetadataArtifactPathType = MetadataArtifactPathType.LOCAL,
23232324
) -> ModelMetadataArtifactDetails:
23242325
"""Update model custom metadata artifact for specified model.
23252326
@@ -2331,8 +2332,8 @@ def update_custom_metadata_artifact(
23312332
artifact_path_or_content: str
23322333
The model custom metadata artifact path. It can also be the actual content of the custom metadata
23332334
2334-
path_type: utils.MetadataArtifactPathType
2335-
Can be either of utils.MetadataArtifactPathType.LOCAL , utils.MetadataArtifactPathType.OSS , utils.MetadataArtifactPathType.CONTENT
2335+
path_type: MetadataArtifactPathType
2336+
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
23362337
Specifies what type of path is to be provided for metadata artifact.
23372338
Can be either local , oss or the actual content itself
23382339
@@ -2363,7 +2364,7 @@ def update_defined_metadata_artifact(
23632364
self,
23642365
metadata_key_name: str,
23652366
artifact_path_or_content: str,
2366-
path_type: utils.MetadataArtifactPathType = utils.MetadataArtifactPathType.LOCAL,
2367+
path_type: MetadataArtifactPathType = MetadataArtifactPathType.LOCAL,
23672368
) -> ModelMetadataArtifactDetails:
23682369
"""Update model defined metadata artifact for specified model.
23692370
@@ -2375,8 +2376,8 @@ def update_defined_metadata_artifact(
23752376
artifact_path_or_content: str
23762377
The model defined metadata artifact path. It can also be the actual content of the defined metadata
23772378
2378-
path_type: utils.MetadataArtifactPathType
2379-
Can be either of utils.MetadataArtifactPathType.LOCAL , utils.MetadataArtifactPathType.OSS , utils.MetadataArtifactPathType.CONTENT
2379+
path_type: MetadataArtifactPathType
2380+
Can be either of MetadataArtifactPathType.LOCAL , MetadataArtifactPathType.OSS , MetadataArtifactPathType.CONTENT
23802381
Specifies what type of path is to be provided for metadata artifact.
23812382
Can be either local , oss or the actual content itself
23822383

ads/model/service/oci_datascience_model.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from oci.exceptions import ServiceError
2222
from requests.structures import CaseInsensitiveDict
2323

24-
from ads.common import utils
2524
from ads.common.auth import default_signer
2625
from ads.common.object_storage_details import ObjectStorageDetails
2726
from ads.common.oci_datascience import OCIDataScienceMixin
@@ -30,6 +29,7 @@
3029
from ads.common.serializer import DataClassSerializable
3130
from ads.common.utils import extract_region, read_file, text_sanitizer
3231
from ads.common.work_request import DataScienceWorkRequest
32+
from ads.model.common.utils import MetadataArtifactPathType
3333
from ads.model.deployment import ModelDeployment
3434

3535
logger = logging.getLogger(__name__)
@@ -620,7 +620,7 @@ def is_model_created_by_reference(self):
620620
return False
621621

622622
def get_metadata_content(
623-
self, artifact_path_or_content: str, path_type: utils.MetadataArtifactPathType
623+
self, artifact_path_or_content: str, path_type: MetadataArtifactPathType
624624
):
625625
"""
626626
returns the content of the metadata artifact
@@ -637,10 +637,10 @@ def get_metadata_content(
637637
metadata artifact content
638638
"""
639639

640-
if path_type == utils.MetadataArtifactPathType.CONTENT:
640+
if path_type == MetadataArtifactPathType.CONTENT:
641641
return artifact_path_or_content
642642

643-
elif path_type == utils.MetadataArtifactPathType.LOCAL:
643+
elif path_type == MetadataArtifactPathType.LOCAL:
644644
if not utils.is_path_exists(artifact_path_or_content):
645645
raise FileNotFoundError(
646646
f"File not found: {artifact_path_or_content} . "
@@ -652,7 +652,7 @@ def get_metadata_content(
652652

653653
return contents
654654

655-
elif path_type == utils.MetadataArtifactPathType.OSS:
655+
elif path_type == MetadataArtifactPathType.OSS:
656656
if not utils.is_path_exists(artifact_path_or_content):
657657
raise FileNotFoundError(f"File not found: {artifact_path_or_content}")
658658

@@ -670,7 +670,7 @@ def create_custom_metadata_artifact(
670670
self,
671671
metadata_key_name: str,
672672
artifact_path: str,
673-
path_type: utils.MetadataArtifactPathType,
673+
path_type: MetadataArtifactPathType,
674674
) -> ModelMetadataArtifactDetails:
675675
"""Creates model custom metadata artifact for specified model.
676676
@@ -682,7 +682,7 @@ def create_custom_metadata_artifact(
682682
artifact_path: str
683683
The model custom metadata artifact path to be upload.
684684
685-
path_type: utils.MetadataArtifactPathType
685+
path_type: MetadataArtifactPathType
686686
can be one of local , oss or actual content itself
687687
688688
Returns
@@ -723,7 +723,7 @@ def create_defined_metadata_artifact(
723723
self,
724724
metadata_key_name: str,
725725
artifact_path: str,
726-
path_type: utils.MetadataArtifactPathType,
726+
path_type: MetadataArtifactPathType,
727727
) -> ModelMetadataArtifactDetails:
728728
"""Creates model defined metadata artifact for specified model.
729729
@@ -735,7 +735,7 @@ def create_defined_metadata_artifact(
735735
artifact_path: str
736736
The model custom metadata artifact path to be upload.
737737
738-
path_type: utils.MetadataArtifactPathType
738+
path_type: MetadataArtifactPathType
739739
can be one of local , oss or actual content itself.
740740
741741
Returns
@@ -776,7 +776,7 @@ def update_defined_metadata_artifact(
776776
self,
777777
metadata_key_name: str,
778778
artifact_path: str,
779-
path_type: utils.MetadataArtifactPathType,
779+
path_type: MetadataArtifactPathType,
780780
) -> ModelMetadataArtifactDetails:
781781
"""Update model defined metadata artifact for specified model.
782782
@@ -788,7 +788,7 @@ def update_defined_metadata_artifact(
788788
artifact_path: str
789789
The model defined metadata artifact path to be upload.
790790
791-
path_type:utils.MetadataArtifactPathType
791+
path_type:MetadataArtifactPathType
792792
can be one of local , oss or actual content itself.
793793
Returns
794794
-------
@@ -828,7 +828,7 @@ def update_custom_metadata_artifact(
828828
self,
829829
metadata_key_name: str,
830830
artifact_path: str,
831-
path_type: utils.MetadataArtifactPathType,
831+
path_type: MetadataArtifactPathType,
832832
) -> ModelMetadataArtifactDetails:
833833
"""Update model custom metadata artifact for specified model.
834834
@@ -840,7 +840,7 @@ def update_custom_metadata_artifact(
840840
artifact_path: str
841841
The model custom metadata artifact path to be upload.
842842
843-
path_type: utils.MetadataArtifactPathType
843+
path_type: MetadataArtifactPathType
844844
can be one of local , oss or actual content itself.
845845
846846
Returns

0 commit comments

Comments
 (0)