oracle-ads 2.12.9__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/common/enums.py +3 -0
- ads/aqua/common/utils.py +62 -2
- ads/aqua/data.py +2 -19
- ads/aqua/extension/finetune_handler.py +8 -14
- ads/aqua/extension/model_handler.py +19 -2
- ads/aqua/finetuning/constants.py +5 -2
- ads/aqua/finetuning/entities.py +64 -17
- ads/aqua/finetuning/finetuning.py +38 -54
- ads/aqua/model/entities.py +2 -1
- ads/aqua/model/model.py +61 -23
- 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/langchain/plugins/chat_models/oci_data_science.py +12 -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 +2 -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 +61 -14
- 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/schema.yaml +13 -0
- ads/opctl/operator/lowcode/forecast/utils.py +4 -3
- 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.9.dist-info → oracle_ads-2.12.10rc0.dist-info}/METADATA +7 -8
- {oracle_ads-2.12.9.dist-info → oracle_ads-2.12.10rc0.dist-info}/RECORD +60 -39
- {oracle_ads-2.12.9.dist-info → oracle_ads-2.12.10rc0.dist-info}/LICENSE.txt +0 -0
- {oracle_ads-2.12.9.dist-info → oracle_ads-2.12.10rc0.dist-info}/WHEEL +0 -0
- {oracle_ads-2.12.9.dist-info → oracle_ads-2.12.10rc0.dist-info}/entry_points.txt +0 -0
@@ -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 = (
|
ads/model/model_metadata.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*--
|
3
2
|
|
4
3
|
# Copyright (c) 2021, 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/
|
@@ -11,20 +10,21 @@ import sys
|
|
11
10
|
from abc import ABC, abstractmethod
|
12
11
|
from dataclasses import dataclass, field, fields
|
13
12
|
from pathlib import Path
|
14
|
-
from typing import Dict, List, Tuple, Union
|
13
|
+
from typing import Any, Dict, List, Optional, Tuple, Union
|
15
14
|
|
16
|
-
import ads.dataset.factory as factory
|
17
15
|
import fsspec
|
18
16
|
import git
|
19
17
|
import oci.data_science.models
|
20
18
|
import pandas as pd
|
21
19
|
import yaml
|
20
|
+
from oci.util import to_dict
|
21
|
+
|
22
22
|
from ads.common import logger
|
23
23
|
from ads.common.error import ChangesNotCommitted
|
24
24
|
from ads.common.extended_enum import ExtendedEnumMeta
|
25
|
-
from ads.common.serializer import DataClassSerializable
|
26
25
|
from ads.common.object_storage_details import ObjectStorageDetails
|
27
|
-
from
|
26
|
+
from ads.common.serializer import DataClassSerializable
|
27
|
+
from ads.dataset import factory
|
28
28
|
|
29
29
|
try:
|
30
30
|
from yaml import CDumper as dumper
|
@@ -173,6 +173,7 @@ class Framework(str, metaclass=ExtendedEnumMeta):
|
|
173
173
|
WORD2VEC = "word2vec"
|
174
174
|
ENSEMBLE = "ensemble"
|
175
175
|
SPARK = "pyspark"
|
176
|
+
EMBEDDING_ONNX = "embedding_onnx"
|
176
177
|
OTHER = "other"
|
177
178
|
|
178
179
|
|
@@ -1398,7 +1399,7 @@ class ModelCustomMetadata(ModelMetadata):
|
|
1398
1399
|
if (
|
1399
1400
|
not data
|
1400
1401
|
or not isinstance(data, Dict)
|
1401
|
-
or
|
1402
|
+
or "data" not in data
|
1402
1403
|
or not isinstance(data["data"], List)
|
1403
1404
|
):
|
1404
1405
|
raise ValueError(
|
@@ -1550,7 +1551,7 @@ class ModelTaxonomyMetadata(ModelMetadata):
|
|
1550
1551
|
if (
|
1551
1552
|
not data
|
1552
1553
|
or not isinstance(data, Dict)
|
1553
|
-
or
|
1554
|
+
or "data" not in data
|
1554
1555
|
or not isinstance(data["data"], List)
|
1555
1556
|
):
|
1556
1557
|
raise ValueError(
|
ads/opctl/config/merger.py
CHANGED
@@ -1,35 +1,33 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8; -*-
|
3
2
|
|
4
|
-
# Copyright (c) 2022,
|
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/
|
6
5
|
|
7
6
|
import os
|
8
7
|
from string import Template
|
9
8
|
from typing import Dict
|
10
|
-
import json
|
11
9
|
|
12
10
|
import yaml
|
13
11
|
|
14
12
|
from ads.common.auth import AuthType, ResourcePrincipal
|
15
13
|
from ads.opctl import logger
|
16
14
|
from ads.opctl.config.base import ConfigProcessor
|
17
|
-
from ads.opctl.config.utils import
|
18
|
-
from ads.opctl.utils import is_in_notebook_session, get_service_pack_prefix
|
15
|
+
from ads.opctl.config.utils import _DefaultNoneDict, read_from_ini
|
19
16
|
from ads.opctl.constants import (
|
20
|
-
DEFAULT_PROFILE,
|
21
|
-
DEFAULT_OCI_CONFIG_FILE,
|
22
|
-
DEFAULT_CONDA_PACK_FOLDER,
|
23
|
-
DEFAULT_ADS_CONFIG_FOLDER,
|
24
|
-
ADS_JOBS_CONFIG_FILE_NAME,
|
25
17
|
ADS_CONFIG_FILE_NAME,
|
26
|
-
ADS_ML_PIPELINE_CONFIG_FILE_NAME,
|
27
18
|
ADS_DATAFLOW_CONFIG_FILE_NAME,
|
19
|
+
ADS_JOBS_CONFIG_FILE_NAME,
|
28
20
|
ADS_LOCAL_BACKEND_CONFIG_FILE_NAME,
|
21
|
+
ADS_ML_PIPELINE_CONFIG_FILE_NAME,
|
29
22
|
ADS_MODEL_DEPLOYMENT_CONFIG_FILE_NAME,
|
30
|
-
DEFAULT_NOTEBOOK_SESSION_CONDA_DIR,
|
31
23
|
BACKEND_NAME,
|
24
|
+
DEFAULT_ADS_CONFIG_FOLDER,
|
25
|
+
DEFAULT_CONDA_PACK_FOLDER,
|
26
|
+
DEFAULT_NOTEBOOK_SESSION_CONDA_DIR,
|
27
|
+
DEFAULT_OCI_CONFIG_FILE,
|
28
|
+
DEFAULT_PROFILE,
|
32
29
|
)
|
30
|
+
from ads.opctl.utils import get_service_pack_prefix, is_in_notebook_session
|
33
31
|
|
34
32
|
|
35
33
|
class ConfigMerger(ConfigProcessor):
|
@@ -41,8 +39,9 @@ class ConfigMerger(ConfigProcessor):
|
|
41
39
|
"""
|
42
40
|
|
43
41
|
def process(self, **kwargs) -> None:
|
44
|
-
|
45
|
-
|
42
|
+
for key, value in self.config.items():
|
43
|
+
if isinstance(value, str): # Substitute only if the value is a string
|
44
|
+
self.config[key] = Template(value).safe_substitute(os.environ)
|
46
45
|
|
47
46
|
if "runtime" not in self.config:
|
48
47
|
self.config["runtime"] = {}
|