oracle-ads 2.11.16__py3-none-any.whl → 2.11.17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ads/aqua/app.py +5 -6
- ads/aqua/common/enums.py +9 -0
- ads/aqua/common/utils.py +128 -1
- ads/aqua/constants.py +1 -0
- ads/aqua/evaluation/evaluation.py +1 -1
- ads/aqua/extension/common_handler.py +75 -5
- ads/aqua/extension/deployment_handler.py +2 -0
- ads/aqua/extension/model_handler.py +113 -12
- ads/aqua/model/entities.py +20 -2
- ads/aqua/model/model.py +417 -172
- ads/aqua/modeldeployment/deployment.py +69 -55
- ads/jobs/builders/infrastructure/dsc_job.py +12 -9
- ads/opctl/operator/lowcode/forecast/model/arima.py +3 -1
- {oracle_ads-2.11.16.dist-info → oracle_ads-2.11.17.dist-info}/METADATA +2 -1
- {oracle_ads-2.11.16.dist-info → oracle_ads-2.11.17.dist-info}/RECORD +18 -18
- {oracle_ads-2.11.16.dist-info → oracle_ads-2.11.17.dist-info}/LICENSE.txt +0 -0
- {oracle_ads-2.11.16.dist-info → oracle_ads-2.11.17.dist-info}/WHEEL +0 -0
- {oracle_ads-2.11.16.dist-info → oracle_ads-2.11.17.dist-info}/entry_points.txt +0 -0
ads/aqua/app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*-
|
3
2
|
# Copyright (c) 2024 Oracle and/or its affiliates.
|
4
3
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
5
4
|
|
@@ -175,7 +174,7 @@ class AquaApp:
|
|
175
174
|
f"Invalid model version set name. Please provide a model version set with `{tag}` in tags."
|
176
175
|
)
|
177
176
|
|
178
|
-
except:
|
177
|
+
except Exception:
|
179
178
|
logger.debug(
|
180
179
|
f"Model version set {model_version_set_name} doesn't exist. "
|
181
180
|
"Creating new model version set."
|
@@ -254,7 +253,7 @@ class AquaApp:
|
|
254
253
|
|
255
254
|
try:
|
256
255
|
response = self.ds_client.head_model_artifact(model_id=model_id, **kwargs)
|
257
|
-
return
|
256
|
+
return response.status == 200
|
258
257
|
except oci.exceptions.ServiceError as ex:
|
259
258
|
if ex.status == 404:
|
260
259
|
logger.info(f"Artifact not found in model {model_id}.")
|
@@ -302,7 +301,7 @@ class AquaApp:
|
|
302
301
|
config_path,
|
303
302
|
config_file_name=config_file_name,
|
304
303
|
)
|
305
|
-
except:
|
304
|
+
except Exception:
|
306
305
|
# todo: temp fix for issue related to config load for byom models, update logic to choose the right path
|
307
306
|
try:
|
308
307
|
config_path = f"{artifact_path.rstrip('/')}/config/"
|
@@ -310,7 +309,7 @@ class AquaApp:
|
|
310
309
|
config_path,
|
311
310
|
config_file_name=config_file_name,
|
312
311
|
)
|
313
|
-
except:
|
312
|
+
except Exception:
|
314
313
|
pass
|
315
314
|
|
316
315
|
if not config:
|
@@ -343,7 +342,7 @@ class CLIBuilderMixin:
|
|
343
342
|
params = [
|
344
343
|
f"--{field.name} {getattr(self,field.name)}"
|
345
344
|
for field in fields(self.__class__)
|
346
|
-
if getattr(self, field.name)
|
345
|
+
if getattr(self, field.name) is not None
|
347
346
|
]
|
348
347
|
cmd = f"{cmd} {' '.join(params)}"
|
349
348
|
return cmd
|
ads/aqua/common/enums.py
CHANGED
@@ -39,6 +39,7 @@ class Tags(str, metaclass=ExtendedEnumMeta):
|
|
39
39
|
BASE_MODEL_CUSTOM = "aqua_custom_base_model"
|
40
40
|
AQUA_EVALUATION_MODEL_ID = "evaluation_model_id"
|
41
41
|
MODEL_FORMAT = "model_format"
|
42
|
+
MODEL_ARTIFACT_FILE = "model_file"
|
42
43
|
|
43
44
|
|
44
45
|
class InferenceContainerType(str, metaclass=ExtendedEnumMeta):
|
@@ -59,6 +60,14 @@ class InferenceContainerParamType(str, metaclass=ExtendedEnumMeta):
|
|
59
60
|
PARAM_TYPE_LLAMA_CPP = "LLAMA_CPP_PARAMS"
|
60
61
|
|
61
62
|
|
63
|
+
class EvaluationContainerTypeFamily(str, metaclass=ExtendedEnumMeta):
|
64
|
+
AQUA_EVALUATION_CONTAINER_FAMILY = "odsc-llm-evaluate"
|
65
|
+
|
66
|
+
|
67
|
+
class FineTuningContainerTypeFamily(str, metaclass=ExtendedEnumMeta):
|
68
|
+
AQUA_FINETUNING_CONTAINER_FAMILY = "odsc-llm-fine-tuning"
|
69
|
+
|
70
|
+
|
62
71
|
class HuggingFaceTags(str, metaclass=ExtendedEnumMeta):
|
63
72
|
TEXT_GENERATION_INFERENCE = "text-generation-inference"
|
64
73
|
|
ads/aqua/common/utils.py
CHANGED
@@ -10,6 +10,8 @@ import logging
|
|
10
10
|
import os
|
11
11
|
import random
|
12
12
|
import re
|
13
|
+
import shlex
|
14
|
+
import subprocess
|
13
15
|
from datetime import datetime, timedelta
|
14
16
|
from functools import wraps
|
15
17
|
from pathlib import Path
|
@@ -19,6 +21,13 @@ from typing import List, Union
|
|
19
21
|
import fsspec
|
20
22
|
import oci
|
21
23
|
from cachetools import TTLCache, cached
|
24
|
+
from huggingface_hub.hf_api import HfApi, ModelInfo
|
25
|
+
from huggingface_hub.utils import (
|
26
|
+
GatedRepoError,
|
27
|
+
HfHubHTTPError,
|
28
|
+
RepositoryNotFoundError,
|
29
|
+
RevisionNotFoundError,
|
30
|
+
)
|
22
31
|
from oci.data_science.models import JobRun, Model
|
23
32
|
from oci.object_storage.models import ObjectSummary
|
24
33
|
|
@@ -37,6 +46,7 @@ from ads.aqua.constants import (
|
|
37
46
|
COMPARTMENT_MAPPING_KEY,
|
38
47
|
CONSOLE_LINK_RESOURCE_TYPE_MAPPING,
|
39
48
|
CONTAINER_INDEX,
|
49
|
+
HF_LOGIN_DEFAULT_TIMEOUT,
|
40
50
|
MAXIMUM_ALLOWED_DATASET_IN_BYTE,
|
41
51
|
MODEL_BY_REFERENCE_OSS_PATH_KEY,
|
42
52
|
SERVICE_MANAGED_CONTAINER_URI_SCHEME,
|
@@ -47,7 +57,7 @@ from ads.aqua.constants import (
|
|
47
57
|
VLLM_INFERENCE_RESTRICTED_PARAMS,
|
48
58
|
)
|
49
59
|
from ads.aqua.data import AquaResourceIdentifier
|
50
|
-
from ads.common.auth import default_signer
|
60
|
+
from ads.common.auth import AuthState, default_signer
|
51
61
|
from ads.common.extended_enum import ExtendedEnumMeta
|
52
62
|
from ads.common.object_storage_details import ObjectStorageDetails
|
53
63
|
from ads.common.oci_resource import SEARCH_TYPE, OCIResource
|
@@ -771,6 +781,33 @@ def get_ocid_substring(ocid: str, key_len: int) -> str:
|
|
771
781
|
return ocid[-key_len:] if ocid and len(ocid) > key_len else ""
|
772
782
|
|
773
783
|
|
784
|
+
def upload_folder(os_path: str, local_dir: str, model_name: str) -> str:
|
785
|
+
"""Upload the local folder to the object storage
|
786
|
+
|
787
|
+
Args:
|
788
|
+
os_path (str): object storage URI with prefix. This is the path to upload
|
789
|
+
local_dir (str): Local directory where the object is downloaded
|
790
|
+
model_name (str): Name of the huggingface model
|
791
|
+
Retuns:
|
792
|
+
str: Object name inside the bucket
|
793
|
+
"""
|
794
|
+
os_details: ObjectStorageDetails = ObjectStorageDetails.from_path(os_path)
|
795
|
+
if not os_details.is_bucket_versioned():
|
796
|
+
raise ValueError(f"Version is not enabled at object storage location {os_path}")
|
797
|
+
auth_state = AuthState()
|
798
|
+
object_path = os_details.filepath.rstrip("/") + "/" + model_name + "/"
|
799
|
+
command = f"oci os object bulk-upload --src-dir {local_dir} --prefix {object_path} -bn {os_details.bucket} -ns {os_details.namespace} --auth {auth_state.oci_iam_type} --profile {auth_state.oci_key_profile} --no-overwrite"
|
800
|
+
try:
|
801
|
+
logger.info(f"Running: {command}")
|
802
|
+
subprocess.check_call(shlex.split(command))
|
803
|
+
except subprocess.CalledProcessError as e:
|
804
|
+
logger.error(
|
805
|
+
f"Error uploading the object. Exit code: {e.returncode} with error {e.stdout}"
|
806
|
+
)
|
807
|
+
|
808
|
+
return f"oci://{os_details.bucket}@{os_details.namespace}" + "/" + object_path
|
809
|
+
|
810
|
+
|
774
811
|
def is_service_managed_container(container):
|
775
812
|
return container and container.startswith(SERVICE_MANAGED_CONTAINER_URI_SCHEME)
|
776
813
|
|
@@ -935,3 +972,93 @@ def get_restricted_params_by_container(container_type_name: str) -> set:
|
|
935
972
|
return TGI_INFERENCE_RESTRICTED_PARAMS
|
936
973
|
else:
|
937
974
|
return set()
|
975
|
+
|
976
|
+
|
977
|
+
def get_huggingface_login_timeout() -> int:
|
978
|
+
"""This helper function returns the huggingface login timeout, returns default if not set via
|
979
|
+
env var.
|
980
|
+
Returns
|
981
|
+
-------
|
982
|
+
timeout: int
|
983
|
+
huggingface login timeout.
|
984
|
+
|
985
|
+
"""
|
986
|
+
timeout = HF_LOGIN_DEFAULT_TIMEOUT
|
987
|
+
try:
|
988
|
+
timeout = int(
|
989
|
+
os.environ.get("HF_LOGIN_DEFAULT_TIMEOUT", HF_LOGIN_DEFAULT_TIMEOUT)
|
990
|
+
)
|
991
|
+
except ValueError:
|
992
|
+
pass
|
993
|
+
return timeout
|
994
|
+
|
995
|
+
|
996
|
+
def format_hf_custom_error_message(error: HfHubHTTPError):
|
997
|
+
"""
|
998
|
+
Formats a custom error message based on the Hugging Face error response.
|
999
|
+
|
1000
|
+
Parameters
|
1001
|
+
----------
|
1002
|
+
error (HfHubHTTPError): The caught exception.
|
1003
|
+
|
1004
|
+
Raises
|
1005
|
+
------
|
1006
|
+
AquaRuntimeError: A user-friendly error message.
|
1007
|
+
"""
|
1008
|
+
# Extract the repository URL from the error message if present
|
1009
|
+
match = re.search(r"(https://huggingface.co/[^\s]+)", str(error))
|
1010
|
+
url = match.group(1) if match else "the requested Hugging Face URL."
|
1011
|
+
|
1012
|
+
if isinstance(error, RepositoryNotFoundError):
|
1013
|
+
raise AquaRuntimeError(
|
1014
|
+
reason=f"Failed to access `{url}`. Please check if the provided repository name is correct. "
|
1015
|
+
"If the repo is private, make sure you are authenticated and have a valid HF token registered. "
|
1016
|
+
"To register your token, run this command in your terminal: `huggingface-cli login`",
|
1017
|
+
service_payload={"error": "RepositoryNotFoundError"},
|
1018
|
+
)
|
1019
|
+
|
1020
|
+
if isinstance(error, GatedRepoError):
|
1021
|
+
raise AquaRuntimeError(
|
1022
|
+
reason=f"Access denied to `{url}` "
|
1023
|
+
"This repository is gated. Access is restricted to authorized users. "
|
1024
|
+
"Please request access or check with the repository administrator. "
|
1025
|
+
"If you are trying to access a gated repository, ensure you have a valid HF token registered. "
|
1026
|
+
"To register your token, run this command in your terminal: `huggingface-cli login`",
|
1027
|
+
service_payload={"error": "GatedRepoError"},
|
1028
|
+
)
|
1029
|
+
|
1030
|
+
if isinstance(error, RevisionNotFoundError):
|
1031
|
+
raise AquaRuntimeError(
|
1032
|
+
reason=f"The specified revision could not be found at `{url}` "
|
1033
|
+
"Please check the revision identifier and try again.",
|
1034
|
+
service_payload={"error": "RevisionNotFoundError"},
|
1035
|
+
)
|
1036
|
+
|
1037
|
+
raise AquaRuntimeError(
|
1038
|
+
reason=f"An error occurred while accessing `{url}` "
|
1039
|
+
"Please check your network connection and try again. "
|
1040
|
+
"If you are trying to access a gated repository, ensure you have a valid HF token registered. "
|
1041
|
+
"To register your token, run this command in your terminal: `huggingface-cli login`",
|
1042
|
+
service_payload={"error": "Error"},
|
1043
|
+
)
|
1044
|
+
|
1045
|
+
|
1046
|
+
@cached(cache=TTLCache(maxsize=1, ttl=timedelta(hours=5), timer=datetime.now))
|
1047
|
+
def get_hf_model_info(repo_id: str) -> ModelInfo:
|
1048
|
+
"""Gets the model information object for the given model repository name. For models that requires a token,
|
1049
|
+
this method assumes that the token validation is already done.
|
1050
|
+
|
1051
|
+
Parameters
|
1052
|
+
----------
|
1053
|
+
repo_id: str
|
1054
|
+
hugging face model repository name
|
1055
|
+
|
1056
|
+
Returns
|
1057
|
+
-------
|
1058
|
+
instance of ModelInfo object
|
1059
|
+
|
1060
|
+
"""
|
1061
|
+
try:
|
1062
|
+
return HfApi().model_info(repo_id=repo_id)
|
1063
|
+
except HfHubHTTPError as err:
|
1064
|
+
raise format_hf_custom_error_message(err) from err
|
ads/aqua/constants.py
CHANGED
@@ -34,6 +34,7 @@ AQUA_MODEL_ARTIFACT_CONFIG = "config.json"
|
|
34
34
|
AQUA_MODEL_ARTIFACT_CONFIG_MODEL_NAME = "_name_or_path"
|
35
35
|
AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE = "model_type"
|
36
36
|
AQUA_MODEL_ARTIFACT_FILE = "model_file"
|
37
|
+
HF_LOGIN_DEFAULT_TIMEOUT = 2
|
37
38
|
|
38
39
|
TRAINING_METRICS_FINAL = "training_metrics_final"
|
39
40
|
VALIDATION_METRICS_FINAL = "validation_metrics_final"
|
@@ -191,7 +191,7 @@ class AquaEvaluationApp(AquaApp):
|
|
191
191
|
enable_spec=True
|
192
192
|
).inference
|
193
193
|
for container in inference_config.values():
|
194
|
-
if container.name == runtime.image.
|
194
|
+
if container.name == runtime.image[:runtime.image.rfind(":")]:
|
195
195
|
eval_inference_configuration = (
|
196
196
|
container.spec.evaluation_configuration
|
197
197
|
)
|
@@ -1,18 +1,24 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*-
|
3
2
|
# Copyright (c) 2024 Oracle and/or its affiliates.
|
4
3
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
5
4
|
|
6
5
|
|
7
6
|
from importlib import metadata
|
8
7
|
|
8
|
+
import huggingface_hub
|
9
9
|
import requests
|
10
|
+
from huggingface_hub import HfApi
|
11
|
+
from huggingface_hub.utils import LocalTokenNotFoundError
|
10
12
|
from tornado.web import HTTPError
|
11
13
|
|
12
14
|
from ads.aqua import ODSC_MODEL_COMPARTMENT_OCID
|
13
15
|
from ads.aqua.common.decorator import handle_exceptions
|
14
16
|
from ads.aqua.common.errors import AquaResourceAccessError, AquaRuntimeError
|
15
|
-
from ads.aqua.common.utils import
|
17
|
+
from ads.aqua.common.utils import (
|
18
|
+
fetch_service_compartment,
|
19
|
+
get_huggingface_login_timeout,
|
20
|
+
known_realm,
|
21
|
+
)
|
16
22
|
from ads.aqua.extension.base_handler import AquaAPIhandler
|
17
23
|
from ads.aqua.extension.errors import Errors
|
18
24
|
|
@@ -46,16 +52,80 @@ class CompatibilityCheckHandler(AquaAPIhandler):
|
|
46
52
|
|
47
53
|
"""
|
48
54
|
if ODSC_MODEL_COMPARTMENT_OCID or fetch_service_compartment():
|
49
|
-
return self.finish(
|
55
|
+
return self.finish({"status": "ok"})
|
50
56
|
elif known_realm():
|
51
|
-
return self.finish(
|
57
|
+
return self.finish({"status": "compatible"})
|
52
58
|
else:
|
53
59
|
raise AquaResourceAccessError(
|
54
|
-
|
60
|
+
"The AI Quick actions extension is not compatible in the given region."
|
55
61
|
)
|
56
62
|
|
57
63
|
|
64
|
+
class NetworkStatusHandler(AquaAPIhandler):
|
65
|
+
"""Handler to check internet connection."""
|
66
|
+
|
67
|
+
@handle_exceptions
|
68
|
+
def get(self):
|
69
|
+
requests.get("https://huggingface.com", timeout=get_huggingface_login_timeout())
|
70
|
+
return self.finish({"status": 200, "message": "success"})
|
71
|
+
|
72
|
+
|
73
|
+
class HFLoginHandler(AquaAPIhandler):
|
74
|
+
"""Handler to login to HF."""
|
75
|
+
|
76
|
+
@handle_exceptions
|
77
|
+
def post(self, *args, **kwargs):
|
78
|
+
"""Handles post request for the HF login.
|
79
|
+
|
80
|
+
Raises
|
81
|
+
------
|
82
|
+
HTTPError
|
83
|
+
Raises HTTPError if inputs are missing or are invalid.
|
84
|
+
"""
|
85
|
+
try:
|
86
|
+
input_data = self.get_json_body()
|
87
|
+
except Exception as ex:
|
88
|
+
raise HTTPError(400, Errors.INVALID_INPUT_DATA_FORMAT) from ex
|
89
|
+
|
90
|
+
if not input_data:
|
91
|
+
raise HTTPError(400, Errors.NO_INPUT_DATA)
|
92
|
+
|
93
|
+
token = input_data.get("token")
|
94
|
+
|
95
|
+
if not token:
|
96
|
+
raise HTTPError(400, Errors.MISSING_REQUIRED_PARAMETER.format("token"))
|
97
|
+
|
98
|
+
# Login to HF
|
99
|
+
try:
|
100
|
+
huggingface_hub.login(token=token, new_session=False)
|
101
|
+
except Exception as ex:
|
102
|
+
raise AquaRuntimeError(
|
103
|
+
reason=str(ex), service_payload={"error": type(ex).__name__}
|
104
|
+
) from ex
|
105
|
+
|
106
|
+
return self.finish({"status": 200, "message": "login successful"})
|
107
|
+
|
108
|
+
|
109
|
+
class HFUserStatusHandler(AquaAPIhandler):
|
110
|
+
"""Handler to check if user logged in to the HF."""
|
111
|
+
|
112
|
+
@handle_exceptions
|
113
|
+
def get(self):
|
114
|
+
try:
|
115
|
+
HfApi().whoami()
|
116
|
+
except LocalTokenNotFoundError as err:
|
117
|
+
raise AquaRuntimeError(
|
118
|
+
"You are not logged in. Please log in to Hugging Face using the `huggingface-cli login` command."
|
119
|
+
"See https://huggingface.co/settings/tokens.",
|
120
|
+
) from err
|
121
|
+
|
122
|
+
return self.finish({"status": 200, "message": "logged in"})
|
123
|
+
|
124
|
+
|
58
125
|
__handlers__ = [
|
59
126
|
("ads_version", ADSVersionHandler),
|
60
127
|
("hello", CompatibilityCheckHandler),
|
128
|
+
("network_status", NetworkStatusHandler),
|
129
|
+
("hf_login", HFLoginHandler),
|
130
|
+
("hf_logged_in", HFUserStatusHandler),
|
61
131
|
]
|
@@ -101,6 +101,7 @@ class AquaDeploymentHandler(AquaAPIhandler):
|
|
101
101
|
container_family = input_data.get("container_family")
|
102
102
|
ocpus = input_data.get("ocpus")
|
103
103
|
memory_in_gbs = input_data.get("memory_in_gbs")
|
104
|
+
model_file = input_data.get("model_file")
|
104
105
|
|
105
106
|
self.finish(
|
106
107
|
AquaDeploymentApp().create(
|
@@ -122,6 +123,7 @@ class AquaDeploymentHandler(AquaAPIhandler):
|
|
122
123
|
container_family=container_family,
|
123
124
|
ocpus=ocpus,
|
124
125
|
memory_in_gbs=memory_in_gbs,
|
126
|
+
model_file=model_file,
|
125
127
|
)
|
126
128
|
)
|
127
129
|
|
@@ -2,15 +2,19 @@
|
|
2
2
|
# Copyright (c) 2024 Oracle and/or its affiliates.
|
3
3
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
4
4
|
|
5
|
+
from typing import Optional
|
5
6
|
from urllib.parse import urlparse
|
6
7
|
|
7
8
|
from tornado.web import HTTPError
|
8
9
|
|
9
10
|
from ads.aqua.common.decorator import handle_exceptions
|
10
|
-
from ads.aqua.common.errors import AquaValueError
|
11
|
+
from ads.aqua.common.errors import AquaRuntimeError, AquaValueError
|
12
|
+
from ads.aqua.common.utils import get_hf_model_info
|
11
13
|
from ads.aqua.extension.base_handler import AquaAPIhandler
|
12
14
|
from ads.aqua.extension.errors import Errors
|
13
15
|
from ads.aqua.model import AquaModelApp
|
16
|
+
from ads.aqua.model.constants import ModelTask
|
17
|
+
from ads.aqua.model.entities import AquaModelSummary, HFModelSummary
|
14
18
|
from ads.aqua.ui import ModelFormat
|
15
19
|
|
16
20
|
|
@@ -26,11 +30,9 @@ class AquaModelHandler(AquaAPIhandler):
|
|
26
30
|
url_parse = urlparse(self.request.path)
|
27
31
|
paths = url_parse.path.strip("/")
|
28
32
|
if paths.startswith("aqua/model/files"):
|
29
|
-
os_path = self.get_argument("os_path")
|
30
|
-
|
31
|
-
|
32
|
-
400, Errors.MISSING_REQUIRED_PARAMETER.format("os_path")
|
33
|
-
)
|
33
|
+
os_path = self.get_argument("os_path", None)
|
34
|
+
model_name = self.get_argument("model_name", None)
|
35
|
+
|
34
36
|
model_format = self.get_argument("model_format")
|
35
37
|
if not model_format:
|
36
38
|
raise HTTPError(
|
@@ -38,10 +40,24 @@ class AquaModelHandler(AquaAPIhandler):
|
|
38
40
|
)
|
39
41
|
try:
|
40
42
|
model_format = ModelFormat(model_format.upper())
|
41
|
-
except ValueError:
|
42
|
-
raise AquaValueError(f"Invalid model format: {model_format}")
|
43
|
+
except ValueError as err:
|
44
|
+
raise AquaValueError(f"Invalid model format: {model_format}") from err
|
43
45
|
else:
|
44
|
-
|
46
|
+
if os_path:
|
47
|
+
return self.finish(
|
48
|
+
AquaModelApp.get_model_files(os_path, model_format)
|
49
|
+
)
|
50
|
+
elif model_name:
|
51
|
+
return self.finish(
|
52
|
+
AquaModelApp.get_hf_model_files(model_name, model_format)
|
53
|
+
)
|
54
|
+
else:
|
55
|
+
raise HTTPError(
|
56
|
+
400,
|
57
|
+
Errors.MISSING_ONEOF_REQUIRED_PARAMETER.format(
|
58
|
+
"os_path", "model_name"
|
59
|
+
),
|
60
|
+
)
|
45
61
|
elif not model_id:
|
46
62
|
return self.list()
|
47
63
|
|
@@ -52,7 +68,7 @@ class AquaModelHandler(AquaAPIhandler):
|
|
52
68
|
return self.finish(AquaModelApp().get(model_id))
|
53
69
|
|
54
70
|
@handle_exceptions
|
55
|
-
def delete(self
|
71
|
+
def delete(self):
|
56
72
|
"""Handles DELETE request for clearing cache"""
|
57
73
|
url_parse = urlparse(self.request.path)
|
58
74
|
paths = url_parse.path.strip("/")
|
@@ -86,8 +102,8 @@ class AquaModelHandler(AquaAPIhandler):
|
|
86
102
|
"""
|
87
103
|
try:
|
88
104
|
input_data = self.get_json_body()
|
89
|
-
except Exception:
|
90
|
-
raise HTTPError(400, Errors.INVALID_INPUT_DATA_FORMAT)
|
105
|
+
except Exception as ex:
|
106
|
+
raise HTTPError(400, Errors.INVALID_INPUT_DATA_FORMAT) from ex
|
91
107
|
|
92
108
|
if not input_data:
|
93
109
|
raise HTTPError(400, Errors.NO_INPUT_DATA)
|
@@ -105,11 +121,15 @@ class AquaModelHandler(AquaAPIhandler):
|
|
105
121
|
compartment_id = input_data.get("compartment_id")
|
106
122
|
project_id = input_data.get("project_id")
|
107
123
|
model_file = input_data.get("model_file")
|
124
|
+
download_from_hf = (
|
125
|
+
str(input_data.get("download_from_hf", "false")).lower() == "true"
|
126
|
+
)
|
108
127
|
|
109
128
|
return self.finish(
|
110
129
|
AquaModelApp().register(
|
111
130
|
model=model,
|
112
131
|
os_path=os_path,
|
132
|
+
download_from_hf=download_from_hf,
|
113
133
|
inference_container=inference_container,
|
114
134
|
finetuning_container=finetuning_container,
|
115
135
|
compartment_id=compartment_id,
|
@@ -130,7 +150,88 @@ class AquaModelLicenseHandler(AquaAPIhandler):
|
|
130
150
|
return self.finish(AquaModelApp().load_license(model_id))
|
131
151
|
|
132
152
|
|
153
|
+
class AquaHuggingFaceHandler(AquaAPIhandler):
|
154
|
+
"""Handler for Aqua Hugging Face REST APIs."""
|
155
|
+
|
156
|
+
@staticmethod
|
157
|
+
def _find_matching_aqua_model(model_id: str) -> Optional[AquaModelSummary]:
|
158
|
+
"""
|
159
|
+
Finds a matching model in AQUA based on the model ID from Hugging Face.
|
160
|
+
|
161
|
+
Parameters
|
162
|
+
----------
|
163
|
+
model_id (str): The Hugging Face model ID to match.
|
164
|
+
|
165
|
+
Returns
|
166
|
+
-------
|
167
|
+
Optional[AquaModelSummary]
|
168
|
+
Returns the matching AquaModelSummary object if found, else None.
|
169
|
+
"""
|
170
|
+
# Convert the Hugging Face model ID to lowercase once
|
171
|
+
model_id_lower = model_id.lower()
|
172
|
+
|
173
|
+
aqua_model_app = AquaModelApp()
|
174
|
+
model_ocid = aqua_model_app._find_matching_aqua_model(model_id=model_id_lower)
|
175
|
+
if model_ocid:
|
176
|
+
return aqua_model_app.get(model_ocid, load_model_card=False)
|
177
|
+
|
178
|
+
return None
|
179
|
+
|
180
|
+
@handle_exceptions
|
181
|
+
def post(self, *args, **kwargs):
|
182
|
+
"""Handles post request for the HF Models APIs
|
183
|
+
|
184
|
+
Raises
|
185
|
+
------
|
186
|
+
HTTPError
|
187
|
+
Raises HTTPError if inputs are missing or are invalid.
|
188
|
+
"""
|
189
|
+
try:
|
190
|
+
input_data = self.get_json_body()
|
191
|
+
except Exception as ex:
|
192
|
+
raise HTTPError(400, Errors.INVALID_INPUT_DATA_FORMAT) from ex
|
193
|
+
|
194
|
+
if not input_data:
|
195
|
+
raise HTTPError(400, Errors.NO_INPUT_DATA)
|
196
|
+
|
197
|
+
model_id = input_data.get("model_id")
|
198
|
+
|
199
|
+
if not model_id:
|
200
|
+
raise HTTPError(400, Errors.MISSING_REQUIRED_PARAMETER.format("model_id"))
|
201
|
+
|
202
|
+
# Get model info from the HF
|
203
|
+
hf_model_info = get_hf_model_info(repo_id=model_id)
|
204
|
+
|
205
|
+
# Check if model is not disabled
|
206
|
+
if hf_model_info.disabled:
|
207
|
+
raise AquaRuntimeError(
|
208
|
+
f"The chosen model '{hf_model_info.id}' is currently disabled and cannot be imported into AQUA. "
|
209
|
+
"Please verify the model's status on the Hugging Face Model Hub or select a different model."
|
210
|
+
)
|
211
|
+
|
212
|
+
# Check pipeline_tag, it should be `text-generation`
|
213
|
+
if (
|
214
|
+
not hf_model_info.pipeline_tag
|
215
|
+
or hf_model_info.pipeline_tag.lower() != ModelTask.TEXT_GENERATION
|
216
|
+
):
|
217
|
+
raise AquaRuntimeError(
|
218
|
+
f"Unsupported pipeline tag for the chosen model: '{hf_model_info.pipeline_tag}'. "
|
219
|
+
f"AQUA currently supports the following tasks only: {', '.join(ModelTask.values())}. "
|
220
|
+
"Please select a model with a compatible pipeline tag."
|
221
|
+
)
|
222
|
+
|
223
|
+
# Check if it is a service/verified model
|
224
|
+
aqua_model_info: AquaModelSummary = self._find_matching_aqua_model(
|
225
|
+
model_id=hf_model_info.id
|
226
|
+
)
|
227
|
+
|
228
|
+
return self.finish(
|
229
|
+
HFModelSummary(model_info=hf_model_info, aqua_model_info=aqua_model_info)
|
230
|
+
)
|
231
|
+
|
232
|
+
|
133
233
|
__handlers__ = [
|
134
234
|
("model/?([^/]*)", AquaModelHandler),
|
135
235
|
("model/?([^/]*)/license", AquaModelLicenseHandler),
|
236
|
+
("model/hf/search/?([^/]*)", AquaHuggingFaceHandler),
|
136
237
|
]
|
ads/aqua/model/entities.py
CHANGED
@@ -14,6 +14,8 @@ from dataclasses import InitVar, dataclass, field
|
|
14
14
|
from typing import List, Optional
|
15
15
|
|
16
16
|
import oci
|
17
|
+
from huggingface_hub import hf_api
|
18
|
+
|
17
19
|
from ads.aqua import logger
|
18
20
|
from ads.aqua.app import CLIBuilderMixin
|
19
21
|
from ads.aqua.common import utils
|
@@ -41,10 +43,12 @@ class AquaFineTuneValidation(DataClassSerializable):
|
|
41
43
|
value: str = ""
|
42
44
|
|
43
45
|
|
46
|
+
@dataclass(repr=False)
|
44
47
|
class ModelValidationResult:
|
45
48
|
model_file: Optional[str] = None
|
46
|
-
|
49
|
+
model_formats: List[ModelFormat] = field(default_factory=list)
|
47
50
|
telemetry_model_name: str = None
|
51
|
+
tags: Optional[dict] = None
|
48
52
|
|
49
53
|
|
50
54
|
@dataclass(repr=False)
|
@@ -84,7 +88,8 @@ class AquaModelSummary(DataClassSerializable):
|
|
84
88
|
ready_to_import: bool = False
|
85
89
|
nvidia_gpu_supported: bool = False
|
86
90
|
arm_cpu_supported: bool = False
|
87
|
-
|
91
|
+
model_file: Optional[str] = None
|
92
|
+
model_formats: List[ModelFormat] = field(default_factory=list)
|
88
93
|
|
89
94
|
|
90
95
|
@dataclass(repr=False)
|
@@ -95,6 +100,7 @@ class AquaModel(AquaModelSummary, DataClassSerializable):
|
|
95
100
|
inference_container: str = None
|
96
101
|
finetuning_container: str = None
|
97
102
|
evaluation_container: str = None
|
103
|
+
artifact_location: str = None
|
98
104
|
|
99
105
|
|
100
106
|
@dataclass(repr=False)
|
@@ -105,6 +111,16 @@ class HFModelContainerInfo:
|
|
105
111
|
finetuning_container: str = None
|
106
112
|
|
107
113
|
|
114
|
+
@dataclass(repr=False)
|
115
|
+
class HFModelSummary:
|
116
|
+
"""Represents a summary of Hugging Face model."""
|
117
|
+
|
118
|
+
model_info: hf_api.ModelInfo = field(default_factory=hf_api.ModelInfo)
|
119
|
+
aqua_model_info: Optional[AquaModelSummary] = field(
|
120
|
+
default_factory=AquaModelSummary
|
121
|
+
)
|
122
|
+
|
123
|
+
|
108
124
|
@dataclass(repr=False)
|
109
125
|
class AquaEvalFTCommon(DataClassSerializable):
|
110
126
|
"""Represents common fields for evaluation and fine-tuning."""
|
@@ -264,6 +280,8 @@ class AquaFineTuneModel(AquaModel, AquaEvalFTCommon, DataClassSerializable):
|
|
264
280
|
class ImportModelDetails(CLIBuilderMixin):
|
265
281
|
model: str
|
266
282
|
os_path: str
|
283
|
+
download_from_hf: Optional[bool] = True
|
284
|
+
local_dir: Optional[str] = None
|
267
285
|
inference_container: Optional[str] = None
|
268
286
|
finetuning_container: Optional[str] = None
|
269
287
|
compartment_id: Optional[str] = None
|