Skip to content

Commit 65802f9

Browse files
authored
quick docs (#101)
2 parents c98bc1b + a6348e3 commit 65802f9

File tree

5 files changed

+81
-8
lines changed

5 files changed

+81
-8
lines changed

ads/model/framework/huggingface_model.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ class HuggingFacePipelineModel(FrameworkSpecificModel):
9292
verify(data, ...)
9393
Tests if deployment works in local environment.
9494
95-
Examples - Image Classification
96-
-------------------------------
95+
Examples
96+
--------
97+
>>> # Image Classification
9798
>>> from transformers import pipeline
9899
>>> import tempfile
99100
>>> import PIL.Image
@@ -133,8 +134,9 @@ class HuggingFacePipelineModel(FrameworkSpecificModel):
133134
>>> headers = {"Content-Type": "application/octet-stream"}
134135
>>> requests.post(endpoint, data=image_bytes, auth=auth, headers=headers).json()
135136
136-
Examples - Image Segmentation
137-
-----------------------------
137+
Examples
138+
--------
139+
>>> # Image Segmentation
138140
>>> from transformers import pipeline
139141
>>> import tempfile
140142
>>> import PIL.Image
@@ -177,8 +179,9 @@ class HuggingFacePipelineModel(FrameworkSpecificModel):
177179
>>> headers = {"Content-Type": "application/octet-stream"}
178180
>>> requests.post(endpoint, data=image_bytes, auth=auth, headers=headers).json()
179181
180-
Examples - Zero Shot Image Classification
181-
-----------------------------------------
182+
Examples
183+
--------
184+
>>> # Zero Shot Image Classification
182185
>>> from transformers import pipeline
183186
>>> import tempfile
184187
>>> import PIL.Image

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# This causes documentation within the __init__ method to be pulled into the documentation properly
1010
autoclass_content = "both"
1111

12-
sys.path.insert(0, os.path.abspath("../../ads"))
12+
sys.path.insert(0, os.path.abspath("../.."))
1313

1414
# -- Project information -----------------------------------------------------
1515

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Example
219219
zero_shot_image_classification_model = HuggingFacePipelineModel(classifier, artifact_dir=tempfile.mkdtemp())
220220
221221
# Autogenerate score.py, serialized model, runtime.yaml
222-
conda_pack_path = "oci://bucket@namespace/path/to/conda/pack"
222+
conda_pack_path = "oci://bucket@namespace/path/to/conda/pack" # your published conda pack
223223
python_version = "3.x" # Remember to update 3.x with your actual python version, e.g. 3.8
224224
zero_shot_image_classification_model.prepare(inference_conda_env=conda_pack_path, inference_python_version = python_version, force_overwrite=True)
225225

docs/source/user_guide/model_registration/quick_start.rst

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,68 @@ Create a model, prepare it, verify that it works, save it to the model catalog,
278278
model_id = tf_model.save(display_name="TensorFlow Model")
279279
280280
281+
HuggingFace Pipelines
282+
---------------------
283+
284+
.. code-block:: python3
285+
286+
from transformers import pipeline
287+
from ads.model import HuggingFacePipelineModel
288+
289+
import tempfile
290+
import PIL.Image
291+
from ads.common.auth import default_signer
292+
import requests
293+
import cloudpickle
294+
295+
## download the image
296+
image_url = "https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png"
297+
image = PIL.Image.open(requests.get(image_url, stream=True).raw)
298+
299+
## download the pretrained model
300+
classifier = pipeline(model="openai/clip-vit-large-patch14")
301+
classifier(
302+
images=image,
303+
candidate_labels=["animals", "humans", "landscape"],
304+
)
305+
306+
## Initiate a HuggingFacePipelineModel instance
307+
zero_shot_image_classification_model = HuggingFacePipelineModel(classifier, artifact_dir=tempfile.mkdtemp())
308+
309+
# Autogenerate score.py, serialized model, runtime.yaml
310+
conda_pack_path = "oci://bucket@namespace/path/to/conda/pack"
311+
python_version = "3.x" # Remember to update 3.x with your actual python version, e.g. 3.8
312+
zero_shot_image_classification_model.prepare(inference_conda_env=conda_pack_path, inference_python_version = python_version, force_overwrite=True)
313+
314+
## Convert payload to bytes
315+
data = {"images": image, "candidate_labels": ["animals", "humans", "landscape"]}
316+
body = cloudpickle.dumps(data) # convert image to bytes
317+
318+
# Verify generated artifacts
319+
zero_shot_image_classification_model.verify(data=data)
320+
zero_shot_image_classification_model.verify(data=body)
321+
322+
# Register HuggingFace Pipeline model
323+
zero_shot_image_classification_model.save()
324+
325+
## Deploy
326+
log_group_id = "<log_group_id>"
327+
log_id = "<log_id>"
328+
zero_shot_image_classification_model.deploy(deployment_bandwidth_mbps=100,
329+
wait_for_completion=False,
330+
deployment_log_group_id = log_group_id,
331+
deployment_access_log_id = log_id,
332+
deployment_predict_log_id = log_id)
333+
zero_shot_image_classification_model.predict(data)
334+
zero_shot_image_classification_model.predict(body)
335+
336+
### Invoke the model by sending bytes
337+
auth = default_signer()['signer']
338+
endpoint = zero_shot_image_classification_model.model_deployment.url + "/predict"
339+
headers = {"Content-Type": "application/octet-stream"}
340+
requests.post(endpoint, data=body, auth=auth, headers=headers).json()
341+
342+
281343
Other Frameworks
282344
----------------
283345

docs/source/user_guide/model_training/automl/quick_start.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Prerequisites
2+
=============
3+
4+
You need to check if AutoMLx library is installed in your environment. For more information on the conda environments that contain AutoMLx, check `this page <https://docs.oracle.com/en-us/iaas/data-science/using/conda-automlx-fam.htm>`__.
5+
6+
17
Quick Start
28
===========
39

@@ -6,6 +12,8 @@ The dataset is a multi-class classification dataset, and more details about the
612
can be found at `Iris dataset <https://scikit-learn.org/stable/auto_examples/datasets/plot_iris_dataset.html>`_. We demonstrate
713
the preliminary steps required to train a model with the Oracle AutoMLx tool. We then explain the tuned model.
814

15+
16+
917
Load dataset
1018
------------
1119
We start by reading in the dataset from Scikit-learn.

0 commit comments

Comments
 (0)