Skip to content

Commit 06dd598

Browse files
authored
Fix for JIRA ODSC-77609. (#1272)
1 parent 9e141cb commit 06dd598

File tree

4 files changed

+44
-39
lines changed

4 files changed

+44
-39
lines changed

ads/model/runtime/utils.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
66

77
import json
8+
import logging
89
import os
9-
from functools import lru_cache
1010
from typing import Dict, Tuple
11-
import logging
1211

1312
import fsspec
14-
import requests
1513
import yaml
1614
from cerberus import DocumentError, Validator
1715

1816
from ads.common.object_storage_details import ObjectStorageDetails
19-
from ads.common.utils import PAR_LINK
2017

2118
MODEL_PROVENANCE_SCHEMA_PATH = os.path.join(
2219
os.path.dirname(os.path.abspath(__file__)),
@@ -127,9 +124,10 @@ def _get_index_json_through_bucket(
127124
service_packs = json.loads(f.read())
128125
service_pack_list = service_packs.get(SERVICE_PACKS)
129126
except Exception as e:
130-
logging.warn(e)
131-
logging.warn(
132-
"Failed to retrieve the full conda pack path from slug. Pass conda pack path 'oci://<bucketname>@<namespace>/<path_to_conda>' instead of slug."
127+
logging.error(
128+
f"Error occurred in attempt to extract the list of the service conda environments "
129+
f"from the object storage for bucket '{bucketname}' and namespace '{namespace}'. "
130+
f"Please make sure that you've provided correct bucket and namespace."
133131
)
134132
return service_pack_list
135133

@@ -159,22 +157,21 @@ def get_service_packs(
159157
"""
160158
service_pack_path_mapping = {}
161159
service_pack_slug_mapping = {}
160+
162161
try:
163-
response = requests.request("GET", PAR_LINK)
164-
165-
# if there is internet
166-
if response.ok:
167-
service_pack_list = response.json().get(SERVICE_PACKS)
168-
# response not good.
169-
else:
170-
service_pack_list = _get_index_json_through_bucket(
171-
namespace=namespace, bucketname=bucketname, auth=auth
172-
)
173-
except Exception as e:
174-
# not internet
175162
service_pack_list = _get_index_json_through_bucket(
176-
namespace=namespace, bucketname=bucketname, auth=auth
163+
namespace=namespace,
164+
bucketname=bucketname,
165+
auth=auth
166+
)
167+
except Exception as e:
168+
logging.error(
169+
"Failed to fetch service packs index from namespace '%s' and bucket '%s': %s",
170+
namespace,
171+
bucketname,
172+
str(e),
177173
)
174+
return service_pack_path_mapping, service_pack_slug_mapping
178175

179176
for service_pack in service_pack_list:
180177
# Here we need to replace the namespace and bucketname

tests/unitary/with_extras/evaluator/test_evaluator.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@
66
"""
77
Contains tests for ads.evaluations.evaluator
88
"""
9-
import pytest
10-
import unittest
119
import tempfile
12-
from ads.evaluations.evaluator import Evaluator
10+
import unittest
1311

14-
from sklearn.datasets import make_regression
15-
from sklearn.datasets import make_classification
16-
from sklearn.model_selection import train_test_split
12+
import pandas as pd
13+
import pytest
1714
from lightgbm import LGBMClassifier, LGBMRegressor
18-
from sklearn.tree import DecisionTreeClassifier
15+
from sklearn.datasets import make_classification, make_regression
1916
from sklearn.linear_model import LinearRegression
20-
import pandas as pd
17+
from sklearn.model_selection import train_test_split
18+
from sklearn.tree import DecisionTreeClassifier
19+
2120
from ads.common.model_metadata import UseCaseType
21+
from ads.evaluations.evaluator import Evaluator
2222
from ads.model.framework.lightgbm_model import LightGBMModel
2323
from ads.model.framework.sklearn_model import SklearnModel
2424

25+
DEFAULT_PYTHON_VERSION = "3.12"
2526

2627
def test_model_types():
2728
with pytest.raises(ValueError):
@@ -39,6 +40,7 @@ def test_pandas_input():
3940
model.prepare(
4041
inference_conda_env="generalml_p38_cpu_v1",
4142
training_conda_env="generalml_p38_cpu_v1",
43+
inference_python_version=DEFAULT_PYTHON_VERSION,
4244
X_sample=X,
4345
y_sample=y,
4446
use_case_type=UseCaseType.MULTINOMIAL_CLASSIFICATION,
@@ -100,6 +102,7 @@ def train_eval_model(self, data, model, use_case):
100102
my_model.prepare(
101103
inference_conda_env="generalml_p38_cpu_v1",
102104
training_conda_env="generalml_p38_cpu_v1",
105+
inference_python_version=DEFAULT_PYTHON_VERSION,
103106
X_sample=X_test,
104107
y_sample=y_test,
105108
use_case_type=use_case,

tests/unitary/with_extras/model/test_generic_model.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
from ads.model.deployment.common.utils import State as ModelDeploymentState
4141
from ads.model.generic_model import (
4242
_ATTRIBUTES_TO_SHOW_,
43+
ArtifactsNotAvailableError,
4344
GenericModel,
4445
NotActiveDeploymentError,
45-
ArtifactsNotAvailableError,
4646
SummaryStatus,
4747
_prepare_artifact_dir,
4848
)
@@ -165,7 +165,7 @@
165165

166166
INFERENCE_CONDA_ENV = "oci://bucket@namespace/<path_to_service_pack>"
167167
TRAINING_CONDA_ENV = "oci://bucket@namespace/<path_to_service_pack>"
168-
DEFAULT_PYTHON_VERSION = "3.8"
168+
DEFAULT_PYTHON_VERSION = "3.12"
169169
MODEL_FILE_NAME = "fake_model_name"
170170
FAKE_MD_URL = "http://<model-deployment-url>"
171171

@@ -257,7 +257,8 @@ def test__handle_model_file_name_raise_error(self):
257257
def test_prepare(self, mock_signer):
258258
"""prepare a trained model."""
259259
self.generic_model.prepare(
260-
"oci://service-conda-packs@ociodscdev/service_pack/cpu/General_Machine_Learning_for_CPUs/1.0/mlcpuv1",
260+
inference_conda_env="oci://service-conda-packs@ociodscdev/service_pack/cpu/General_Machine_Learning_for_CPUs/1.0/mlcpuv1",
261+
inference_python_version=DEFAULT_PYTHON_VERSION,
261262
model_file_name="fake_model_name",
262263
)
263264

@@ -1449,7 +1450,8 @@ def test__to_dict_not_prepared(self):
14491450
@patch("ads.common.auth.default_signer")
14501451
def test__to_dict_prepared(self, moxk_signer):
14511452
self.generic_model.prepare(
1452-
"oci://service-conda-packs@ociodscdev/service_pack/cpu/General_Machine_Learning_for_CPUs/1.0/mlcpuv1"
1453+
inference_conda_env="oci://service-conda-packs@ociodscdev/service_pack/cpu/General_Machine_Learning_for_CPUs/1.0/mlcpuv1",
1454+
inference_python_version=DEFAULT_PYTHON_VERSION
14531455
)
14541456
dictionary = self.generic_model._to_dict()
14551457
for key in _ATTRIBUTES_TO_SHOW_:
@@ -2255,7 +2257,7 @@ class TestCommonMethods:
22552257
def test__prepare_artifact_dir(
22562258
self, mock_signer, mock_mkdtemp, test_value, expected_value
22572259
):
2258-
"""Ensures that artifact dir name can be benerated propertly."""
2260+
"""Ensures that artifact dir name can be generated propertly."""
22592261

22602262
assert (
22612263
_prepare_artifact_dir(test_value) == expected_value

tests/unitary/with_extras/model/test_model_metadata_mixin.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
# Copyright (c) 2022, 2023 Oracle and/or its affiliates.
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
55

6+
import os
7+
import shutil
68
from unittest.mock import patch
9+
710
import numpy as np
811
import pytest
12+
import sklearn
13+
import xgboost
914
from sklearn import datasets, linear_model
1015

11-
from ads.model.generic_model import GenericModel
16+
from ads.feature_engineering.schema import Schema
1217
from ads.model.framework.sklearn_model import SklearnModel
1318
from ads.model.framework.xgboost_model import XGBoostModel
14-
from ads.feature_engineering.schema import Schema
15-
import sklearn
16-
import os
17-
import shutil
18-
import xgboost
19+
from ads.model.generic_model import GenericModel
1920

21+
DEFAULT_PYTHON_VERSION = "3.12"
2022

2123
class TestMetadataMixin:
2224
def setup_method(cls):
@@ -49,6 +51,7 @@ def test_metadata_generic_model(self):
4951
model.prepare(
5052
inference_conda_env="dataexpl_p37_cpu_v3",
5153
namespace="ociodscdev",
54+
inference_python_version=DEFAULT_PYTHON_VERSION,
5255
model_file_name="model.joblib",
5356
force_overwrite=True,
5457
)

0 commit comments

Comments
 (0)