oracle-ads 2.12.8__py3-none-any.whl → 2.12.10rc0__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/__init__.py +4 -4
- ads/aqua/app.py +12 -2
- ads/aqua/common/enums.py +3 -0
- ads/aqua/common/utils.py +62 -2
- ads/aqua/data.py +2 -19
- ads/aqua/evaluation/entities.py +6 -0
- ads/aqua/evaluation/evaluation.py +25 -3
- ads/aqua/extension/deployment_handler.py +8 -4
- ads/aqua/extension/finetune_handler.py +8 -14
- ads/aqua/extension/model_handler.py +25 -6
- ads/aqua/extension/ui_handler.py +13 -1
- ads/aqua/finetuning/constants.py +5 -2
- ads/aqua/finetuning/entities.py +70 -17
- ads/aqua/finetuning/finetuning.py +79 -82
- ads/aqua/model/entities.py +4 -1
- ads/aqua/model/model.py +95 -29
- ads/aqua/modeldeployment/deployment.py +13 -1
- ads/aqua/modeldeployment/entities.py +7 -4
- ads/aqua/ui.py +24 -2
- ads/common/auth.py +9 -9
- ads/llm/autogen/__init__.py +2 -0
- ads/llm/autogen/constants.py +15 -0
- ads/llm/autogen/reports/__init__.py +2 -0
- ads/llm/autogen/reports/base.py +67 -0
- ads/llm/autogen/reports/data.py +103 -0
- ads/llm/autogen/reports/session.py +526 -0
- ads/llm/autogen/reports/templates/chat_box.html +13 -0
- ads/llm/autogen/reports/templates/chat_box_lt.html +5 -0
- ads/llm/autogen/reports/templates/chat_box_rt.html +6 -0
- ads/llm/autogen/reports/utils.py +56 -0
- ads/llm/autogen/v02/__init__.py +4 -0
- ads/llm/autogen/{client_v02.py → v02/client.py} +23 -10
- ads/llm/autogen/v02/log_handlers/__init__.py +2 -0
- ads/llm/autogen/v02/log_handlers/oci_file_handler.py +83 -0
- ads/llm/autogen/v02/loggers/__init__.py +6 -0
- ads/llm/autogen/v02/loggers/metric_logger.py +320 -0
- ads/llm/autogen/v02/loggers/session_logger.py +580 -0
- ads/llm/autogen/v02/loggers/utils.py +86 -0
- ads/llm/autogen/v02/runtime_logging.py +163 -0
- ads/llm/guardrails/base.py +6 -5
- ads/llm/langchain/plugins/chat_models/oci_data_science.py +46 -20
- ads/llm/langchain/plugins/llms/oci_data_science_model_deployment_endpoint.py +38 -11
- ads/model/__init__.py +11 -13
- ads/model/artifact.py +47 -8
- ads/model/extractor/embedding_onnx_extractor.py +80 -0
- ads/model/framework/embedding_onnx_model.py +438 -0
- ads/model/generic_model.py +26 -24
- ads/model/model_metadata.py +8 -7
- ads/opctl/config/merger.py +13 -14
- ads/opctl/operator/common/operator_config.py +4 -4
- ads/opctl/operator/lowcode/common/transformations.py +12 -5
- ads/opctl/operator/lowcode/common/utils.py +11 -5
- ads/opctl/operator/lowcode/forecast/const.py +3 -0
- ads/opctl/operator/lowcode/forecast/model/arima.py +19 -13
- ads/opctl/operator/lowcode/forecast/model/automlx.py +129 -36
- ads/opctl/operator/lowcode/forecast/model/autots.py +1 -0
- ads/opctl/operator/lowcode/forecast/model/base_model.py +58 -17
- ads/opctl/operator/lowcode/forecast/model/neuralprophet.py +10 -3
- ads/opctl/operator/lowcode/forecast/model/prophet.py +25 -18
- ads/opctl/operator/lowcode/forecast/model_evaluator.py +3 -2
- ads/opctl/operator/lowcode/forecast/schema.yaml +13 -0
- ads/opctl/operator/lowcode/forecast/utils.py +8 -6
- ads/telemetry/base.py +18 -11
- ads/telemetry/client.py +33 -13
- ads/templates/schemas/openapi.json +1740 -0
- ads/templates/score_embedding_onnx.jinja2 +202 -0
- {oracle_ads-2.12.8.dist-info → oracle_ads-2.12.10rc0.dist-info}/METADATA +9 -10
- {oracle_ads-2.12.8.dist-info → oracle_ads-2.12.10rc0.dist-info}/RECORD +71 -50
- {oracle_ads-2.12.8.dist-info → oracle_ads-2.12.10rc0.dist-info}/LICENSE.txt +0 -0
- {oracle_ads-2.12.8.dist-info → oracle_ads-2.12.10rc0.dist-info}/WHEEL +0 -0
- {oracle_ads-2.12.8.dist-info → oracle_ads-2.12.10rc0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
|
3
|
+
# Copyright (c) 2025 Oracle and/or its affiliates.
|
4
|
+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
5
|
+
|
6
|
+
from ads.common.decorator.runtime_dependency import (
|
7
|
+
OptionalDependency,
|
8
|
+
runtime_dependency,
|
9
|
+
)
|
10
|
+
from ads.model.extractor.model_info_extractor import ModelInfoExtractor
|
11
|
+
from ads.model.model_metadata import Framework
|
12
|
+
|
13
|
+
|
14
|
+
class EmbeddingONNXExtractor(ModelInfoExtractor):
|
15
|
+
"""Class that extract model metadata from EmbeddingONNXModel models.
|
16
|
+
|
17
|
+
Attributes
|
18
|
+
----------
|
19
|
+
model: object
|
20
|
+
The model to extract metadata from.
|
21
|
+
|
22
|
+
Methods
|
23
|
+
-------
|
24
|
+
framework(self) -> str
|
25
|
+
Returns the framework of the model.
|
26
|
+
algorithm(self) -> object
|
27
|
+
Returns the algorithm of the model.
|
28
|
+
version(self) -> str
|
29
|
+
Returns the version of framework of the model.
|
30
|
+
hyperparameter(self) -> dict
|
31
|
+
Returns the hyperparameter of the model.
|
32
|
+
"""
|
33
|
+
|
34
|
+
def __init__(self, model=None):
|
35
|
+
self.model = model
|
36
|
+
|
37
|
+
@property
|
38
|
+
def framework(self):
|
39
|
+
"""Extracts the framework of the model.
|
40
|
+
|
41
|
+
Returns
|
42
|
+
----------
|
43
|
+
str:
|
44
|
+
The framework of the model.
|
45
|
+
"""
|
46
|
+
return Framework.EMBEDDING_ONNX
|
47
|
+
|
48
|
+
@property
|
49
|
+
def algorithm(self):
|
50
|
+
"""Extracts the algorithm of the model.
|
51
|
+
|
52
|
+
Returns
|
53
|
+
----------
|
54
|
+
object:
|
55
|
+
The algorithm of the model.
|
56
|
+
"""
|
57
|
+
return "Embedding_ONNX"
|
58
|
+
|
59
|
+
@property
|
60
|
+
@runtime_dependency(module="onnxruntime", install_from=OptionalDependency.ONNX)
|
61
|
+
def version(self):
|
62
|
+
"""Extracts the framework version of the model.
|
63
|
+
|
64
|
+
Returns
|
65
|
+
----------
|
66
|
+
str:
|
67
|
+
The framework version of the model.
|
68
|
+
"""
|
69
|
+
return onnxruntime.__version__
|
70
|
+
|
71
|
+
@property
|
72
|
+
def hyperparameter(self):
|
73
|
+
"""Extracts the hyperparameters of the model.
|
74
|
+
|
75
|
+
Returns
|
76
|
+
----------
|
77
|
+
dict:
|
78
|
+
The hyperparameters of the model.
|
79
|
+
"""
|
80
|
+
return None
|
@@ -0,0 +1,438 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
|
3
|
+
# Copyright (c) 2025 Oracle and/or its affiliates.
|
4
|
+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
5
|
+
|
6
|
+
import logging
|
7
|
+
import os
|
8
|
+
from pathlib import Path
|
9
|
+
from typing import Dict, Optional
|
10
|
+
|
11
|
+
from ads.model.extractor.embedding_onnx_extractor import EmbeddingONNXExtractor
|
12
|
+
from ads.model.generic_model import FrameworkSpecificModel
|
13
|
+
|
14
|
+
logger = logging.getLogger(__name__)
|
15
|
+
|
16
|
+
CONFIG = "config.json"
|
17
|
+
TOKENIZERS = [
|
18
|
+
"tokenizer.json",
|
19
|
+
"tokenizer.model",
|
20
|
+
"tokenizer_config.json",
|
21
|
+
"sentencepiece.bpe.model",
|
22
|
+
"spiece.model",
|
23
|
+
"vocab.txt",
|
24
|
+
"vocab.json",
|
25
|
+
]
|
26
|
+
|
27
|
+
|
28
|
+
class EmbeddingONNXModel(FrameworkSpecificModel):
|
29
|
+
"""EmbeddingONNXModel class for embedding onnx model.
|
30
|
+
|
31
|
+
Attributes
|
32
|
+
----------
|
33
|
+
algorithm: str
|
34
|
+
The algorithm of the model.
|
35
|
+
artifact_dir: str
|
36
|
+
Artifact directory to store the files needed for deployment.
|
37
|
+
model_file_name: str
|
38
|
+
Path to the model artifact.
|
39
|
+
config_json: str
|
40
|
+
Path to the config.json file.
|
41
|
+
tokenizer_dir: str
|
42
|
+
Path to the tokenizer directory.
|
43
|
+
auth: Dict
|
44
|
+
Default authentication is set using the `ads.set_auth` API. To override the
|
45
|
+
default, use the `ads.common.auth.api_keys` or `ads.common.auth.resource_principal` to create
|
46
|
+
an authentication signer to instantiate an IdentityClient object.
|
47
|
+
framework: str
|
48
|
+
"embedding_onnx", the framework name of the model.
|
49
|
+
hyperparameter: dict
|
50
|
+
The hyperparameters of the estimator.
|
51
|
+
metadata_custom: ModelCustomMetadata
|
52
|
+
The model custom metadata.
|
53
|
+
metadata_provenance: ModelProvenanceMetadata
|
54
|
+
The model provenance metadata.
|
55
|
+
metadata_taxonomy: ModelTaxonomyMetadata
|
56
|
+
The model taxonomy metadata.
|
57
|
+
model_artifact: ModelArtifact
|
58
|
+
This is built by calling prepare.
|
59
|
+
model_deployment: ModelDeployment
|
60
|
+
A ModelDeployment instance.
|
61
|
+
model_file_name: str
|
62
|
+
Name of the serialized model.
|
63
|
+
model_id: str
|
64
|
+
The model ID.
|
65
|
+
properties: ModelProperties
|
66
|
+
ModelProperties object required to save and deploy model.
|
67
|
+
runtime_info: RuntimeInfo
|
68
|
+
A RuntimeInfo instance.
|
69
|
+
schema_input: Schema
|
70
|
+
Schema describes the structure of the input data.
|
71
|
+
schema_output: Schema
|
72
|
+
Schema describes the structure of the output data.
|
73
|
+
serialize: bool
|
74
|
+
Whether to serialize the model to pkl file by default. If False, you need to serialize the model manually,
|
75
|
+
save it under artifact_dir and update the score.py manually.
|
76
|
+
version: str
|
77
|
+
The framework version of the model.
|
78
|
+
|
79
|
+
Methods
|
80
|
+
-------
|
81
|
+
delete_deployment(...)
|
82
|
+
Deletes the current model deployment.
|
83
|
+
deploy(..., **kwargs)
|
84
|
+
Deploys a model.
|
85
|
+
from_model_artifact(uri, ..., **kwargs)
|
86
|
+
Loads model from the specified folder, or zip/tar archive.
|
87
|
+
from_model_catalog(model_id, ..., **kwargs)
|
88
|
+
Loads model from model catalog.
|
89
|
+
from_model_deployment(model_deployment_id, ..., **kwargs)
|
90
|
+
Loads model from model deployment.
|
91
|
+
update_deployment(model_deployment_id, ..., **kwargs)
|
92
|
+
Updates a model deployment.
|
93
|
+
from_id(ocid, ..., **kwargs)
|
94
|
+
Loads model from model OCID or model deployment OCID.
|
95
|
+
introspect(...)
|
96
|
+
Runs model introspection.
|
97
|
+
predict(data, ...)
|
98
|
+
Returns prediction of input data run against the model deployment endpoint.
|
99
|
+
prepare(..., **kwargs)
|
100
|
+
Prepare and save the score.py, serialized model and runtime.yaml file.
|
101
|
+
prepare_save_deploy(..., **kwargs)
|
102
|
+
Shortcut for prepare, save and deploy steps.
|
103
|
+
reload(...)
|
104
|
+
Reloads the model artifact files: `score.py` and the `runtime.yaml`.
|
105
|
+
restart_deployment(...)
|
106
|
+
Restarts the model deployment.
|
107
|
+
save(..., **kwargs)
|
108
|
+
Saves model artifacts to the model catalog.
|
109
|
+
set_model_input_serializer(serde)
|
110
|
+
Registers serializer used for serializing data passed in verify/predict.
|
111
|
+
summary_status(...)
|
112
|
+
Gets a summary table of the current status.
|
113
|
+
verify(data, ...)
|
114
|
+
Tests if deployment works in local environment.
|
115
|
+
upload_artifact(...)
|
116
|
+
Uploads model artifacts to the provided `uri`.
|
117
|
+
download_artifact(...)
|
118
|
+
Downloads model artifacts from the model catalog.
|
119
|
+
update_summary_status(...)
|
120
|
+
Update the status in the summary table.
|
121
|
+
update_summary_action(...)
|
122
|
+
Update the actions needed from the user in the summary table.
|
123
|
+
|
124
|
+
Examples
|
125
|
+
--------
|
126
|
+
>>> import tempfile
|
127
|
+
>>> import os
|
128
|
+
>>> import shutil
|
129
|
+
>>> from ads.model import EmbeddingONNXModel
|
130
|
+
>>> from huggingface_hub import snapshot_download
|
131
|
+
|
132
|
+
>>> local_dir=tempfile.mkdtemp()
|
133
|
+
>>> allow_patterns=[
|
134
|
+
... "onnx/model.onnx",
|
135
|
+
... "config.json",
|
136
|
+
... "special_tokens_map.json",
|
137
|
+
... "tokenizer_config.json",
|
138
|
+
... "tokenizer.json",
|
139
|
+
... "vocab.txt"
|
140
|
+
... ]
|
141
|
+
|
142
|
+
>>> # download files needed for this demostration to local folder
|
143
|
+
>>> snapshot_download(
|
144
|
+
... repo_id="sentence-transformers/all-MiniLM-L6-v2",
|
145
|
+
... local_dir=local_dir,
|
146
|
+
... allow_patterns=allow_patterns
|
147
|
+
... )
|
148
|
+
|
149
|
+
>>> artifact_dir = tempfile.mkdtemp()
|
150
|
+
>>> # copy all downloaded files to artifact folder
|
151
|
+
>>> for file in allow_patterns:
|
152
|
+
>>> shutil.copy(local_dir + "/" + file, artifact_dir)
|
153
|
+
|
154
|
+
>>> model = EmbeddingONNXModel(artifact_dir=artifact_dir)
|
155
|
+
>>> model.summary_status()
|
156
|
+
>>> model.prepare(
|
157
|
+
... inference_conda_env="onnxruntime_p311_gpu_x86_64",
|
158
|
+
... inference_python_version="3.11",
|
159
|
+
... model_file_name="model.onnx",
|
160
|
+
... force_overwrite=True
|
161
|
+
... )
|
162
|
+
>>> model.summary_status()
|
163
|
+
>>> model.verify(
|
164
|
+
... {
|
165
|
+
... "input": ['What are activation functions?', 'What is Deep Learning?'],
|
166
|
+
... "model": "sentence-transformers/all-MiniLM-L6-v2"
|
167
|
+
... },
|
168
|
+
... )
|
169
|
+
>>> model.summary_status()
|
170
|
+
>>> model.save(display_name="sentence-transformers/all-MiniLM-L6-v2")
|
171
|
+
>>> model.summary_status()
|
172
|
+
>>> model.deploy(
|
173
|
+
... display_name="all-MiniLM-L6-v2 Embedding deployment",
|
174
|
+
... deployment_instance_shape="VM.Standard.E4.Flex",
|
175
|
+
... deployment_ocpus=20,
|
176
|
+
... deployment_memory_in_gbs=256,
|
177
|
+
... )
|
178
|
+
>>> model.predict(
|
179
|
+
... {
|
180
|
+
... "input": ['What are activation functions?', 'What is Deep Learning?'],
|
181
|
+
... "model": "sentence-transformers/all-MiniLM-L6-v2"
|
182
|
+
... },
|
183
|
+
... )
|
184
|
+
>>> # Uncomment the line below to delete the model and the associated model deployment
|
185
|
+
>>> # model.delete(delete_associated_model_deployment = True)
|
186
|
+
"""
|
187
|
+
|
188
|
+
def __init__(
|
189
|
+
self,
|
190
|
+
artifact_dir: Optional[str] = None,
|
191
|
+
model_file_name: Optional[str] = None,
|
192
|
+
config_json: Optional[str] = None,
|
193
|
+
tokenizer_dir: Optional[str] = None,
|
194
|
+
auth: Optional[Dict] = None,
|
195
|
+
serialize: bool = False,
|
196
|
+
**kwargs: dict,
|
197
|
+
):
|
198
|
+
"""
|
199
|
+
Initiates a EmbeddingONNXModel instance.
|
200
|
+
|
201
|
+
Parameters
|
202
|
+
----------
|
203
|
+
artifact_dir: (str, optional). Defaults to None.
|
204
|
+
Directory for generate artifact.
|
205
|
+
model_file_name: (str, optional). Defaults to None.
|
206
|
+
Path to the model artifact.
|
207
|
+
config_json: (str, optional). Defaults to None.
|
208
|
+
Path to the config.json file.
|
209
|
+
tokenizer_dir: (str, optional). Defaults to None.
|
210
|
+
Path to the tokenizer directory.
|
211
|
+
auth: (Dict, optional). Defaults to None.
|
212
|
+
The default authetication is set using `ads.set_auth` API. If you need to override the
|
213
|
+
default, use the `ads.common.auth.api_keys` or `ads.common.auth.resource_principal` to create appropriate
|
214
|
+
authentication signer and kwargs required to instantiate IdentityClient object.
|
215
|
+
serialize: bool
|
216
|
+
Whether to serialize the model to pkl file by default.
|
217
|
+
Required as `False` for embedding onnx model.
|
218
|
+
|
219
|
+
Returns
|
220
|
+
-------
|
221
|
+
EmbeddingONNXModel
|
222
|
+
EmbeddingONNXModel instance.
|
223
|
+
|
224
|
+
Examples
|
225
|
+
--------
|
226
|
+
>>> import tempfile
|
227
|
+
>>> import os
|
228
|
+
>>> import shutil
|
229
|
+
>>> from ads.model import EmbeddingONNXModel
|
230
|
+
>>> from huggingface_hub import snapshot_download
|
231
|
+
|
232
|
+
>>> local_dir=tempfile.mkdtemp()
|
233
|
+
>>> allow_patterns=[
|
234
|
+
... "onnx/model.onnx",
|
235
|
+
... "config.json",
|
236
|
+
... "special_tokens_map.json",
|
237
|
+
... "tokenizer_config.json",
|
238
|
+
... "tokenizer.json",
|
239
|
+
... "vocab.txt"
|
240
|
+
... ]
|
241
|
+
|
242
|
+
>>> # download files needed for this demostration to local folder
|
243
|
+
>>> snapshot_download(
|
244
|
+
... repo_id="sentence-transformers/all-MiniLM-L6-v2",
|
245
|
+
... local_dir=local_dir,
|
246
|
+
... allow_patterns=allow_patterns
|
247
|
+
... )
|
248
|
+
|
249
|
+
>>> artifact_dir = tempfile.mkdtemp()
|
250
|
+
>>> # copy all downloaded files to artifact folder
|
251
|
+
>>> for file in allow_patterns:
|
252
|
+
>>> shutil.copy(local_dir + "/" + file, artifact_dir)
|
253
|
+
|
254
|
+
>>> model = EmbeddingONNXModel(artifact_dir=artifact_dir)
|
255
|
+
>>> model.summary_status()
|
256
|
+
>>> model.prepare(
|
257
|
+
... inference_conda_env="onnxruntime_p311_gpu_x86_64",
|
258
|
+
... inference_python_version="3.11",
|
259
|
+
... model_file_name="model.onnx",
|
260
|
+
... force_overwrite=True
|
261
|
+
... )
|
262
|
+
>>> model.summary_status()
|
263
|
+
>>> model.verify(
|
264
|
+
... {
|
265
|
+
... "input": ['What are activation functions?', 'What is Deep Learning?'],
|
266
|
+
... "model": "sentence-transformers/all-MiniLM-L6-v2"
|
267
|
+
... },
|
268
|
+
... )
|
269
|
+
>>> model.summary_status()
|
270
|
+
>>> model.save(display_name="sentence-transformers/all-MiniLM-L6-v2")
|
271
|
+
>>> model.summary_status()
|
272
|
+
>>> model.deploy(
|
273
|
+
... display_name="all-MiniLM-L6-v2 Embedding deployment",
|
274
|
+
... deployment_instance_shape="VM.Standard.E4.Flex",
|
275
|
+
... deployment_ocpus=20,
|
276
|
+
... deployment_memory_in_gbs=256,
|
277
|
+
... )
|
278
|
+
>>> model.predict(
|
279
|
+
... {
|
280
|
+
... "input": ['What are activation functions?', 'What is Deep Learning?'],
|
281
|
+
... "model": "sentence-transformers/all-MiniLM-L6-v2"
|
282
|
+
... },
|
283
|
+
... )
|
284
|
+
>>> # Uncomment the line below to delete the model and the associated model deployment
|
285
|
+
>>> # model.delete(delete_associated_model_deployment = True)
|
286
|
+
"""
|
287
|
+
super().__init__(
|
288
|
+
artifact_dir=artifact_dir,
|
289
|
+
auth=auth,
|
290
|
+
serialize=serialize,
|
291
|
+
**kwargs,
|
292
|
+
)
|
293
|
+
|
294
|
+
self._validate_artifact_directory(
|
295
|
+
model_file_name=model_file_name,
|
296
|
+
config_json=config_json,
|
297
|
+
tokenizer_dir=tokenizer_dir,
|
298
|
+
)
|
299
|
+
|
300
|
+
self._extractor = EmbeddingONNXExtractor()
|
301
|
+
self.framework = self._extractor.framework
|
302
|
+
self.algorithm = self._extractor.algorithm
|
303
|
+
self.version = self._extractor.version
|
304
|
+
self.hyperparameter = self._extractor.hyperparameter
|
305
|
+
|
306
|
+
def _validate_artifact_directory(
|
307
|
+
self,
|
308
|
+
model_file_name: str = None,
|
309
|
+
config_json: str = None,
|
310
|
+
tokenizer_dir: str = None,
|
311
|
+
):
|
312
|
+
artifacts = []
|
313
|
+
for _, _, files in os.walk(self.artifact_dir):
|
314
|
+
artifacts.extend(files)
|
315
|
+
|
316
|
+
if not artifacts:
|
317
|
+
raise ValueError(
|
318
|
+
f"No files found in {self.artifact_dir}. Specify a valid `artifact_dir`."
|
319
|
+
)
|
320
|
+
|
321
|
+
if not model_file_name:
|
322
|
+
has_model_file = False
|
323
|
+
for artifact in artifacts:
|
324
|
+
if Path(artifact).suffix.lstrip(".").lower() == "onnx":
|
325
|
+
has_model_file = True
|
326
|
+
break
|
327
|
+
|
328
|
+
if not has_model_file:
|
329
|
+
raise ValueError(
|
330
|
+
f"No onnx model found in {self.artifact_dir}. Specify a valid `artifact_dir` or `model_file_name`."
|
331
|
+
)
|
332
|
+
|
333
|
+
if not config_json:
|
334
|
+
if CONFIG not in artifacts:
|
335
|
+
logger.warning(
|
336
|
+
f"No {CONFIG} found in {self.artifact_dir}. Specify a valid `artifact_dir` or `config_json`."
|
337
|
+
)
|
338
|
+
|
339
|
+
if not tokenizer_dir:
|
340
|
+
has_tokenizer = False
|
341
|
+
for artifact in artifacts:
|
342
|
+
if artifact in TOKENIZERS:
|
343
|
+
has_tokenizer = True
|
344
|
+
break
|
345
|
+
|
346
|
+
if not has_tokenizer:
|
347
|
+
logger.warning(
|
348
|
+
f"No tokenizer found in {self.artifact_dir}. Specify a valid `artifact_dir` or `tokenizer_dir`."
|
349
|
+
)
|
350
|
+
|
351
|
+
def verify(
|
352
|
+
self, data=None, reload_artifacts=True, auto_serialize_data=False, **kwargs
|
353
|
+
):
|
354
|
+
"""Test if embedding onnx model deployment works in local environment.
|
355
|
+
|
356
|
+
Examples
|
357
|
+
--------
|
358
|
+
>>> data = {
|
359
|
+
... "input": ['What are activation functions?', 'What is Deep Learning?'],
|
360
|
+
... "model": "sentence-transformers/all-MiniLM-L6-v2"
|
361
|
+
... }
|
362
|
+
>>> prediction = model.verify(data)
|
363
|
+
|
364
|
+
Parameters
|
365
|
+
----------
|
366
|
+
data: Any
|
367
|
+
Data used to test if deployment works in local environment.
|
368
|
+
reload_artifacts: bool. Defaults to True.
|
369
|
+
Whether to reload artifacts or not.
|
370
|
+
auto_serialize_data: bool.
|
371
|
+
Whether to auto serialize input data. Required as `False` for embedding onnx model.
|
372
|
+
Input `data` must be json serializable.
|
373
|
+
kwargs:
|
374
|
+
content_type: str, used to indicate the media type of the resource.
|
375
|
+
image: PIL.Image Object or uri for the image.
|
376
|
+
A valid string path for image file can be local path, http(s), oci, s3, gs.
|
377
|
+
storage_options: dict
|
378
|
+
Passed to `fsspec.open` for a particular storage connection.
|
379
|
+
Please see `fsspec` (https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.open) for more details.
|
380
|
+
|
381
|
+
Returns
|
382
|
+
-------
|
383
|
+
Dict
|
384
|
+
A dictionary which contains prediction results.
|
385
|
+
"""
|
386
|
+
if auto_serialize_data:
|
387
|
+
raise ValueError(
|
388
|
+
"ADS will not auto serialize `data` for embedding onnx model. "
|
389
|
+
"Input json serializable `data` and set `auto_serialize_data` as False."
|
390
|
+
)
|
391
|
+
|
392
|
+
return super().verify(
|
393
|
+
data=data,
|
394
|
+
reload_artifacts=reload_artifacts,
|
395
|
+
auto_serialize_data=auto_serialize_data,
|
396
|
+
**kwargs,
|
397
|
+
)
|
398
|
+
|
399
|
+
def predict(self, data=None, auto_serialize_data=False, **kwargs):
|
400
|
+
"""Returns prediction of input data run against the embedding onnx model deployment endpoint.
|
401
|
+
|
402
|
+
Examples
|
403
|
+
--------
|
404
|
+
>>> data = {
|
405
|
+
... "input": ['What are activation functions?', 'What is Deep Learning?'],
|
406
|
+
... "model": "sentence-transformers/all-MiniLM-L6-v2"
|
407
|
+
... }
|
408
|
+
>>> prediction = model.predict(data)
|
409
|
+
|
410
|
+
Parameters
|
411
|
+
----------
|
412
|
+
data: Any
|
413
|
+
Data for the prediction for model deployment.
|
414
|
+
auto_serialize_data: bool.
|
415
|
+
Whether to auto serialize input data. Required as `False` for embedding onnx model.
|
416
|
+
Input `data` must be json serializable.
|
417
|
+
kwargs:
|
418
|
+
content_type: str, used to indicate the media type of the resource.
|
419
|
+
image: PIL.Image Object or uri for the image.
|
420
|
+
A valid string path for image file can be local path, http(s), oci, s3, gs.
|
421
|
+
storage_options: dict
|
422
|
+
Passed to `fsspec.open` for a particular storage connection.
|
423
|
+
Please see `fsspec` (https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.open) for more details.
|
424
|
+
|
425
|
+
Returns
|
426
|
+
-------
|
427
|
+
Dict[str, Any]
|
428
|
+
Dictionary with the predicted values.
|
429
|
+
"""
|
430
|
+
if auto_serialize_data:
|
431
|
+
raise ValueError(
|
432
|
+
"ADS will not auto serialize `data` for embedding onnx model. "
|
433
|
+
"Input json serializable `data` and set `auto_serialize_data` as False."
|
434
|
+
)
|
435
|
+
|
436
|
+
return super().predict(
|
437
|
+
data=data, auto_serialize_data=auto_serialize_data, **kwargs
|
438
|
+
)
|
ads/model/generic_model.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*--
|
3
2
|
|
4
3
|
# Copyright (c) 2022, 2024 Oracle and/or its affiliates.
|
5
4
|
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
|
@@ -8,9 +7,9 @@ import inspect
|
|
8
7
|
import os
|
9
8
|
import shutil
|
10
9
|
import tempfile
|
10
|
+
import warnings
|
11
11
|
from enum import Enum
|
12
12
|
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, TypeVar, Union
|
13
|
-
import warnings
|
14
13
|
|
15
14
|
import numpy as np
|
16
15
|
import pandas as pd
|
@@ -21,8 +20,8 @@ from PIL import Image
|
|
21
20
|
from ads.common import auth as authutil
|
22
21
|
from ads.common import logger, utils
|
23
22
|
from ads.common.decorator.utils import class_or_instance_method
|
24
|
-
from ads.common.utils import DATA_SCHEMA_MAX_COL_NUM, get_files
|
25
23
|
from ads.common.object_storage_details import ObjectStorageDetails
|
24
|
+
from ads.common.utils import DATA_SCHEMA_MAX_COL_NUM, get_files
|
26
25
|
from ads.config import (
|
27
26
|
CONDA_BUCKET_NS,
|
28
27
|
JOB_RUN_COMPARTMENT_OCID,
|
@@ -49,11 +48,11 @@ from ads.model.deployment import (
|
|
49
48
|
DEFAULT_POLL_INTERVAL,
|
50
49
|
DEFAULT_WAIT_TIME,
|
51
50
|
ModelDeployment,
|
52
|
-
ModelDeploymentMode,
|
53
|
-
ModelDeploymentProperties,
|
54
51
|
ModelDeploymentCondaRuntime,
|
55
|
-
ModelDeploymentInfrastructure,
|
56
52
|
ModelDeploymentContainerRuntime,
|
53
|
+
ModelDeploymentInfrastructure,
|
54
|
+
ModelDeploymentMode,
|
55
|
+
ModelDeploymentProperties,
|
57
56
|
)
|
58
57
|
from ads.model.deployment.common.utils import State as ModelDeploymentState
|
59
58
|
from ads.model.deployment.common.utils import send_request
|
@@ -66,10 +65,10 @@ from ads.model.model_introspect import (
|
|
66
65
|
from ads.model.model_metadata import (
|
67
66
|
ExtendedEnumMeta,
|
68
67
|
Framework,
|
68
|
+
MetadataCustomCategory,
|
69
69
|
ModelCustomMetadata,
|
70
70
|
ModelProvenanceMetadata,
|
71
71
|
ModelTaxonomyMetadata,
|
72
|
-
MetadataCustomCategory,
|
73
72
|
)
|
74
73
|
from ads.model.model_metadata_mixin import MetadataMixin
|
75
74
|
from ads.model.model_properties import ModelProperties
|
@@ -940,11 +939,10 @@ class GenericModel(MetadataMixin, Introspectable, EvaluatorMixin):
|
|
940
939
|
manifest = fetch_manifest_from_conda_location(conda_prefix)
|
941
940
|
if "pack_path" in manifest:
|
942
941
|
self.properties.inference_conda_env = manifest["pack_path"]
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
)
|
942
|
+
elif not self.ignore_conda_error:
|
943
|
+
raise ValueError(
|
944
|
+
"`inference_conda_env` must be specified for conda runtime. If you are using container runtime, set `ignore_conda_error=True`."
|
945
|
+
)
|
948
946
|
self.properties.inference_python_version = (
|
949
947
|
manifest["python"]
|
950
948
|
if "python" in manifest
|
@@ -1025,7 +1023,7 @@ class GenericModel(MetadataMixin, Introspectable, EvaluatorMixin):
|
|
1025
1023
|
detail=PREPARE_STATUS_SERIALIZE_MODEL_DETAIL,
|
1026
1024
|
status=ModelState.DONE.value,
|
1027
1025
|
)
|
1028
|
-
except SerializeModelNotImplementedError
|
1026
|
+
except SerializeModelNotImplementedError:
|
1029
1027
|
if not utils.is_path_exists(
|
1030
1028
|
uri=os.path.join(self.artifact_dir, self.model_file_name),
|
1031
1029
|
auth=self.auth,
|
@@ -1056,17 +1054,19 @@ class GenericModel(MetadataMixin, Introspectable, EvaluatorMixin):
|
|
1056
1054
|
except Exception as e:
|
1057
1055
|
raise e
|
1058
1056
|
|
1057
|
+
if self.framework == Framework.EMBEDDING_ONNX:
|
1058
|
+
self.model_artifact.prepare_schema(schema_name="openapi.json")
|
1059
|
+
|
1059
1060
|
if as_onnx:
|
1060
1061
|
jinja_template_filename = "score_onnx_new"
|
1062
|
+
elif self.framework and self.framework != "other":
|
1063
|
+
jinja_template_filename = "score_" + self.framework
|
1064
|
+
if self.framework == "transformers":
|
1065
|
+
jinja_template_filename = "score_" + "huggingface_pipeline"
|
1061
1066
|
else:
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
jinja_template_filename = "score_" + "huggingface_pipeline"
|
1066
|
-
else:
|
1067
|
-
jinja_template_filename = (
|
1068
|
-
"score-pkl" if self._serialize else "score_generic"
|
1069
|
-
)
|
1067
|
+
jinja_template_filename = (
|
1068
|
+
"score-pkl" if self._serialize else "score_generic"
|
1069
|
+
)
|
1070
1070
|
|
1071
1071
|
if score_py_uri:
|
1072
1072
|
utils.copy_file(
|
@@ -1276,7 +1276,7 @@ class GenericModel(MetadataMixin, Introspectable, EvaluatorMixin):
|
|
1276
1276
|
if self.model_artifact is None:
|
1277
1277
|
raise ArtifactsNotAvailableError
|
1278
1278
|
|
1279
|
-
endpoint =
|
1279
|
+
endpoint = "http://127.0.0.1:8000/predict"
|
1280
1280
|
data = self._handle_input_data(data, auto_serialize_data, **kwargs)
|
1281
1281
|
|
1282
1282
|
request_body = send_request(
|
@@ -2179,7 +2179,7 @@ class GenericModel(MetadataMixin, Introspectable, EvaluatorMixin):
|
|
2179
2179
|
)
|
2180
2180
|
self.update_summary_action(
|
2181
2181
|
detail=SAVE_STATUS_INTROSPECT_TEST_DETAIL,
|
2182
|
-
action=
|
2182
|
+
action="Use `.introspect()` method to get detailed information.",
|
2183
2183
|
)
|
2184
2184
|
raise IntrospectionNotPassed(msg)
|
2185
2185
|
else:
|
@@ -2470,7 +2470,9 @@ class GenericModel(MetadataMixin, Introspectable, EvaluatorMixin):
|
|
2470
2470
|
.with_shape_name(self.properties.deployment_instance_shape)
|
2471
2471
|
.with_replica(self.properties.deployment_instance_count)
|
2472
2472
|
.with_subnet_id(self.properties.deployment_instance_subnet_id)
|
2473
|
-
.with_private_endpoint_id(
|
2473
|
+
.with_private_endpoint_id(
|
2474
|
+
self.properties.deployment_instance_private_endpoint_id
|
2475
|
+
)
|
2474
2476
|
)
|
2475
2477
|
|
2476
2478
|
web_concurrency = (
|