Update Llama2 PEFT finetuning notebook to low-code version and minor fixes to HPT notebook (#2825)

This commit is contained in:
KCFindstr
2024-03-29 23:28:32 +00:00
committed by GitHub
parent 22435976d9
commit 6110aa2b13
2 changed files with 395 additions and 638 deletions
File diff suppressed because it is too large Load Diff
@@ -149,9 +149,19 @@
"BUCKET_NAME = \"/\".join(BUCKET_URI.split(\"/\")[:3])\n",
"! gsutil iam ch serviceAccount:{SERVICE_ACCOUNT}:roles/storage.admin $BUCKET_NAME\n",
"\n",
"! gcloud config set project $PROJECT_ID\n",
"\n",
"# @markdown #### Access LLaMA2 models on Vertex AI for GPU based serving\n",
"! gcloud config set project $PROJECT_ID"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "esW92m2vEdOd"
},
"outputs": [],
"source": [
"# @title Access LLaMA2 models on Vertex AI for GPU based serving\n",
"# @markdown The original models from Meta are converted into the Hugging Face format for serving in Vertex AI.\n",
"# @markdown Accept the model agreement to access the models:\n",
"# @markdown 1. Open the [LLaMA2 model card](https://console.cloud.google.com/vertex-ai/publishers/google/model-garden/139) from [Vertex AI Model Garden](https://cloud.google.com/model-garden).\n",
@@ -340,7 +350,7 @@
"source": [
"# @title Run hyperparameter tuning\n",
"\n",
"# @markdown This section demonstrates the way to hyperparameter tune the LLaMA 2 models with PEFT LoRA.\n",
"# @markdown This section demonstrates how to hyperparameter tune the LLaMA 2 models with PEFT LoRA.\n",
"\n",
"# @markdown You can use the Vertex AI SDK to create and run the [hyperparameter tuning job](https://cloud.google.com/vertex-ai/docs/training/hyperparameter-tuning-overview) to obtain a better performance by experimenting with different hyperparameters.\n",
"# @markdown You can customize the search space by extending the range of learning rates, adding other parameters such as LoRA rank, etc. Please refer to the [hyperparameter tuning documentation](https://cloud.google.com/vertex-ai/docs/training/hyperparameter-tuning-overview) for more information.\n",
@@ -403,6 +413,7 @@
"\n",
"# Runs 200 training steps.\n",
"max_steps = 200 # @param {type: \"integer\"}\n",
"per_device_train_batch_size = 4\n",
"# Evaluates the model on 1000 examples.\n",
"eval_limit = 1000\n",
"# LoRA parameters.\n",
@@ -418,10 +429,13 @@
" \"output_dir\": output_dir,\n",
" \"warmup_steps\": 10,\n",
" \"max_steps\": max_steps,\n",
" \"per_device_train_batch_size\": per_device_train_batch_size,\n",
" \"lora_rank\": lora_rank,\n",
" \"lora_alpha\": lora_alpha,\n",
" \"lora_dropout\": lora_dropout,\n",
" \"dataset_name\": dataset_name,\n",
" \"instruct_column_in_dataset\": instruct_column_in_dataset,\n",
" \"template\": template,\n",
" \"eval_steps\": max_steps + 1, # Only evaluates in the end.\n",
" \"eval_tasks\": eval_task,\n",
" \"eval_metric_name\": eval_metric_name,\n",
@@ -530,18 +544,20 @@
"outputs": [],
"source": [
"# @title Deploy\n",
"# @markdown This section uploads the model to Model Registry and deploys it on the Endpoint with NVIDIA L4 GPUs. It takes 15 minutes to 1 hour to finish.\n",
"# @markdown This section uploads the model to Model Registry and deploys it on the Endpoint. It takes 15 minutes to 1 hour to finish.\n",
"# @markdown Please click \"Show code\" to see more details.\n",
"\n",
"print(\"Deploying models in: \", merged_model_output_dir)\n",
"\n",
"# Note that a larger max_model_len will require more GPU memory.\n",
"# The max_model_len must not exceed the model's context length.\n",
"# A larger max_model_len will require more GPU memory.\n",
"max_model_len = 2048\n",
"# Worker pool spec.\n",
"# Find Vertex AI supported accelerators and regions in:\n",
"# https://cloud.google.com/vertex-ai/docs/training/configure-compute\n",
"machine_type = None\n",
"accelerator_type = \"NVIDIA_L4\"\n",
"accelerator_type = \"NVIDIA_L4\" # @param[\"NVIDIA_L4\", \"NVIDIA_TESLA_V100\", \"NVIDIA_TESLA_A100\"]\n",
"\n",
"if \"7b\" in model_id:\n",
" if accelerator_type == \"NVIDIA_TESLA_A100\":\n",
" machine_type = \"a2-highgpu-1g\"\n",
@@ -656,18 +672,21 @@
"source": [
"# @title Clean up resources\n",
"\n",
"# @markdown Delete the experiment models and endpoints to recycle the resources\n",
"# @markdown and avoid unnecessary continuous charges that may incur.\n",
"\n",
"if train_job._gca_resource.name:\n",
" # Training job is submitted.\n",
" train_job.delete()\n",
"train_hpt_job.delete()\n",
"\n",
"# Undeploy models and delete endpoints.\n",
"# Undeploy model and delete endpoint.\n",
"endpoint.delete(force=True)\n",
"\n",
"# Delete models.\n",
"# Delete model.\n",
"model.delete()\n",
"\n",
"# Delete Cloud Storage objects that were created\n",
"# Delete Cloud Storage objects that were created.\n",
"delete_bucket = False # @param {type:\"boolean\"}\n",
"if delete_bucket:\n",
" ! gsutil -m rm -r $BUCKET_URI"