Compare commits

...
Author SHA1 Message Date
Andrew Ferlitsch 2f22d50f6e update: use GetVertexModelOp 2022-08-26 17:40:09 +00:00
Andrew Ferlitsch e7ea5ea5b2 update: use GetVertexModelOp 2022-08-26 17:28:31 +00:00
@@ -340,7 +340,7 @@
"source": [
"### Authenticate your Google Cloud account\n",
"\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. Skip this step.\n",
"**If you are using Vertex AI Workbench Notebooks**, your environment is already authenticated. \n",
"\n",
"**If you are using Colab**, run the cell below and follow the instructions when prompted to authenticate your account via oAuth.\n",
"\n",
@@ -376,12 +376,11 @@
"import sys\n",
"\n",
"# If on Vertex AI Workbench, then don't execute this code\n",
"IS_COLAB = False\n",
"IS_COLAB = \"google.colab\" in sys.modules\n",
"if not os.path.exists(\"/opt/deeplearning/metadata/env_version\") and not os.getenv(\n",
" \"DL_ANACONDA_HOME\"\n",
"):\n",
" if \"google.colab\" in sys.modules:\n",
" IS_COLAB = True\n",
" from google.colab import auth as google_auth\n",
"\n",
" google_auth.authenticate_user()\n",
@@ -428,8 +427,9 @@
},
"outputs": [],
"source": [
"if BUCKET_URI == \"\" or BUCKET_URI is None or BUCKET_URI == \"gs://[your-bucket-name]\":\n",
" BUCKET_URI = \"gs://\" + PROJECT_ID + \"aip-\" + TIMESTAMP"
"if BUCKET_NAME == \"\" or BUCKET_NAME is None or BUCKET_NAME == \"[your-bucket-name]\":\n",
" BUCKET_NAME = PROJECT_ID + \"aip-\" + TIMESTAMP\n",
" BUCKET_URI = f\"gs://{BUCKET_NAME}\""
]
},
{
@@ -785,7 +785,7 @@
},
"outputs": [],
"source": [
"endpoint.gca_resource"
"print(endpoint.gca_resource)"
]
},
{
@@ -908,7 +908,7 @@
},
"outputs": [],
"source": [
"endpoint.gca_resource.deployed_models[0]"
"print(endpoint.gca_resource.deployed_models[0])"
]
},
{
@@ -1203,12 +1203,10 @@
"\n",
"In this pipeline, you create an `Endpoint` resource, and then you deploy a `Model` resource to the `Endpoint` resource. The `Model` resource to deploy is your existing TFHub model which you previously imported as a `Model` resource. The steps are:\n",
"\n",
"- For pipeline parameters, pass the resource name and resource URI for the existing `Model` resource.\n",
"- Use the `importer_node()` component to create a `VertexModel` pipeline artifact for the model.\n",
"- For pipeline parameters, pass the resource name for the existing `Model` resource.\n",
"- Use the `GetVertexModelOp()` component to create a `VertexModel` pipeline artifact for the model.\n",
"- Create an `Endpoint` resource.\n",
"- Using the `VertexModel` pipeline artifact, deploy the `Model` resource to the `Endpoint` resource.\n",
"\n",
"*Note:* This example currently blocked by internal issue: b/219835305"
"- Using the `VertexModel` pipeline artifact, deploy the `Model` resource to the `Endpoint` resource."
]
},
{
@@ -1225,20 +1223,6 @@
"\n",
"PIPELINE_ROOT = \"{}/pipeline_root/endpoint_example\".format(BUCKET_URI)\n",
"\n",
"# (WORKAROUND b/219835305)\n",
"@component(\n",
" base_image=\"python:3.9\",\n",
" packages_to_install=[\"google-cloud-aiplatform\"],\n",
")\n",
"def return_unmanaged_model(\n",
" serving_image: str, artifact_uri: str, resource_name: str, model: Output[Artifact]\n",
"):\n",
" model.metadata[\"containerSpec\"] = {\"imageUri\": serving_image}\n",
"\n",
" model.metadata[\"resourceName\"] = resource_name\n",
"\n",
" model.uri = artifact_uri\n",
"\n",
"\n",
"@dsl.pipeline(\n",
" name=\"create-endpoint-deploy-model\",\n",
@@ -1246,34 +1230,16 @@
")\n",
"def pipeline(\n",
" display_name: str,\n",
" resource_uri: str,\n",
" resource_name: str,\n",
" # Model properties (WORKAROUND b/219835305)\n",
" serving_image: str,\n",
" artifact_uri: str,\n",
" project: str = PROJECT_ID,\n",
" region: str = REGION,\n",
"):\n",
" from google_cloud_pipeline_components.types import artifact_types\n",
" from google_cloud_pipeline_components.experimental.evaluation import \\\n",
" GetVertexModelOp\n",
" from google_cloud_pipeline_components.v1.endpoint import (EndpointCreateOp,\n",
" ModelDeployOp)\n",
" from kfp.v2.components import importer_node\n",
"\n",
" # Desired sequence: blocked by b/219835305\n",
" \"\"\"\n",
" model = importer_node.importer(\n",
" artifact_uri=resource_uri,\n",
" artifact_class=artifact_types.VertexModel,\n",
" metadata={\"resourceName\": resource_name},\n",
" )\n",
" \"\"\"\n",
"\n",
" # (WORKAROUND b/219835305)\n",
" model = return_unmanaged_model(\n",
" serving_image=serving_image,\n",
" artifact_uri=artifact_uri,\n",
" resource_name=resource_name,\n",
" )\n",
" model = GetVertexModelOp(model_resource_name=resource_name)\n",
"\n",
" endpoint_op = EndpointCreateOp(\n",
" project=project,\n",
@@ -1281,7 +1247,7 @@
" display_name=display_name,\n",
" )\n",
"\n",
" deploy_op = ModelDeployOp(\n",
" _ = ModelDeployOp(\n",
" model=model.outputs[\"model\"],\n",
" endpoint=endpoint_op.outputs[\"endpoint\"],\n",
" dedicated_resources_min_replica_count=1,\n",
@@ -1310,7 +1276,6 @@
"\n",
"- `display_name`: The display name for the generated Vertex AI resources.\n",
"- `resource_name`: The resource name of the existing `Model` resource.\n",
"- `resource_uri`: The resource uri of the existing `Model` resource.\n",
"- `project`: The project ID.\n",
"- `region`: The region."
]
@@ -1323,10 +1288,6 @@
},
"outputs": [],
"source": [
"# Model properties (WORKAROUND b/219835305)\n",
"SERVING_CONTAINER_URI = model.gca_resource.container_spec.image_uri\n",
"ARTIFACT_URI = model.gca_resource.artifact_uri\n",
"\n",
"try:\n",
" pipeline = aip.PipelineJob(\n",
" display_name=\"create-endpoint-deploy-pipeline\",\n",
@@ -1335,11 +1296,6 @@
" parameter_values={\n",
" \"display_name\": \"create_endpoint_and_deploy_model_\" + TIMESTAMP,\n",
" \"resource_name\": model.resource_name,\n",
" \"resource_uri\": \"https://us-central1-aiplatform.googleapis.com/v1/\"\n",
" + model.resource_name,\n",
" # Model properties (WORKAROUND b/219835305)\n",
" \"serving_image\": SERVING_CONTAINER_URI,\n",
" \"artifact_uri\": ARTIFACT_URI,\n",
" \"project\": PROJECT_ID,\n",
" \"region\": REGION,\n",
" },\n",
@@ -1488,7 +1444,7 @@
"\n",
"- For pipeline parameters, pass the resource names and resource URIs for the existing `Model` and `Endpoint` resource.\n",
"- Use the `importer_node()` component to create a `VertexModel` pipeline artifact for the model.\n",
"- Use the `importer_node()` component to create a `VertexEndpoint` pipeline artifact for the endpoint.\n",
"- Use the `GetVertexModelOp()` component to create a `VertexModel` pipeline artifact for the model.\n",
"- Using the `VertexModel` and `VertexEndpoint` pipeline artifacts, deploy the `Model` resource to the `Endpoint` resource.\n",
"\n",
"*Note:* This example currently blocked by internal issue: b/219835305"
@@ -1504,6 +1460,7 @@
"source": [
"PIPELINE_ROOT = \"{}/pipeline_root/endpoint_example_2\".format(BUCKET_URI)\n",
"\n",
"\n",
"# (WORKAROUND b/219835305)\n",
"@component(\n",
" base_image=\"python:3.9\",\n",
@@ -1520,35 +1477,23 @@
")\n",
"def pipeline(\n",
" display_name: str,\n",
" model_resource_uri: str,\n",
" model_resource_name: str,\n",
" endpoint_resource_uri: str,\n",
" endpoint_resource_name: str,\n",
" # Model properties (WORKAROUND b/219835305)\n",
" serving_image: str,\n",
" artifact_uri: str,\n",
" project: str = PROJECT_ID,\n",
" region: str = REGION,\n",
"):\n",
" from google_cloud_pipeline_components.types import artifact_types\n",
" from google_cloud_pipeline_components.experimental.evaluation import \\\n",
" GetVertexModelOp\n",
" from google_cloud_pipeline_components.v1.endpoint import ModelDeployOp\n",
" from kfp.v2.components import importer_node\n",
"\n",
" # Desired sequence: blocked by b/219835305\n",
" \"\"\"\n",
" model = importer_node.importer(\n",
" artifact_uri=resource_uri,\n",
" artifact_class=artifact_types.VertexModel,\n",
" metadata={\"resourceName\": resource_name},\n",
" )\n",
" from kfp.v2.components import importer_node\n",
" from google_cloud_pipeline_components.types import artifact_types\n",
" \"\"\"\n",
"\n",
" # (WORKAROUND b/219835305)\n",
" model = return_unmanaged_model(\n",
" serving_image=serving_image,\n",
" artifact_uri=artifact_uri,\n",
" resource_name=model_resource_name,\n",
" )\n",
" model = GetVertexModelOp(model_resource_name=model_resource_name)\n",
"\n",
" # Desired sequence: blocked by b/219835305\n",
" \"\"\"\n",
@@ -1562,7 +1507,7 @@
" # (WORKAROUND b/219835305)\n",
" endpoint = return_unmanaged_endpoint(resource_name=endpoint_resource_name)\n",
"\n",
" deploy_op = ModelDeployOp(\n",
" _ = ModelDeployOp(\n",
" model=model.outputs[\"model\"],\n",
" endpoint=endpoint.outputs[\"endpoint\"],\n",
" dedicated_resources_min_replica_count=1,\n",
@@ -1591,7 +1536,6 @@
"\n",
"- `display_name`: The display name for the generated Vertex AI resources.\n",
"- `model_resource_name`: The resource name of the existing `Model` resource.\n",
"- `model_resource_uri`: The resource uri of the existing `Model` resource.\n",
"- `endpoint_resource_name`: The resource name of the existing `Endpoint` resource.\n",
"- `endpoint_resource_uri`: The resource uri of the existing `Endpoint` resource.\n",
"- `project`: The project ID.\n",
@@ -1614,14 +1558,9 @@
" parameter_values={\n",
" \"display_name\": \"deploy_model_existing_endpoint_\" + TIMESTAMP,\n",
" \"model_resource_name\": model.resource_name,\n",
" \"model_resource_uri\": \"https://us-central1-aiplatform.googleapis.com/v1/\"\n",
" + model.resource_name,\n",
" \"endpoint_resource_name\": endpoint.resource_name,\n",
" \"endpoint_resource_uri\": \"https://us-central1-aiplatform.googleapis.com/v1/\"\n",
" + endpoint.resource_name,\n",
" # Model properties (WORKAROUND b/219835305)\n",
" \"serving_image\": SERVING_CONTAINER_URI,\n",
" \"artifact_uri\": ARTIFACT_URI,\n",
" \"project\": PROJECT_ID,\n",
" \"region\": REGION,\n",
" },\n",