Skip to content

Commit cbf43e3

Browse files
committed
update
1 parent da4821b commit cbf43e3

File tree

7 files changed

+58
-81
lines changed

7 files changed

+58
-81
lines changed

docs/source/ads.model.extractor.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ ads.model.extractor package
44
Submodules
55
----------
66

7-
ads.model.extractor.automl\_extractor module
8-
--------------------------------------------
9-
10-
.. automodule:: ads.model.extractor.automl_extractor
11-
:members:
12-
:undoc-members:
13-
:show-inheritance:
14-
157
ads.model.extractor.keras\_extractor module
168
-------------------------------------------
179

docs/source/user_guide/model_registration/frameworks/automlmodel.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ AutoMLModel
88
Working with AutoML has moved from within ADS to working directly with the automlx library.
99
To deploy an AutoMlx model, use `GenericModel <../../../ads.model.html#ads.model.generic_model.GenericModel>`__ class.
1010

11-
The following example take your trained ``AutoML`` model using ``GenericModel`` and deploy it into production.
11+
The following example takes your trained ``AutoML`` model using ``GenericModel`` and deploys it into production.
1212

1313

1414
Example
@@ -244,7 +244,7 @@ Verify score.py changes by running inference locally.
244244
245245
automl_model.verify(X_test.iloc[:2], auto_serialize_data=True)
246246
247-
Save model and Deploy the model. After it is successfully deployed, invoke the endpoint by calling .predict() function.
247+
Save the model, and Deploy the model. After it is successfully deployed, invoke the endpoint by calling .predict() function.
248248

249249

250250
.. code-block:: python3

docs/source/user_guide/model_registration/frameworks/genericmodel.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Overview
1111

1212
The ``ads.model.generic_model.GenericModel`` class in ADS provides an efficient way to serialize almost any model class. This section demonstrates how to use the ``GenericModel`` class to prepare model artifacts, verify models, save models to the model catalog, deploy models, and perform predictions on model deployment endpoints.
1313

14-
The ``GenericModel`` class works with any unsupported model framework that has a ``.predict()`` method. For the most common model classes such as scikit-learn, XGBoost, LightGBM, TensorFlow, and PyTorch, and AutoML, we recommend that you use the ADS provided, framework-specific serializations models. For example, for a scikit-learn model, use SKLearnmodel. For other models, use the ``GenericModel`` class.
14+
The ``GenericModel`` class works with any unsupported model framework that has a ``.predict()`` method. For the most common model classes such as scikit-learn, XGBoost, LightGBM, TensorFlow, and PyTorch, we recommend that you use the ADS provided, framework-specific serializations models. For example, for a scikit-learn model, use SKLearnmodel. For other models, use the ``GenericModel`` class.
1515

1616
.. include:: ../_template/overview.rst
1717

@@ -177,7 +177,7 @@ Example -- Save Your Own Model
177177
==============================
178178

179179
By default, the ``serialize`` in ``GenericModel`` class is True, and it will serialize the model using cloudpickle. However, you can set ``serialize=False`` to disable it. And serialize the model on your own. You just need to copy the serialized model into the ``.artifact_dir``. This example shows step by step how you can do that.
180-
The example is illustrated using an AutoMLx model.
180+
The example is illustrated using a Sklearn model.
181181

182182
.. code-block:: python3
183183
@@ -369,8 +369,8 @@ After verify run successfully, you can save the model to model catalog, deploy a
369369

370370
.. code-block:: python3
371371
372-
model_id = model.save(display_name='Demo AutoMLModel model')
373-
deploy = model.deploy(display_name='Demo AutoMLModel deployment')
372+
model_id = model.save(display_name='Demo Sklearn model')
373+
deploy = model.deploy(display_name='Demo Sklearn deployment')
374374
model.predict(X_test[:2].tolist())
375375
376376
You can also use the shortcut ``.prepare_save_deploy()`` instead of calling ``.prepare()``, ``.save()`` and ``.deploy()`` seperately.
@@ -393,4 +393,4 @@ You can also use the shortcut ``.prepare_save_deploy()`` instead of calling ``.p
393393
model.verify(2)
394394
model.predict(2)
395395
model.delete_deployment(wait_for_completion=True)
396-
ModelCatalog(compartment_id=os.environ['NB_SESSION_COMPARTMENT_OCID']).delete_model(model.model_id)
396+
model.delete()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
You can call the ``.summary_status()`` method after a model serialization instance such as ``AutoMLModel``, ``GenericModel``, ``SklearnModel``, ``TensorFlowModel``, or ``PyTorchModel`` is created. The ``.summary_status()`` method returns a Pandas dataframe that guides you through the entire workflow. It shows which methods are available to call and which ones aren't. Plus it outlines what each method does. If extra actions are required, it also shows those actions.
1+
You can call the ``.summary_status()`` method after a model serialization instance such as ``GenericModel``, ``SklearnModel``, ``TensorFlowModel``, or ``PyTorchModel`` is created. The ``.summary_status()`` method returns a Pandas dataframe that guides you through the entire workflow. It shows which methods are available to call and which ones aren't. Plus it outlines what each method does. If extra actions are required, it also shows those actions.
22

33
The following image displays an example summary status table created after a user initiates a model instance. The table's Step column displays a Status of Done for the initiate step. And the ``Details`` column explains what the initiate step did such as generating a ``score.py`` file. The Step column also displays the ``prepare()``, ``verify()``, ``save()``, ``deploy()``, and ``predict()`` methods for the model. The Status column displays which method is available next. After the initiate step, the ``prepare()`` method is available. The next step is to call the ``prepare()`` method.
44

docs/source/user_guide/model_serialization/automlmodel.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The ``ads.model.framework.automl_model.AutoMLModel`` class is deprecated. See th
99

1010
To deploy an AutoMlx model, use `GenericModel <../../../ads.model.html#ads.model.generic_model.GenericModel>`__ class.
1111

12-
The following example take your trained ``AutoML`` model using ``GenericModel`` and deploy it into production with a few lines of code.
12+
The following example takes your trained ``AutoML`` model using ``GenericModel`` and deploys it into production with a few lines of code.
1313

1414

1515
Example
@@ -245,7 +245,7 @@ Verify score.py changes by running inference locally
245245
246246
automl_model.verify(X_test.iloc[:2])
247247
248-
Save model and Deploy the model. After it is successfully deployed, invoke the endpoint by calling .predict() function.
248+
Save model, and Deploy the model. After it is successfully deployed, invoke the endpoint by calling .predict() function.
249249
.. code-block:: python3
250250
251251
model_id = automl_model.save(display_name='Demo AutoMLModel model')

docs/source/user_guide/model_serialization/genericmodel.rst

Lines changed: 47 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Overview
88

99
The ``GenericModel`` class in ADS provides an efficient way to serialize almost any model class. This section demonstrates how to use the ``GenericModel`` class to prepare model artifacts, verify models, save models to the model catalog, deploy models, and perform predictions on model deployment endpoints.
1010

11-
The ``GenericModel`` class works with any unsupported model framework that has a ``.predict()`` method. For the most common model classes such as scikit-learn, XGBoost, LightGBM, TensorFlow, and PyTorch, and AutoML, we recommend that you use the ADS provided, framework-specific serializations models. For example, for a scikit-learn model, use SKLearnmodel. For other models, use the ``GenericModel`` class.
11+
The ``GenericModel`` class works with any unsupported model framework that has a ``.predict()`` method. For the most common model classes such as scikit-learn, XGBoost, LightGBM, TensorFlow, and PyTorch, we recommend that you use the ADS provided, framework-specific serializations models. For example, for a scikit-learn model, use SKLearnmodel. For other models, use the ``GenericModel`` class.
1212

1313
.. include:: _template/overview.rst
1414

@@ -190,83 +190,46 @@ By default, the ``GenericModel`` serializes to a pickle file. The following exam
190190
catboost_model.delete_deployment(wait_for_completion=True)
191191
catboost_model.delete() # delete the model
192192
193-
You can also use the shortcut ``.prepare_save_deploy()`` instead of calling ``.prepare()``, ``.save()`` and ``.deploy()`` seperately.
194-
195-
.. code-block:: python3
196-
197-
import tempfile
198-
from ads.catalog.model import ModelCatalog
199-
from ads.model.generic_model import GenericModel
200-
201-
class Toy:
202-
def predict(self, x):
203-
return x ** 2
204-
estimator = Toy()
205-
206-
model = GenericModel(estimator=estimator)
207-
model.summary_status()
208-
# If you are running the code inside a notebook session and using a service pack, `inference_conda_env` can be omitted.
209-
model.prepare_save_deploy(inference_conda_env="dataexpl_p37_cpu_v3")
210-
model.verify(2)
211-
model.predict(2)
212-
model.delete_deployment(wait_for_completion=True)
213-
ModelCatalog(compartment_id=os.environ['NB_SESSION_COMPARTMENT_OCID']).delete_model(model.model_id)
214-
215193
216194
Example -- Save Your Own Model
217195
==============================
218196

219197
By default, the ``serialize`` in ``GenericModel`` class is True, and it will serialize the model using cloudpickle. However, you can set ``serialize=False`` to disable it. And serialize the model on your own. You just need to copy the serialized model into the ``.artifact_dir``. This example shows step by step how you can do that.
220-
The example is illustrated using an AutoMLx model.
198+
The example is illustrated using a Sklearn model.
221199

222200
.. code-block:: python3
223201
224-
import automl
225-
import ads
226-
from automl import init
227-
from sklearn.datasets import fetch_openml
228-
from sklearn.model_selection import train_test_split
202+
import tempfile
203+
from ads import set_auth
229204
from ads.model import GenericModel
205+
from sklearn.datasets import load_iris
206+
from sklearn.linear_model import LogisticRegression
207+
from sklearn.model_selection import train_test_split
230208
231-
dataset = fetch_openml(name='adult', as_frame=True)
232-
df, y = dataset.data, dataset.target
233-
234-
# Several of the columns are incorrectly labeled as category type in the original dataset
235-
numeric_columns = ['age', 'capitalgain', 'capitalloss', 'hoursperweek']
236-
for col in df.columns:
237-
if col in numeric_columns:
238-
df[col] = df[col].astype(int)
239-
240-
241-
X_train, X_test, y_train, y_test = train_test_split(df,
242-
y.map({'>50K': 1, '<=50K': 0}).astype(int),
243-
train_size=0.7,
244-
random_state=0)
245-
246-
X_train.shape, X_test.shape
247-
248-
# create a AutoMLx model
249-
init(engine='local')
209+
set_auth(auth="resource_principal")
250210
251-
est = automl.Pipeline(task='classification')
252-
est.fit(X_train, y_train)
211+
# Load dataset and Prepare train and test split
212+
iris = load_iris()
213+
X, y = iris.data, iris.target
214+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)
253215
254-
# Authentication
255-
ads.set_auth(auth="resource_principal")
216+
# Train a LogisticRegression model
217+
sklearn_estimator = LogisticRegression()
218+
sklearn_estimator.fit(X_train, y_train)
256219
257220
# Serialize your model. You can choose your own way to serialize your model.
258221
import cloudpickle
259222
with open("./model.pkl", "wb") as f:
260-
cloudpickle.dump(est, f)
223+
cloudpickle.dump(sklearn_estimator, f)
261224
262-
model = GenericModel(est, artifact_dir = "model_artifact_folder", serialize=False)
263-
model.prepare(inference_conda_env="automlx_p38_cpu_v1",force_overwrite=True, model_file_name="model.pkl", X_sample=X_test)
225+
model = GenericModel(sklearn_estimator, artifact_dir = "model_artifact_folder", serialize=False)
226+
model.prepare(inference_conda_env="generalml_p38_cpu_v1",force_overwrite=True, model_file_name="model.pkl", X_sample=X_test)
264227
265-
Now copy the model.pkl file and paste into the ``model_artifact_folder`` folder. And open the score.py in the ``model_artifact_folder`` folder and add implement the ``load_model`` function. You can also edit ``pre_inference`` and ``post_inference`` function. Below is an example implementation of the score.py.
228+
Now copy the model.pkl file and paste into the ``model_artifact_folder`` folder. And open the score.py in the ``model_artifact_folder`` folder to add implementation of the ``load_model`` function. You can also add your preprocessing steps in ``pre_inference`` function and postprocessing steps in ``post_inference`` function. Below is an example implementation of the score.py.
266229
Replace your score.py with the code below.
267230

268231
.. code-block:: python3
269-
:emphasize-lines: 28, 29, 30, 31, 122
232+
:emphasize-lines: 28, 29, 30, 31, 123
270233
271234
# score.py 1.0 generated by ADS 2.8.2 on 20230301_065458
272235
import os
@@ -414,16 +377,38 @@ Replace your score.py with the code below.
414377
)
415378
return {'prediction': yhat}
416379
417-
Save the score.py and now call verify to check if it works locally.
380+
Save the score.py and now call ``.verify()`` to check if it works locally.
418381

419382
.. code-block:: python3
420383
421-
model.verify(X_test.iloc[:2], auto_serialize_data=True)
384+
model.verify(X_test[:2], auto_serialize_data=True)
422385
423386
After verify run successfully, you can save the model to model catalog, deploy and call predict to invoke the endpoint.
424387

425388
.. code-block:: python3
426389
427-
model_id = model.save(display_name='Demo AutoMLModel model')
428-
deploy = model.deploy(display_name='Demo AutoMLModel deployment')
429-
model.predict(X_test.iloc[:2].to_json())
390+
model_id = model.save(display_name='Demo Sklearn model')
391+
deploy = model.deploy(display_name='Demo Sklearn deployment')
392+
model.predict(X_test[:2].tolist())
393+
394+
You can also use the shortcut ``.prepare_save_deploy()`` instead of calling ``.prepare()``, ``.save()`` and ``.deploy()`` seperately.
395+
396+
.. code-block:: python3
397+
398+
import tempfile
399+
from ads.catalog.model import ModelCatalog
400+
from ads.model.generic_model import GenericModel
401+
402+
class Toy:
403+
def predict(self, x):
404+
return x ** 2
405+
estimator = Toy()
406+
407+
model = GenericModel(estimator=estimator)
408+
model.summary_status()
409+
# If you are running the code inside a notebook session and using a service pack, `inference_conda_env` can be omitted.
410+
model.prepare_save_deploy(inference_conda_env="dataexpl_p37_cpu_v3")
411+
model.verify(2)
412+
model.predict(2)
413+
model.delete_deployment(wait_for_completion=True)
414+
model.delete()

docs/source/user_guide/model_training/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Train Models
33
============
44

55
In this section you will learn about model training on the Data Science cloud service using a variety of popular frameworks. This section
6-
covers the popular ``sklearn`` framework, along with gradient boosted tree estimators like LightGBM and XGBoost, Oracle AutoML and
6+
covers the popular ``sklearn`` framework, along with gradient boosted tree estimators like LightGBM and XGBoost, and
77
deep learning packages likes TensorFlow and PyTorch.
88

99
The section covers how to serialize models and make use of the OCI Model Catalog to store model artifacts and meta data all using

0 commit comments

Comments
 (0)