class_docstr: Class for interacting with Vertex Prediction service.
class_docstr_tok: ["Class","for","interacting","with","Vertex","Prediction","service","."]
docstr: Deletes a model from Google Cloud AI Platform if model exists.
  
  Args:
    ai_platform_serving_args: Dictionary containing arguments for pushing to
      AI Platform. For the full set of parameters supported, refer to
      https://googleapis.dev/python/aiplatform/latest/aiplatform.html?highlight=deploy#google.cloud.aiplatform.Model.deploy.
    model_version_name: Name of the Vertex model being deleted. Required if
      delete_model_endpoint is False, otherwise not needed.
    delete_model_endpoint: If True, deletes the Vertex endpoint, which
      automatically deletes all models at the endpoint. If False, deletes only
      the model with model_version_name at the endpoint.
  
  Raises:
    RuntimeError: if an error is encountered when trying to delete.
docstr_tok: ["Deletes","a","model","from","Google","Cloud","AI","Platform","if","model","exists",".","Args",":","ai_platform_serving_args",":","Dictionary","containing","arguments","for","pushing","to","AI","Platform",".","For","the","full","set","of","parameters","supported",",","refer","to","https",":","\/\/googleapis.dev\/python\/aiplatform\/latest\/aiplatform.html","?","highlight=deploy","#","google.cloud.aiplatform.Model.deploy",".","model_version_name",":","Name","of","the","Vertex","model","being","deleted",".","Required","if","delete_model_endpoint","is","False",",","otherwise","not","needed",".","delete_model_endpoint",":","If","True",",","deletes","the","Vertex","endpoint",",","which","automatically","deletes","all","models","at","the","endpoint",".","If","False",",","deletes","only","the","model","with","model_version_name","at","the","endpoint",".","Raises",":","RuntimeError",":","if","an","error","is","encountered","when","trying","to","delete","."]
code: def delete_model_from_aip_if_exists(
      self,
      ai_platform_serving_args: Dict[str, Any],
      model_version_name: Optional[str] = None,
      delete_model_endpoint: Optional[bool] = False,
  ) -> None:
      """Deletes a model from Google Cloud AI Platform if model exists.
  
      Args:
        ai_platform_serving_args: Dictionary containing arguments for pushing to
          AI Platform. For the full set of parameters supported, refer to
          https://googleapis.dev/python/aiplatform/latest/aiplatform.html?highlight=deploy#google.cloud.aiplatform.Model.deploy.
        model_version_name: Name of the Vertex model being deleted. Required if
          delete_model_endpoint is False, otherwise not needed.
        delete_model_endpoint: If True, deletes the Vertex endpoint, which
          automatically deletes all models at the endpoint. If False, deletes only
          the model with model_version_name at the endpoint.
  
      Raises:
        RuntimeError: if an error is encountered when trying to delete.
      """
      endpoint = self._get_endpoint(ai_platform_serving_args)
  
      if endpoint is None:
          return
  
      if delete_model_endpoint:
          logging.info(
              "Deleting endpoint with from AI Platform: %s",
              ai_platform_serving_args,
          )
          try:
              endpoint.delete(force=True, sync=True)
          except errors.HttpError as e:
              if e.resp.status == 404:
                  logging.warn(
                      "Endpoint %s does not exist",
                      ai_platform_serving_args["endpoint_name"],
                  )
              else:
                  raise RuntimeError(
                      "Deleting endpoint from AI Platform failed."
                  ) from e
      else:
          if model_version_name is None:
              raise ValueError(
                  "model_version_name is required if"
                  " delete_model_endpoint is False"
              )
          logging.info(
              "Deleting model %s from AI Platform: %s",
              model_version_name,
              ai_platform_serving_args,
          )
          deployed_models = endpoint.list_models()
          models = [
              model
              for model in deployed_models
              if model.display_name == model_version_name
          ]
          if models:
              model_to_undeploy = models[0]
          else:
              logging.warn(
                  "Model %s does not exist at endpoint %s",
                  model_version_name,
                  ai_platform_serving_args["endpoint_name"],
              )
              return
          deployed_model_id = model_to_undeploy.id
          try:
              endpoint.undeploy(
                  deployed_model_id=deployed_model_id, sync=True
              )
          except errors.HttpError as e:
              # If the error is to delete an non-existent model version,
              # it's ok to ignore.
              if e.resp.status == 404:
                  logging.warn(
                      "Model %s does not exist", model_version_name
                  )
              if e.resp.status == 400:
                  logging.warn(
                      "Model %s won't be deleted because it is the "
                      "default version and not the only version in the model",
                      model_version_name,
                  )
              else:
                  raise RuntimeError(
                      "Deleting model {} from AI Platform failed.".format(
                          model_version_name
                      )
                  ) from e
  
imports: import abc
  import sys
  import time
  from typing import Any, Dict, Optional, Union
  from absl import logging
  from google.cloud import aiplatform
  from googleapiclient import discovery
  from googleapiclient import errors
  import tensorflow
label_desc: Use image node_id 3 for calling the VertexPredictionClient obj's underlying member method code with example usage: obj.delete_model_from_aip_if_exists(ai_platform_serving_args, model_version_name, delete_model_endpoint) without return types