<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 TF-Keras Text Classification Distributed Single Worker GPUs using Vertex Training with Local Mode Container
<table align="left">
  <td>
    <a href="https
Step1:  Local Training with Vertex Local Mode and Auto Packaging
Step2:  Vertex Training using Vertex SDK and Vertex Local Mode Container
Container Built by Vertex Local Mode
Step3:  Initialize Vertex SDK
Step4:  Create a Vertex Tensorboard Instance
Step5:  Option
Step6:  Training Output Artifact
Step7:  Clean Up Artifact
<ASSISTANT_TASK:>
Python Code:
PROJECT_ID = "YOUR PROJECT ID"
BUCKET_NAME = "gs://YOUR BUCKET NAME"
REGION = "YOUR REGION"
SERVICE_ACCOUNT = "YOUR SERVICE ACCOUNT"
content_name = "tf-keras-txt-cls-dist-single-worker-gpus-local-mode-cont"
Explanation: TF-Keras Text Classification Distributed Single Worker GPUs using Vertex Training with Local Mode Container
<table align="left">
  <td>
    <a href="https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/community-content/tf_keras_text_classification_distributed_single_worker_gpus_with_gcloud_local_run_and_vertex_sdk/vertex_training_with_local_mode_container.ipynb">
      <img src="https://cloud.google.com/ml-engine/images/github-logo-32px.png" alt="GitHub logo">
      View on GitHub
    </a>
  </td>
</table>
Setup
End of explanation
BASE_IMAGE_URI = "us-docker.pkg.dev/vertex-ai/training/tf-gpu.2-5:latest"
SCRIPT_PATH = "trainer/task.py"
OUTPUT_IMAGE_NAME = "gcr.io/{}/{}:latest".format(PROJECT_ID, content_name)
ARGS = "--epochs 5 --batch-size 16 --local-mode"
! gcloud ai custom-jobs local-run \
  --executor-image-uri=$BASE_IMAGE_URI \
  --script=$SCRIPT_PATH \
  --output-image-uri=$OUTPUT_IMAGE_NAME \
  -- \
  $ARGS
Explanation: Local Training with Vertex Local Mode and Auto Packaging
End of explanation
custom_container_image_uri = OUTPUT_IMAGE_NAME
! docker push $custom_container_image_uri
! gcloud container images list --repository "gcr.io"/$PROJECT_ID
Explanation: Vertex Training using Vertex SDK and Vertex Local Mode Container
Container Built by Vertex Local Mode
End of explanation
! pip install -r requirements.txt
from google.cloud import aiplatform
aiplatform.init(
    project=PROJECT_ID,
    staging_bucket=BUCKET_NAME,
    location=REGION,
)
Explanation: Initialize Vertex SDK
End of explanation
tensorboard = aiplatform.Tensorboard.create(
    display_name=content_name,
)
Explanation: Create a Vertex Tensorboard Instance
End of explanation
display_name = content_name
gcs_output_uri_prefix = f"{BUCKET_NAME}/{display_name}"
machine_type = "n1-standard-8"
accelerator_count = 4
accelerator_type = "NVIDIA_TESLA_P100"
args = [
    "--epochs",
    "100",
    "--batch-size",
    "128",
    "--num-gpus",
    f"{accelerator_count}",
]
custom_container_training_job = aiplatform.CustomContainerTrainingJob(
    display_name=display_name,
    container_uri=custom_container_image_uri,
)
custom_container_training_job.run(
    args=args,
    base_output_dir=gcs_output_uri_prefix,
    machine_type=machine_type,
    accelerator_type=accelerator_type,
    accelerator_count=accelerator_count,
    tensorboard=tensorboard.resource_name,
    service_account=SERVICE_ACCOUNT,
)
print(f"Custom Training Job Name: {custom_container_training_job.resource_name}")
print(f"GCS Output URI Prefix: {gcs_output_uri_prefix}")
Explanation: Option: Use a Previously Created Vertex Tensorboard Instance
tensorboard_name = "Your Tensorboard Resource Name or Tensorboard ID"
tensorboard = aiplatform.Tensorboard(tensorboard_name=tensorboard_name)
Run a Vertex SDK CustomContainerTrainingJob
End of explanation
! gsutil ls $gcs_output_uri_prefix
Explanation: Training Output Artifact
End of explanation
! gsutil rm -rf $gcs_output_uri_prefix
Explanation: Clean Up Artifact
End of explanation
<END_TASK>