Skip to content

Commit 69a67f2

Browse files
yeesiancopybara-github
authored andcommitted
docs: add documentation for the preview namespace
* Sync the contents of the two README files in aiplatform * add information on importing SDK, SDK preview, and client library namespaces PiperOrigin-RevId: 570092703
1 parent f978200 commit 69a67f2

File tree

2 files changed

+143
-32
lines changed

2 files changed

+143
-32
lines changed

README.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,23 @@ If none of the above scenarios could help you find the right tools for your task
107107

108108
Importing
109109
^^^^^^^^^
110-
SDK functionality can be used from the root of the package:
110+
Vertex AI SDK functionality can be used by importing the following namespace:
111111

112112
.. code-block:: Python
113113
114114
from google.cloud import aiplatform
115115
116+
Vertex AI SDK preview functionality can be used by importing the following namespace:
117+
118+
.. code-block:: Python
119+
120+
from vertexai import preview
121+
122+
Vertex AI client library functionality can be used by importing the following namespace:
123+
124+
.. code-block:: Python
125+
126+
import vertexai
116127
117128
Initialization
118129
^^^^^^^^^^^^^^

docs/README.rst

Lines changed: 131 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Vertex AI SDK for Python
1515
.. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-aiplatform.svg
1616
:target: https://pypi.org/project/google-cloud-aiplatform/
1717
.. _Vertex AI: https://cloud.google.com/vertex-ai/docs
18-
.. _Client Library Documentation: https://googleapis.dev/python/aiplatform/latest
18+
.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/aiplatform/latest
1919
.. _Product Documentation: https://cloud.google.com/vertex-ai/docs
2020

2121

@@ -26,12 +26,12 @@ In order to use this library, you first need to go through the following steps:
2626

2727
1. `Select or create a Cloud Platform project.`_
2828
2. `Enable billing for your project.`_
29-
3. `Enable the Cloud AI Platform API.`_
29+
3. `Enable the Vertex AI API.`_
3030
4. `Setup Authentication.`_
3131

3232
.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project
3333
.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project
34-
.. _Enable the Cloud AI Platform API.: https://cloud.google.com/ai-platform/docs
34+
.. _Enable the Vertex AI API.: https://cloud.google.com/vertex-ai/docs/start/use-vertex-ai-python-sdk
3535
.. _Setup Authentication.: https://googleapis.dev/python/google-api-core/latest/auth.html
3636

3737
Installation
@@ -45,7 +45,7 @@ With `virtualenv`_, it's possible to install this library without needing system
4545
install permissions, and without clashing with the installed system
4646
dependencies.
4747

48-
.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/
48+
.. _virtualenv: https://virtualenv.pypa.io/en/latest/
4949

5050

5151
Mac/Linux
@@ -59,6 +59,7 @@ Mac/Linux
5959
<your-env>/bin/pip install google-cloud-aiplatform
6060
6161
62+
6263
Windows
6364
^^^^^^^
6465

@@ -69,20 +70,53 @@ Windows
6970
<your-env>\Scripts\activate
7071
<your-env>\Scripts\pip.exe install google-cloud-aiplatform
7172
73+
Supported Python Versions
74+
^^^^^^^^^^^^^^^^^^^^^^^^^
75+
Python >= 3.7
76+
77+
Deprecated Python Versions
78+
^^^^^^^^^^^^^^^^^^^^^^^^^^
79+
Python == 3.6.
80+
81+
The last version of this library compatible with Python 3.6 is google-cloud-aiplatform==1.12.1.
82+
7283
Overview
7384
~~~~~~~~
7485
This section provides a brief overview of the Vertex AI SDK for Python. You can also reference the notebooks in `vertex-ai-samples`_ for examples.
7586

76-
.. _vertex-ai-samples: https://github.com/GoogleCloudPlatform/ai-platform-samples/tree/master/ai-platform-unified/notebooks/unofficial/sdk
87+
.. _vertex-ai-samples: https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/community/sdk
88+
89+
All publicly available SDK features can be found in the :code:`google/cloud/aiplatform` directory.
90+
Under the hood, Vertex SDK builds on top of GAPIC, which stands for Google API CodeGen.
91+
The GAPIC library code sits in :code:`google/cloud/aiplatform_v1` and :code:`google/cloud/aiplatform_v1beta1`,
92+
and it is auto-generated from Google's service proto files.
93+
94+
For most developers' programmatic needs, they can follow these steps to figure out which libraries to import:
95+
96+
1. Look through :code:`google/cloud/aiplatform` first -- Vertex SDK's APIs will almost always be easier to use and more concise comparing with GAPIC
97+
2. If the feature that you are looking for cannot be found there, look through :code:`aiplatform_v1` to see if it's available in GAPIC
98+
3. If it is still in beta phase, it will be available in :code:`aiplatform_v1beta1`
99+
100+
If none of the above scenarios could help you find the right tools for your task, please feel free to open a github issue and send us a feature request.
77101

78102
Importing
79103
^^^^^^^^^
80-
SDK functionality can be used from the root of the package:
104+
Vertex AI SDK functionality can be used by importing the following namespace:
81105

82106
.. code-block:: Python
83107
84108
from google.cloud import aiplatform
85109
110+
Vertex AI SDK preview functionality can be used by importing the following namespace:
111+
112+
.. code-block:: Python
113+
114+
from vertexai import preview
115+
116+
Vertex AI client library functionality can be used by importing the following namespace:
117+
118+
.. code-block:: Python
119+
86120
87121
Initialization
88122
^^^^^^^^^^^^^^
@@ -104,7 +138,7 @@ Initialize the SDK to store common configurations that you use with the SDK.
104138
staging_bucket='gs://my_staging_bucket',
105139
106140
# custom google.auth.credentials.Credentials
107-
# environment default creds used if not set
141+
# environment default credentials used if not set
108142
credentials=my_credentials,
109143
110144
# customer managed encryption key resource name
@@ -116,7 +150,7 @@ Initialize the SDK to store common configurations that you use with the SDK.
116150
experiment='my-experiment',
117151
118152
# description of the experiment above
119-
experiment_description='my experiment decsription'
153+
experiment_description='my experiment description'
120154
)
121155
122156
Datasets
@@ -181,7 +215,7 @@ Please visit `Using a managed dataset in a custom training application`_ for a d
181215

182216
.. _Using a managed dataset in a custom training application: https://cloud.google.com/vertex-ai/docs/training/using-managed-datasets
183217

184-
It must write the model artifact to the environment variable populated by the traing service:
218+
It must write the model artifact to the environment variable populated by the training service:
185219

186220
.. code-block:: Python
187221
@@ -194,9 +228,10 @@ It must write the model artifact to the environment variable populated by the tr
194228
job = aiplatform.CustomTrainingJob(
195229
display_name="my-training-job",
196230
script_path="training_script.py",
197-
container_uri="gcr.io/cloud-aiplatform/training/tf-cpu.2-2:latest",
231+
container_uri="us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-2:latest",
198232
requirements=["gcsfs==0.7.1"],
199-
model_serving_container_image_uri="gcr.io/cloud-aiplatform/prediction/tf2-cpu.2-2:latest",
233+
model_serving_container_image_uri="us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-2:latest",
234+
200235
)
201236
202237
model = job.run(my_dataset,
@@ -238,6 +273,26 @@ To train an AutoML tabular model:
238273
239274
Models
240275
------
276+
To get a model:
277+
278+
279+
.. code-block:: Python
280+
281+
model = aiplatform.Model('/projects/my-project/locations/us-central1/models/{MODEL_ID}')
282+
283+
284+
285+
To upload a model:
286+
287+
.. code-block:: Python
288+
289+
model = aiplatform.Model.upload(
290+
display_name='my-model',
291+
artifact_uri="gs://python/to/my/model/dir",
292+
serving_container_image_uri="us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-2:latest",
293+
)
294+
295+
241296
242297
To deploy a model:
243298

@@ -252,25 +307,51 @@ To deploy a model:
252307
accelerator_count=1)
253308
254309
255-
To upload a model:
310+
Please visit `Importing models to Vertex AI`_ for a detailed overview:
311+
312+
.. _Importing models to Vertex AI: https://cloud.google.com/vertex-ai/docs/general/import-model
313+
314+
315+
Model Evaluation
316+
----------------
317+
318+
The Vertex AI SDK for Python currently supports getting model evaluation metrics for all AutoML models.
319+
320+
To list all model evaluations for a model:
256321

257322
.. code-block:: Python
258323
259-
model = aiplatform.Model.upload(
260-
display_name='my-model',
261-
artifact_uri="gs://python/to/my/model/dir",
262-
serving_container_image_uri="gcr.io/cloud-aiplatform/prediction/tf2-cpu.2-2:latest",
263-
)
324+
model = aiplatform.Model('projects/my-project/locations/us-central1/models/{MODEL_ID}')
325+
326+
evaluations = model.list_model_evaluations()
264327
265-
To get a model:
328+
329+
To get the model evaluation resource for a given model:
266330

267331
.. code-block:: Python
268332
269-
model = aiplatform.Model('/projects/my-project/locations/us-central1/models/{MODEL_ID}')
333+
model = aiplatform.Model('projects/my-project/locations/us-central1/models/{MODEL_ID}')
270334
271-
Please visit `Importing models to Vertex AI`_ for a detailed overview:
335+
# returns the first evaluation with no arguments, you can also pass the evaluation ID
336+
evaluation = model.get_model_evaluation()
337+
338+
eval_metrics = evaluation.metrics
272339
273-
.. _Importing models to Vertex AI: https://cloud.google.com/vertex-ai/docs/general/import-model
340+
341+
You can also create a reference to your model evaluation directly by passing in the resource name of the model evaluation:
342+
343+
.. code-block:: Python
344+
345+
evaluation = aiplatform.ModelEvaluation(
346+
evaluation_name='projects/my-project/locations/us-central1/models/{MODEL_ID}/evaluations/{EVALUATION_ID}')
347+
348+
Alternatively, you can create a reference to your evaluation by passing in the model and evaluation IDs:
349+
350+
.. code-block:: Python
351+
352+
evaluation = aiplatform.ModelEvaluation(
353+
evaluation_name={EVALUATION_ID},
354+
model_id={MODEL_ID})
274355
275356
276357
Batch Prediction
@@ -310,18 +391,11 @@ You can also create a batch prediction job asynchronously by including the `sync
310391
Endpoints
311392
---------
312393

313-
To get predictions from endpoints:
314-
315-
.. code-block:: Python
316-
317-
endpoint.predict(instances=[[6.7, 3.1, 4.7, 1.5], [4.6, 3.1, 1.5, 0.2]])
318-
319-
320-
To create an endpoint
394+
To create an endpoint:
321395

322396
.. code-block:: Python
323397
324-
endpoint = endpoint.create(display_name='my-endpoint')
398+
endpoint = aiplatform.Endpoint.create(display_name='my-endpoint')
325399
326400
To deploy a model to a created endpoint:
327401

@@ -331,11 +405,18 @@ To deploy a model to a created endpoint:
331405
332406
endpoint.deploy(model,
333407
min_replica_count=1,
334-
max_replica_count=5
408+
max_replica_count=5,
335409
machine_type='n1-standard-4',
336410
accelerator_type='NVIDIA_TESLA_K80',
337411
accelerator_count=1)
338412
413+
To get predictions from endpoints:
414+
415+
.. code-block:: Python
416+
417+
endpoint.predict(instances=[[6.7, 3.1, 4.7, 1.5], [4.6, 3.1, 1.5, 0.2]])
418+
419+
339420
To undeploy models from an endpoint:
340421

341422
.. code-block:: Python
@@ -458,6 +539,25 @@ To use Explanation Metadata in endpoint deployment and model upload:
458539
aiplatform.Model.upload(..., explanation_metadata=explanation_metadata)
459540
460541
542+
543+
Cloud Profiler
544+
----------------------------
545+
546+
Cloud Profiler allows you to profile your remote Vertex AI Training jobs on demand and visualize the results in Vertex AI Tensorboard.
547+
548+
To start using the profiler with TensorFlow, update your training script to include the following:
549+
550+
.. code-block:: Python
551+
552+
from google.cloud.aiplatform.training_utils import cloud_profiler
553+
...
554+
cloud_profiler.init()
555+
556+
Next, run the job with with a Vertex AI TensorBoard instance. For full details on how to do this, visit https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-overview
557+
558+
Finally, visit your TensorBoard in your Google Cloud Console, navigate to the "Profile" tab, and click the `Capture Profile` button. This will allow users to capture profiling statistics for the running jobs.
559+
560+
461561
Next Steps
462562
~~~~~~~~~~
463563

0 commit comments

Comments
 (0)