From 782e0b60e1d1784a098e395edb63ad871ef7edd7 Mon Sep 17 00:00:00 2001 From: Liz Johnson Date: Wed, 17 Sep 2025 15:14:36 -0700 Subject: [PATCH 1/4] init code for fix --- ads/model/runtime/utils.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/ads/model/runtime/utils.py b/ads/model/runtime/utils.py index 979445bc1..e386d7b0b 100644 --- a/ads/model/runtime/utils.py +++ b/ads/model/runtime/utils.py @@ -5,18 +5,15 @@ # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ import json +import logging import os -from functools import lru_cache from typing import Dict, Tuple -import logging import fsspec -import requests import yaml from cerberus import DocumentError, Validator from ads.common.object_storage_details import ObjectStorageDetails -from ads.common.utils import PAR_LINK MODEL_PROVENANCE_SCHEMA_PATH = os.path.join( os.path.dirname(os.path.abspath(__file__)), @@ -127,8 +124,8 @@ def _get_index_json_through_bucket( service_packs = json.loads(f.read()) service_pack_list = service_packs.get(SERVICE_PACKS) except Exception as e: - logging.warn(e) - logging.warn( + logging.warning(e) + logging.warning( "Failed to retrieve the full conda pack path from slug. Pass conda pack path 'oci://@/' instead of slug." ) return service_pack_list @@ -160,21 +157,15 @@ def get_service_packs( service_pack_path_mapping = {} service_pack_slug_mapping = {} try: - response = requests.request("GET", PAR_LINK) - - # if there is internet - if response.ok: - service_pack_list = response.json().get(SERVICE_PACKS) - # response not good. - else: - service_pack_list = _get_index_json_through_bucket( - namespace=namespace, bucketname=bucketname, auth=auth - ) - except Exception as e: - # not internet + logging.info("Obtaining service packs through bucket.") service_pack_list = _get_index_json_through_bucket( namespace=namespace, bucketname=bucketname, auth=auth ) + except Exception as e: + # not internet + logging.warning(e) + logging.warning("Failed to obtain service packs through bucket. Please ensure internet connection.") + for service_pack in service_pack_list: # Here we need to replace the namespace and bucketname From aa23f2504fcd21b06fa3916a217533aa73db2881 Mon Sep 17 00:00:00 2001 From: Liz Johnson Date: Wed, 17 Sep 2025 15:49:39 -0700 Subject: [PATCH 2/4] addressed comments --- ads/model/runtime/utils.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ads/model/runtime/utils.py b/ads/model/runtime/utils.py index e386d7b0b..6a3f3ad77 100644 --- a/ads/model/runtime/utils.py +++ b/ads/model/runtime/utils.py @@ -124,9 +124,10 @@ def _get_index_json_through_bucket( service_packs = json.loads(f.read()) service_pack_list = service_packs.get(SERVICE_PACKS) except Exception as e: - logging.warning(e) - logging.warning( - "Failed to retrieve the full conda pack path from slug. Pass conda pack path 'oci://@/' instead of slug." + logging.error( + f"Error occurred in attempt to extract the list of the service conda environments " + f"from the object storage for bucket '{bucketname}' and namespace '{namespace}'. " + f"Please make sure that you've provided correct bucket and namespace." ) return service_pack_list @@ -156,16 +157,21 @@ def get_service_packs( """ service_pack_path_mapping = {} service_pack_slug_mapping = {} + try: - logging.info("Obtaining service packs through bucket.") service_pack_list = _get_index_json_through_bucket( - namespace=namespace, bucketname=bucketname, auth=auth + namespace=namespace, + bucketname=bucketname, + auth=auth ) except Exception as e: - # not internet - logging.warning(e) - logging.warning("Failed to obtain service packs through bucket. Please ensure internet connection.") - + logging.error( + "Failed to fetch service packs index from namespace '%s' and bucket '%s': %s", + namespace, + bucketname, + str(e), + ) + return service_pack_path_mapping, service_pack_slug_mapping for service_pack in service_pack_list: # Here we need to replace the namespace and bucketname From 07dc35bdb6eea8de33805f1808ff24dcd718a5f3 Mon Sep 17 00:00:00 2001 From: Liz Johnson Date: Thu, 18 Sep 2025 14:15:22 -0700 Subject: [PATCH 3/4] fixed some unit test issues --- .../unitary/with_extras/model/test_generic_model.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/unitary/with_extras/model/test_generic_model.py b/tests/unitary/with_extras/model/test_generic_model.py index c070c606e..20c675749 100644 --- a/tests/unitary/with_extras/model/test_generic_model.py +++ b/tests/unitary/with_extras/model/test_generic_model.py @@ -40,9 +40,9 @@ from ads.model.deployment.common.utils import State as ModelDeploymentState from ads.model.generic_model import ( _ATTRIBUTES_TO_SHOW_, + ArtifactsNotAvailableError, GenericModel, NotActiveDeploymentError, - ArtifactsNotAvailableError, SummaryStatus, _prepare_artifact_dir, ) @@ -165,7 +165,7 @@ INFERENCE_CONDA_ENV = "oci://bucket@namespace/" TRAINING_CONDA_ENV = "oci://bucket@namespace/" -DEFAULT_PYTHON_VERSION = "3.8" +DEFAULT_PYTHON_VERSION = "3.12" MODEL_FILE_NAME = "fake_model_name" FAKE_MD_URL = "http://" @@ -257,7 +257,8 @@ def test__handle_model_file_name_raise_error(self): def test_prepare(self, mock_signer): """prepare a trained model.""" self.generic_model.prepare( - "oci://service-conda-packs@ociodscdev/service_pack/cpu/General_Machine_Learning_for_CPUs/1.0/mlcpuv1", + inference_conda_env="oci://service-conda-packs@ociodscdev/service_pack/cpu/General_Machine_Learning_for_CPUs/1.0/mlcpuv1", + inference_python_version=DEFAULT_PYTHON_VERSION, model_file_name="fake_model_name", ) @@ -1449,7 +1450,8 @@ def test__to_dict_not_prepared(self): @patch("ads.common.auth.default_signer") def test__to_dict_prepared(self, moxk_signer): self.generic_model.prepare( - "oci://service-conda-packs@ociodscdev/service_pack/cpu/General_Machine_Learning_for_CPUs/1.0/mlcpuv1" + inference_conda_env="oci://service-conda-packs@ociodscdev/service_pack/cpu/General_Machine_Learning_for_CPUs/1.0/mlcpuv1", + inference_python_version=DEFAULT_PYTHON_VERSION ) dictionary = self.generic_model._to_dict() for key in _ATTRIBUTES_TO_SHOW_: @@ -2255,7 +2257,7 @@ class TestCommonMethods: def test__prepare_artifact_dir( self, mock_signer, mock_mkdtemp, test_value, expected_value ): - """Ensures that artifact dir name can be benerated propertly.""" + """Ensures that artifact dir name can be generated propertly.""" assert ( _prepare_artifact_dir(test_value) == expected_value From 653b82d05aaf4fd1ca53dcda5c15acb091a68e8d Mon Sep 17 00:00:00 2001 From: Liz Johnson Date: Thu, 18 Sep 2025 16:35:45 -0700 Subject: [PATCH 4/4] fixed unit tests --- .../with_extras/evaluator/test_evaluator.py | 19 +++++++++++-------- .../model/test_model_metadata_mixin.py | 15 +++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/tests/unitary/with_extras/evaluator/test_evaluator.py b/tests/unitary/with_extras/evaluator/test_evaluator.py index 455ece27c..73631fee9 100644 --- a/tests/unitary/with_extras/evaluator/test_evaluator.py +++ b/tests/unitary/with_extras/evaluator/test_evaluator.py @@ -6,22 +6,23 @@ """ Contains tests for ads.evaluations.evaluator """ -import pytest -import unittest import tempfile -from ads.evaluations.evaluator import Evaluator +import unittest -from sklearn.datasets import make_regression -from sklearn.datasets import make_classification -from sklearn.model_selection import train_test_split +import pandas as pd +import pytest from lightgbm import LGBMClassifier, LGBMRegressor -from sklearn.tree import DecisionTreeClassifier +from sklearn.datasets import make_classification, make_regression from sklearn.linear_model import LinearRegression -import pandas as pd +from sklearn.model_selection import train_test_split +from sklearn.tree import DecisionTreeClassifier + from ads.common.model_metadata import UseCaseType +from ads.evaluations.evaluator import Evaluator from ads.model.framework.lightgbm_model import LightGBMModel from ads.model.framework.sklearn_model import SklearnModel +DEFAULT_PYTHON_VERSION = "3.12" def test_model_types(): with pytest.raises(ValueError): @@ -39,6 +40,7 @@ def test_pandas_input(): model.prepare( inference_conda_env="generalml_p38_cpu_v1", training_conda_env="generalml_p38_cpu_v1", + inference_python_version=DEFAULT_PYTHON_VERSION, X_sample=X, y_sample=y, use_case_type=UseCaseType.MULTINOMIAL_CLASSIFICATION, @@ -100,6 +102,7 @@ def train_eval_model(self, data, model, use_case): my_model.prepare( inference_conda_env="generalml_p38_cpu_v1", training_conda_env="generalml_p38_cpu_v1", + inference_python_version=DEFAULT_PYTHON_VERSION, X_sample=X_test, y_sample=y_test, use_case_type=use_case, diff --git a/tests/unitary/with_extras/model/test_model_metadata_mixin.py b/tests/unitary/with_extras/model/test_model_metadata_mixin.py index ad9b41f7e..b743b8095 100644 --- a/tests/unitary/with_extras/model/test_model_metadata_mixin.py +++ b/tests/unitary/with_extras/model/test_model_metadata_mixin.py @@ -3,20 +3,22 @@ # Copyright (c) 2022, 2023 Oracle and/or its affiliates. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ +import os +import shutil from unittest.mock import patch + import numpy as np import pytest +import sklearn +import xgboost from sklearn import datasets, linear_model -from ads.model.generic_model import GenericModel +from ads.feature_engineering.schema import Schema from ads.model.framework.sklearn_model import SklearnModel from ads.model.framework.xgboost_model import XGBoostModel -from ads.feature_engineering.schema import Schema -import sklearn -import os -import shutil -import xgboost +from ads.model.generic_model import GenericModel +DEFAULT_PYTHON_VERSION = "3.12" class TestMetadataMixin: def setup_method(cls): @@ -49,6 +51,7 @@ def test_metadata_generic_model(self): model.prepare( inference_conda_env="dataexpl_p37_cpu_v3", namespace="ociodscdev", + inference_python_version=DEFAULT_PYTHON_VERSION, model_file_name="model.joblib", force_overwrite=True, )