Skip to content

Commit 42f297b

Browse files
authored
Automatically select latest version of conda pack (#1273)
2 parents 71e2184 + b02c9d5 commit 42f297b

File tree

6 files changed

+53
-3
lines changed

6 files changed

+53
-3
lines changed

ads/opctl/backend/ads_ml_job.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
import shutil
1212
import tempfile
1313
import time
14+
import re
1415
from distutils import dir_util
1516
from typing import Dict, Tuple, Union
1617

1718
from ads.common.auth import AuthContext, AuthType, create_signer
1819
from ads.common.oci_client import OCIClientFactory
20+
from ads.config import (
21+
CONDA_BUCKET_NAME,
22+
CONDA_BUCKET_NS,
23+
)
1924
from ads.jobs import (
2025
ContainerRuntime,
2126
DataScienceJob,
@@ -65,6 +70,32 @@ def __init__(self, config: Dict) -> None:
6570
self.auth_type = config["execution"].get("auth")
6671
self.profile = config["execution"].get("oci_profile", None)
6772
self.client = OCIClientFactory(**self.oci_auth).data_science
73+
self.object_storage = OCIClientFactory(**self.oci_auth).object_storage
74+
75+
def _get_latest_conda_pack(self,
76+
prefix,
77+
python_version,
78+
base_conda) -> str:
79+
"""
80+
get the latest conda pack.
81+
"""
82+
try:
83+
objects = self.object_storage.list_objects(namespace_name=CONDA_BUCKET_NS,
84+
bucket_name=CONDA_BUCKET_NAME,
85+
prefix=prefix).data.objects
86+
py_str = python_version.replace(".", "")
87+
py_filter = [obj for obj in objects if f"p{py_str}" in obj.name]
88+
89+
def extract_version(obj_name):
90+
match = re.search(rf"{prefix}([\d.]+)/", obj_name)
91+
return tuple(map(int, match.group(1).split("."))) if match else (0,)
92+
93+
latest_obj = max(py_filter, key=lambda obj: extract_version(obj.name))
94+
return latest_obj.name.split("/")[-1]
95+
except Exception as e:
96+
logger.warning(f"Error while fetching latest conda pack: {e}")
97+
return base_conda
98+
6899

69100
def init(
70101
self,
@@ -100,6 +131,16 @@ def init(
100131
or ""
101132
).lower()
102133

134+
# If a tag is present
135+
if ":" in conda_slug:
136+
base_conda = conda_slug.split(":")[0]
137+
conda_slug = self._get_latest_conda_pack(
138+
self.config["prefix"],
139+
self.config["python_version"],
140+
base_conda
141+
)
142+
logger.info(f"Proceeding with the {conda_slug} conda pack.")
143+
103144
# if conda slug contains '/' then the assumption is that it is a custom conda pack
104145
# the conda prefix needs to be added
105146
if "/" in conda_slug:

ads/opctl/operator/common/backend_factory.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ def _init_backend_config(
362362
if operator_info.conda_type == PACK_TYPE.SERVICE
363363
else operator_info.conda_prefix,
364364
"freeform_tags": freeform_tags,
365+
"python_version": operator_info.python_version,
366+
"prefix": operator_info.prefix,
365367
}
366368
},
367369
{

ads/opctl/operator/common/operator_loader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ class OperatorInfo(DataClassSerializable):
152152
description: str = ""
153153
version: str = ""
154154
conda: str = ""
155+
prefix: str = ""
156+
python_version: str = "3.11"
155157
conda_type: str = ""
156158
path: str = ""
157159
keywords: List[str] = None

ads/opctl/operator/lowcode/anomaly/MLoperator

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ type: anomaly
22
version: v1
33
conda_type: service
44
name: Anomaly Detection Operator
5-
conda: anomaly_p310_cpu_x86_64_v1
5+
conda: anomaly_p311_cpu_x86_64_v2:latest
6+
prefix: service_pack/cpu/AI_Anomaly_Detection_Operator/
7+
python_version: "3.11"
68
gpu: no
79
keywords:
810
- Anomaly Detection

ads/opctl/operator/lowcode/forecast/MLoperator

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ type: forecast
22
version: v1
33
name: Forecasting Operator
44
conda_type: service
5-
conda: forecast_p310_cpu_x86_64_v4
5+
conda: forecast_p311_cpu_x86_64_v10:latest
6+
prefix: service_pack/cpu/AI_Forecasting_Operator/
7+
python_version: "3.11"
68
gpu: no
79
jobs_default_params:
810
shape_name: VM.Standard.E4.Flex

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ forecast = [
181181
"oci-cli",
182182
"optuna",
183183
"pmdarima",
184-
"prophet",
184+
"prophet==1.1.7",
185+
"cmdstanpy==1.2.5",
185186
"shap",
186187
"sktime",
187188
"statsmodels",

0 commit comments

Comments
 (0)