Compare commits

...
@@ -180,6 +180,7 @@
" ! pip3 install -U tensorflow-transform==1.2 $USER_FLAG\n",
" ! pip3 install -U tensorflow-io==0.18 $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-aiplatform[tensorboard] $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-pipeline-components $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-bigquery $USER_FLAG\n",
" ! pip3 install --upgrade google-cloud-logging $USER_FLAG\n",
" ! pip3 install --upgrade apache-beam[gcp] $USER_FLAG\n",
@@ -282,7 +283,7 @@
"\n",
"You may not use a multi-regional bucket for training with Vertex AI. Not all regions provide support for all Vertex AI services.\n",
"\n",
"Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations)"
"Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations)."
]
},
{
@@ -567,9 +568,9 @@
"\n",
"Otherwise specify `(None, None)` to use a container image to run on a CPU.\n",
"\n",
"Learn more [here](https://cloud.google.com/vertex-ai/docs/general/locations#accelerators) hardware accelerator support for your region\n",
"Learn more about [hardware accelerator support for your region](https://cloud.google.com/vertex-ai/docs/general/locations#accelerators).\n",
"\n",
"*Note*: TF releases before 2.3 for GPU support will fail to load the custom model in this tutorial. It is a known issue and fixed in TF 2.3 -- which is caused by static graph ops that are generated in the serving function. If you encounter this issue on your own custom models, use a container image for TF 2.3 with GPU support."
"*Note*: TF releases before 2.3 for GPU support will fail to load the custom model in this tutorial. It is a known issue and fixed in TF 2.3. This is caused by static graph ops that are generated in the serving function. If you encounter this issue on your own custom models, use a container image for TF 2.3 with GPU support."
]
},
{
@@ -950,7 +951,7 @@
"id": "create_input_layer:tabular"
},
"source": [
"### Create the input layer for custom model\n",
"### Create the input layer for your custom model\n",
"\n",
"Next, you create the input layer for your custom tabular model, based on the data types of each feature."
]
@@ -1100,7 +1101,7 @@
"id": "visualize_model"
},
"source": [
"#### Visualize the model archirecture\n",
"#### Visualize the model architecture\n",
"\n",
"Next, visualize the architecture of the custom model."
]
@@ -1143,10 +1144,10 @@
{
"cell_type": "markdown",
"metadata": {
"id": "upload_model:vertex"
"id": "upload_model:vertex,base_model"
},
"source": [
"### Upload the local model to a Model resource\n",
"### Upload the local model to a Vertex AI Model resource\n",
"\n",
"Next, you upload your local custom model artifacts to Vertex AI to convert into a managed Vertex AI Model resource."
]
@@ -1155,7 +1156,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "upload_model:vertex"
"id": "upload_model:vertex,base_model"
},
"outputs": [],
"source": [
@@ -1163,6 +1164,7 @@
" display_name=\"chicago_\" + TIMESTAMP,\n",
" artifact_uri=MODEL_DIR,\n",
" serving_container_image_uri=DEPLOY_IMAGE,\n",
" labels={\"base_model\": 1},\n",
" sync=True,\n",
")"
]
@@ -1774,17 +1776,14 @@
" if args.experiment:\n",
" aip.log_params(trainparams)\n",
" train.train(model, trainparams, train_data_file_pattern, val_data_file_pattern, label_column, transform_feature_spec, args.tensorboard_log_dir, args.tuning)\n",
" logging.info(\"ANDY training is complete\")\n",
" return model\n",
"\n",
"def evaluate_model(model):\n",
" ''' Evaluate the model '''\n",
" logging.info(\"evaluate the model\")\n",
" evalparams = {}\n",
" evalparams[\"batch_size\"] = args.batch_size\n",
" metrics = train.evaluate(model, evalparams, test_data_file_pattern, label_column, transform_feature_spec)\n",
" logging.info('ANDY: write metrics file ' + args.model_dir + \"/metrics.txt\")\n",
" with tf.io.gfile.GFile(args.model_dir + \"metrics.txt\", \"w\") as f:\n",
" with tf.io.gfile.GFile(os.path.join(args.model_dir, \"metrics.txt\", \"w\")) as f:\n",
" f.write(str(metrics))\n",
"\n",
"get_data()\n",
@@ -1792,8 +1791,6 @@
" model = get_model()\n",
"model = train_model(model)\n",
"\n",
"logging.info('ANDY: args.evaluate')\n",
"logging.info(args.evaluate)\n",
"if args.evaluate:\n",
" evaluate_model(model)\n",
"\n",
@@ -1801,17 +1798,6 @@
"model.save(args.model_dir)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "98baaa73fb9c"
},
"outputs": [],
"source": [
"!gsutil ls gs://andy-1234-221921aip-20211123191641/trained/model/"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -1963,7 +1949,7 @@
"CMDARGS = [\n",
" \"--epochs=5\",\n",
" \"--batch_size=16\",\n",
" \"--distribute=single\",\n",
" \"--distribute=mirrored\",\n",
" \"--experiment=chicago\",\n",
" \"--run=test\",\n",
" \"--project=\" + PROJECT_ID,\n",
@@ -2006,6 +1992,28 @@
"job.delete()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "model_delete:mbsdk"
},
"source": [
"#### Delete the model\n",
"\n",
"The method 'delete()' will delete the model."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "model_delete:mbsdk"
},
"outputs": [],
"source": [
"model.delete()"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -2301,8 +2309,8 @@
},
"outputs": [],
"source": [
"LR = 0.01 # best[2]\n",
"BATCH_SIZE = 32 # int(best[1])"
"LR = best[2]\n",
"BATCH_SIZE = int(best[1])"
]
},
{
@@ -2372,13 +2380,13 @@
"outputs": [],
"source": [
"MODEL_DIR = BUCKET_NAME + \"/trained\"\n",
"FULL_EPOCHS = 10\n",
"FULL_EPOCHS = 100\n",
"\n",
"CMDARGS = [\n",
" f\"--epochs={FULL_EPOCHS}\",\n",
" f\"--lr={LR}\",\n",
" f\"--batch_size={BATCH_SIZE}\",\n",
" \"--distribute=single\",\n",
" \"--distribute=mirrored\",\n",
" \"--experiment=chicago\",\n",
" \"--run=full\",\n",
" \"--project=\" + PROJECT_ID,\n",
@@ -2469,17 +2477,6 @@
"! gsutil cat $METRICS"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "02f35c40eff6"
},
"outputs": [],
"source": [
"!gsutil ls -l {MODEL_DIR}"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -2700,7 +2697,7 @@
"id": "upload_serving_model:vertex,labels"
},
"source": [
"### Upload the serving model to a Model resource\n",
"### Upload the serving model to a Vertex AI Model resource\n",
"\n",
"Next, you upload your serving custom model artifacts to Vertex AI to convert into a managed Vertex AI Model resource."
]
@@ -2717,7 +2714,7 @@
" display_name=\"chicago_\" + TIMESTAMP,\n",
" artifact_uri=SERVING_MODEL_DIR,\n",
" serving_container_image_uri=DEPLOY_IMAGE,\n",
" labels={\"metadata\": BUCKET_NAME[5:]},\n",
" labels={\"user_metadata\": BUCKET_NAME[5:]},\n",
" sync=True,\n",
")"
]
@@ -2960,17 +2957,6 @@
" if \"BUCKET_NAME\" in globals():\n",
" ! gsutil rm -r $BUCKET_NAME"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "2899195b3e37"
},
"outputs": [],
"source": [
"! gsutil rm -r $BUCKET_NAME"
]
}
],
"metadata": {