mirror of
https://github.com/GoogleCloudPlatform/vertex-ai-samples.git
synced 2026-09-26 14:42:04 +00:00
Update Llama 2 evaluation notebook.
PiperOrigin-RevId: 681657733
This commit is contained in:
committed by
Copybara-Service
parent
bd3283b2a6
commit
fe42990c9d
@@ -8,7 +8,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Copyright 2023 Google LLC\n",
|
||||
"# Copyright 2024 Google LLC\n",
|
||||
"#\n",
|
||||
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
|
||||
"# you may not use this file except in compliance with the License.\n",
|
||||
@@ -31,18 +31,18 @@
|
||||
"source": [
|
||||
"# Vertex AI Model Garden - LLaMA 2 (Evaluation)\n",
|
||||
"\n",
|
||||
"\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\n",
|
||||
" \u003ctd style=\"text-align: center\"\u003e\n",
|
||||
" \u003ca href=\"https://console.cloud.google.com/vertex-ai/colab/import/https:%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fcommunity%2Fmodel_garden%2Fmodel_garden_pytorch_llama2_evaluation.ipynb\"\u003e\n",
|
||||
" \u003cimg alt=\"Google Cloud Colab Enterprise logo\" src=\"https://lh3.googleusercontent.com/JmcxdQi-qOpctIvWKgPtrzZdJJK-J3sWE1RsfjZNwshCFgE_9fULcNpuXYTilIR2hjwN\" width=\"32px\"\u003e\u003cbr\u003e Run in Colab Enterprise\n",
|
||||
" \u003c/a\u003e\n",
|
||||
" \u003c/td\u003e\n",
|
||||
" \u003ctd style=\"text-align: center\"\u003e\n",
|
||||
" \u003ca href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/model_garden/model_garden_pytorch_llama2_evaluation.ipynb\"\u003e\n",
|
||||
" \u003cimg alt=\"GitHub logo\" src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" width=\"32px\"\u003e\u003cbr\u003e View on GitHub\n",
|
||||
" \u003c/a\u003e\n",
|
||||
" \u003c/td\u003e\n",
|
||||
"\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e"
|
||||
"<table><tbody><tr>\n",
|
||||
" <td style=\"text-align: center\">\n",
|
||||
" <a href=\"https://console.cloud.google.com/vertex-ai/colab/import/https:%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fcommunity%2Fmodel_garden%2Fmodel_garden_pytorch_llama2_evaluation.ipynb\">\n",
|
||||
" <img alt=\"Google Cloud Colab Enterprise logo\" src=\"https://lh3.googleusercontent.com/JmcxdQi-qOpctIvWKgPtrzZdJJK-J3sWE1RsfjZNwshCFgE_9fULcNpuXYTilIR2hjwN\" width=\"32px\"><br> Run in Colab Enterprise\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
" <td style=\"text-align: center\">\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/model_garden/model_garden_pytorch_llama2_evaluation.ipynb\">\n",
|
||||
" <img alt=\"GitHub logo\" src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" width=\"32px\"><br> View on GitHub\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
"</tr></tbody></table>"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -104,14 +104,20 @@
|
||||
"# Import the necessary packages\n",
|
||||
"! pip3 install --upgrade --quiet google-cloud-aiplatform google-cloud-pipeline-components\n",
|
||||
"\n",
|
||||
"import importlib\n",
|
||||
"import json\n",
|
||||
"import os\n",
|
||||
"import uuid\n",
|
||||
"from datetime import datetime\n",
|
||||
"from typing import Dict\n",
|
||||
"\n",
|
||||
"import pandas as pd\n",
|
||||
"from google.cloud import aiplatform, storage\n",
|
||||
"\n",
|
||||
"common_util = importlib.import_module(\n",
|
||||
" \"vertex-ai-samples.community-content.vertex_model_garden.model_oss.notebook_util.common_util\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Get the default cloud project id.\n",
|
||||
"PROJECT_ID = os.environ[\"GOOGLE_CLOUD_PROJECT\"]\n",
|
||||
"\n",
|
||||
@@ -129,7 +135,7 @@
|
||||
"BUCKET_URI = \"gs://\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"if BUCKET_URI is None or BUCKET_URI.strip() == \"\" or BUCKET_URI == \"gs://\":\n",
|
||||
" BUCKET_URI = f\"gs://{PROJECT_ID}-tmp-{now}\"\n",
|
||||
" BUCKET_URI = f\"gs://{PROJECT_ID}-tmp-{now}-{str(uuid.uuid4())[:4]}\"\n",
|
||||
" ! gsutil mb -l {REGION} {BUCKET_URI}\n",
|
||||
"else:\n",
|
||||
" assert BUCKET_URI.startswith(\"gs://\"), \"BUCKET_URI must start with `gs://`.\"\n",
|
||||
@@ -172,16 +178,14 @@
|
||||
"BULK_INFERRER_DOCKER_URI = \"us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-bulk-inferrer:20240708_1042_RC00\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def get_job_name_with_datetime(prefix: str) -\u003e str:\n",
|
||||
" \"\"\"Gets the job name with date time when triggering training or deployment\n",
|
||||
" jobs in Vertex AI.\n",
|
||||
" \"\"\"\n",
|
||||
"def get_job_name_with_datetime(prefix: str) -> str:\n",
|
||||
" \"\"\"Gets the job name with date time when triggering jobs in Vertex AI.\"\"\"\n",
|
||||
" return prefix + datetime.now().strftime(\"-%Y%m%d%H%M%S\")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def preprocess(\n",
|
||||
" output_prediction_a: Dict[str, str], output_prediction_b: Dict[str, str]\n",
|
||||
") -\u003e Dict[str, str]:\n",
|
||||
") -> Dict[str, str]:\n",
|
||||
" \"\"\"Preprocesses the output predictions of model a and model b.\n",
|
||||
"\n",
|
||||
" It takes the output predictions of bulk inference job of the model a and\n",
|
||||
@@ -236,7 +240,7 @@
|
||||
"VERTEX_AI_MODEL_GARDEN_LLAMA2 = \"\" # @param {type:\"string\"}\n",
|
||||
"assert (\n",
|
||||
" VERTEX_AI_MODEL_GARDEN_LLAMA2\n",
|
||||
"), \"Please click the agreement of LLaMA2 in Vertex AI Model Garden, and get the GCS path of LLaMA2 model artifacts.\"\n",
|
||||
"), \"Click the agreement of LLaMA2 in Vertex AI Model Garden, and get the GCS path of LLaMA2 model artifacts.\"\n",
|
||||
"print(\n",
|
||||
" \"Copy LLaMA2 model artifacts from\",\n",
|
||||
" VERTEX_AI_MODEL_GARDEN_LLAMA2,\n",
|
||||
@@ -303,6 +307,14 @@
|
||||
" accelerator_type = \"NVIDIA_L4\"\n",
|
||||
" accelerator_count = 8\n",
|
||||
"\n",
|
||||
"common_util.check_quota(\n",
|
||||
" project_id=PROJECT_ID,\n",
|
||||
" region=REGION,\n",
|
||||
" accelerator_type=accelerator_type,\n",
|
||||
" accelerator_count=accelerator_count,\n",
|
||||
" is_for_training=True,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"replica_count = 1\n",
|
||||
"\n",
|
||||
"job_name = get_job_name_with_datetime(prefix=\"llama2-eval\")\n",
|
||||
@@ -489,6 +501,14 @@
|
||||
" accelerator_type_a = \"NVIDIA_L4\"\n",
|
||||
" accelerator_count_a = 8\n",
|
||||
"\n",
|
||||
"common_util.check_quota(\n",
|
||||
" project_id=PROJECT_ID,\n",
|
||||
" region=REGION,\n",
|
||||
" accelerator_type=accelerator_type_a,\n",
|
||||
" accelerator_count=accelerator_count_a,\n",
|
||||
" is_for_training=True,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"if model_b in [\"llama2-7b-hf\", \"llama2-7b-chat-hf\"]:\n",
|
||||
" machine_type_b = \"g2-standard-16\"\n",
|
||||
" accelerator_type_b = \"NVIDIA_L4\"\n",
|
||||
@@ -502,6 +522,14 @@
|
||||
" accelerator_type_b = \"NVIDIA_L4\"\n",
|
||||
" accelerator_count_b = 8\n",
|
||||
"\n",
|
||||
"common_util.check_quota(\n",
|
||||
" project_id=PROJECT_ID,\n",
|
||||
" region=REGION,\n",
|
||||
" accelerator_type=accelerator_type_b,\n",
|
||||
" accelerator_count=accelerator_count_b,\n",
|
||||
" is_for_training=True,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"replica_count = 1\n",
|
||||
"\n",
|
||||
"bulk_infer_job_name = get_job_name_with_datetime(prefix=\"bulk-infer\")\n",
|
||||
@@ -777,7 +805,6 @@
|
||||
"metadata": {
|
||||
"colab": {
|
||||
"name": "model_garden_pytorch_llama2_evaluation.ipynb",
|
||||
"provenance": [],
|
||||
"toc_visible": true
|
||||
},
|
||||
"kernelspec": {
|
||||
|
||||
Reference in New Issue
Block a user