Compare commits

..
Author SHA1 Message Date
Andrew Ferlitsch 0f812fe2af debug: create repo 2023-07-14 23:14:19 +00:00
Andrew Ferlitsch a9daa9031d debug: install dbdtypes 2023-07-14 22:47:43 +00:00
Andrew Ferlitsch eb8506ba90 debug: internal error 2023-07-14 22:44:29 +00:00
4 changed files with 74 additions and 52 deletions
@@ -44,7 +44,7 @@
" View on GitHub\n",
" </a>\n",
" </td>\n",
" <td>\n",
" <td> <td>\n",
" <a href=\"https://console.cloud.google.com/vertex-ai/notebooks/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/community/model_garden/model_garden_keras_stable_diffusion.ipynb\">\n",
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
"Open in Vertex AI Workbench\n",
@@ -282,11 +282,8 @@
"from io import BytesIO\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from google.cloud import storage\n",
"from PIL import Image\n",
"\n",
"GCS_URI_PREFIX = \"gs://\"\n",
"\n",
"# Training constants.\n",
"TRAINING_JOB_PREFIX = \"train\"\n",
"TRAIN_CONTAINER_URI = \"us-docker.pkg.dev/vertex-ai-restricted/vertex-vision-model-garden-dockers/keras-train:latest\"\n",
@@ -320,21 +317,6 @@
" return gcs_path\n",
"\n",
"\n",
"def download_gcs_file_to_local(gcs_uri: str, local_path: str):\n",
" \"\"\"Download a gcs file to a local path.\n",
"\n",
" Args:\n",
" gcs_uri: A string of file path on GCS.\n",
" local_path: A string of local file path.\n",
" \"\"\"\n",
" if not gcs_uri.startswith(GCS_URI_PREFIX):\n",
" raise ValueError(f\"{gcs_uri} is not a GCS path starting with {GCS_URI_PREFIX}.\")\n",
" client = storage.Client()\n",
" os.makedirs(os.path.dirname(local_path), exist_ok=True)\n",
" with open(local_path, \"wb\") as f:\n",
" client.download_blob_to_file(gcs_uri, f)\n",
"\n",
"\n",
"def deploy_model(model_path, service_account):\n",
"\n",
" deploy_model_name = get_job_name_with_datetime(DEPLOY_JOB_PREFIX)\n",
@@ -438,11 +420,7 @@
"from keras_cv.models import StableDiffusion\n",
"\n",
"model = StableDiffusion(img_height=RESOLUTION, img_width=RESOLUTION, jit_compile=True)\n",
"if model_path.startswith(GCS_URI_PREFIX):\n",
" local_model_path = \"/tmp/saved_model.h5\"\n",
" download_gcs_file_to_local(model_path, local_model_path)\n",
" model.diffusion_model.load_weights(local_model_path)\n",
"elif model_path:\n",
"if model_path:\n",
" model.diffusion_model.load_weights(model_path)"
]
},
@@ -590,7 +568,7 @@
},
"source": [
"## Finetune models\n",
"This section shows how to finetune Keras Stable diffusion models with training dockers.\n",
"This section shows how to finetune Keras Stable diffusion models with trainig dockers.\n",
"\n",
"If you would like to use finetuned models, please go to the section `Run inferences`."
]
@@ -389,6 +389,7 @@
"- `model_type`: The type of model for deployment.\n",
" - `EFFICIENTNET`: A model that is available in Vertex Model Garden image classification training with customizable hyperparameters. Best tailored to be used within Google Cloud, and cannot be exported externally.\n",
" - `MAXVIT`: A model that is available in Vertex Model Garden image classification training with customizable hyperparameters. Best tailored to be used within Google Cloud, and cannot be exported externally.\n",
" - `COCA`: A model that is available in Vertex Model Garden image classification training with customizable hyperparameters. Best tailored to be used within Google Cloud, and cannot be exported externally.\n",
"- `checkpoint_name`: Optional. The field is reserved for Model Garden model training, based on the provided pre-trained model checkpoint.\n",
"- `trainer_config`: Optional. The field is usually used together with the Model Garden model training when passing the customized configs for the trainer.\n",
"\n",
@@ -456,7 +457,7 @@
"METRIC_SPEC_VALUE = \"maximize\"\n",
"SEARCH_ALGORITHM = \"random\"\n",
"MEASUREMENT_SELECTION = \"best\"\n",
"MODEL_TYPE = \"MAXVIT\" # @param {type:\"string\"} one of the values [\"MAXVIT\", \"EFFICIENTNET\"]\n",
"MODEL_TYPE = \"COCA\" # @param {type:\"string\"} one of the values [\"COCA\", \"MAXVIT\", \"EFFICIENTNET\"]\n",
"\n",
"job = aiplatform.AutoMLImageTrainingJob(\n",
" display_name=get_job_name_with_datetime(TRAINING_JOB_PREFIX),\n",
@@ -29,7 +29,7 @@
"id": "JAPoU8Sm5E6e"
},
"source": [
"# Vertex AI Pipelines: Evaluating BatchPrediction results from a Custom Tabular classification model\n",
"# Vertex AI Pipelines: Evaluating BatchPrediction results from a custom tabular classification model\n",
"\n",
"<table align=\"left\">\n",
"\n",
@@ -151,15 +151,16 @@
"outputs": [],
"source": [
"# Install the latest versions of the following packages\n",
"! pip3 install --upgrade google-cloud-aiplatform \\\n",
" google-cloud-pipeline-components==1.0.26 \\\n",
" matplotlib \\\n",
" pyarrow -q\n",
"! pip3 install --upgrade --quiet google-cloud-aiplatform \\\n",
" google-cloud-pipeline-components==1.0.26 \\\n",
" matplotlib \\\n",
" pyarrow \n",
"# Install the specified versions of the following packages\n",
"! pip3 install scikit-learn==1.0 \\\n",
" pandas \\\n",
" joblib==1.2.0 \\\n",
" numpy==1.23.3 -q"
"! pip3 install --quiet scikit-learn==1.0 \\\n",
" pandas \\\n",
" joblib==1.2.0 \\\n",
" numpy==1.23.3 \\\n",
" db-dtypes"
]
},
{
@@ -401,12 +402,25 @@
},
"outputs": [],
"source": [
"if SERVICE_ACCOUNT == \"[your-service-account]\":\n",
" shell_output = ! gcloud projects list --filter=\"PROJECT_ID:'{PROJECT_ID}'\" --format='value(PROJECT_NUMBER)'\n",
" PROJECT_NUMBER = shell_output[0]\n",
" SERVICE_ACCOUNT = f\"{PROJECT_NUMBER}-compute@developer.gserviceaccount.com\"\n",
"import sys\n",
"\n",
"print(\"Service Account:\", SERVICE_ACCOUNT)"
"IS_COLAB = \"google.colab\" in sys.modules\n",
"if (\n",
" SERVICE_ACCOUNT == \"\"\n",
" or SERVICE_ACCOUNT is None\n",
" or SERVICE_ACCOUNT == \"[your-service-account]\"\n",
"):\n",
" # Get your service account from gcloud\n",
" if not IS_COLAB:\n",
" shell_output = !gcloud auth list 2>/dev/null\n",
" SERVICE_ACCOUNT = shell_output[2].replace(\"*\", \"\").strip()\n",
"\n",
" else: # IS_COLAB:\n",
" shell_output = ! gcloud projects describe $PROJECT_ID\n",
" project_number = shell_output[-1].split(\":\")[1].strip().replace(\"'\", \"\")\n",
" SERVICE_ACCOUNT = f\"{project_number}-compute@developer.gserviceaccount.com\"\n",
"\n",
" print(\"Service Account:\", SERVICE_ACCOUNT)"
]
},
{
@@ -1035,6 +1049,34 @@
"RUN pip install -r requirements.txt"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "OrpUIkAIs_uQ"
},
"source": [
"#### Create a private Docker repository\n",
"\n",
"Your first step is to create your own Docker repository in Google Artifact Registry."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "0amu4063tDnG"
},
"outputs": [],
"source": [
"import os\n",
"\n",
"! gcloud services enable artifactregistry.googleapis.com\n",
"\n",
"if os.getenv(\"IS_TESTING\"):\n",
" ! sudo apt-get update --yes && sudo apt-get --only-upgrade --yes install google-cloud-sdk-cloud-run-proxy google-cloud-sdk-harbourbridge google-cloud-sdk-cbt google-cloud-sdk-gke-gcloud-auth-plugin google-cloud-sdk-kpt google-cloud-sdk-local-extract google-cloud-sdk-minikube google-cloud-sdk-app-engine-java google-cloud-sdk-app-engine-go google-cloud-sdk-app-engine-python google-cloud-sdk-spanner-emulator google-cloud-sdk-bigtable-emulator google-cloud-sdk-nomos google-cloud-sdk-package-go-module google-cloud-sdk-firestore-emulator kubectl google-cloud-sdk-datastore-emulator google-cloud-sdk-app-engine-python-extras google-cloud-sdk-cloud-build-local google-cloud-sdk-kubectl-oidc google-cloud-sdk-anthos-auth google-cloud-sdk-app-engine-grpc google-cloud-sdk-pubsub-emulator google-cloud-sdk-datalab google-cloud-sdk-skaffold google-cloud-sdk google-cloud-sdk-terraform-tools google-cloud-sdk-config-connector\n",
" ! gcloud components update --quiet"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -154,11 +154,10 @@
"outputs": [],
"source": [
"# Install the packages\n",
"! pip3 install --upgrade --quiet google-cloud-aiplatform \\\n",
" google-cloud-storage \\\n",
" google-cloud-bigquery \\\n",
" pyarrow \\\n",
" db-dtypes\n"
"! pip3 install --upgrade google-cloud-aiplatform \\\n",
" google-cloud-storage \\\n",
" google-cloud-bigquery \\\n",
" pyarrow -q"
]
},
{
@@ -353,7 +352,7 @@
},
"outputs": [],
"source": [
"BUCKET_URI = f\"gs://your-bucket-name-{PROJECT_ID}-unique\" # @param {type:\"string\"}"
"BUCKET_URI = \"gs://your-bucket-name-unique\" # @param {type:\"string\"}"
]
},
{
@@ -373,7 +372,7 @@
},
"outputs": [],
"source": [
"! gsutil mb -l {REGION} -p {PROJECT_ID} {BUCKET_URI}"
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI"
]
},
{
@@ -1017,7 +1016,7 @@
" display_name=JOB_NAME,\n",
" script_path=\"task.py\",\n",
" container_uri=TRAIN_IMAGE,\n",
" requirements=[\"google-cloud-bigquery>=2.20.0\", \"db-dtypes\", \"protobuf==3.20.3\"],\n",
" requirements=[\"google-cloud-bigquery>=2.20.0\", \"db-dtypes\"],\n",
" model_serving_container_image_uri=DEPLOY_IMAGE,\n",
")\n",
"\n",
@@ -1440,7 +1439,12 @@
"\n",
"To clean up all Google Cloud resources used in this project, you can [delete the Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects) you used for the tutorial.\n",
"\n",
"Otherwise, you can delete the individual resources you created in this notebook."
"Otherwise, you can delete the individual resources you created in this notebook:\n",
"\n",
"- Training Job\n",
"- Model\n",
"- Cloud Storage Bucket\n",
"- BigQuery Dataset"
]
},
{
@@ -1457,9 +1461,6 @@
"# Delete the training job\n",
"job.delete()\n",
"\n",
"# Delete the dataset\n",
"dataset.delete()\n",
"\n",
"# Delete the model\n",
"model.delete()\n",
"\n",