@@ -276,24 +276,34 @@ deploymentSpec:
276276 )\n\n # 1. Initialize Vertex AI and find blessed model\n aiplatform.init(project=project_id,\
277277 \ location=location)\n\n client = aiplatform_v1.ModelServiceClient(\n \
278278 \ client_options={\" api_endpoint\" : f\" {location}-aiplatform.googleapis.com\" \
279- }\n )\n request = {\n \" parent\" : f\" projects/{project_id}/locations/{location}\" \
280- ,\n \" filter\" : f\" display_name={model_name}\"\n }\n\n models\
281- \ = list(client.list_models(request=request))\n blessed_model = None\n \
282- \n print(f\" Found {len(models)} models with name {model_name}\" )\n\n \
283- \ for model in models:\n print(f\" Model: {model.name}, Aliases:\
284- \ {list(model.version_aliases)}\" )\n if \" blessed\" in model.version_aliases:\n \
285- \ blessed_model = model\n break\n\n if not blessed_model:\n \
286- \ raise ValueError(f\" No blessed version found for model {model_name}.\
287- \ Available models: {[(m.name, list(m.version_aliases)) for m in models]}\" \
288- )\n\n print(f\" Found blessed model: {blessed_model.name}\" )\n print(f\" \
289- Model URI: {blessed_model.artifact_uri}\" )\n\n # 2. Download joblib model\
290- \ from blessed version\n gcs_uri = blessed_model.artifact_uri\n if\
291- \ not gcs_uri.startswith('gs://'):\n raise ValueError(f\" Expected\
292- \ GCS URI, got: {gcs_uri}\" )\n\n bucket_name = gcs_uri.replace('gs://',\
293- \ '').split('/')[0]\n model_path = '/'.join(gcs_uri.replace('gs://',\
294- \ '').split('/')[1:])\n\n print(f\" Downloading model from gs://{bucket_name}/{model_path}\" \
295- )\n\n storage_client = storage.Client()\n bucket = storage_client.bucket(bucket_name)\n \
296- \n # Download and validate the model\n model_blob_path = f\" {model_path}/model.joblib\" \
279+ }\n )\n\n print(f\" Searching for blessed model with name: {model_name}\" \
280+ )\n\n # Use the high-level aiplatform library to list all model versions\n \
281+ \ models = aiplatform.Model.list(filter=f\" display_name={model_name}\" \
282+ )\n blessed_model = None\n\n print(f\" Found {len(models)} model versions\
283+ \ with name {model_name}\" )\n\n # Search through all model versions (each\
284+ \ item in models is already a version)\n for parent_model in models:\n \
285+ \ print(f\" Checking parent model: projects/57434141298/locations/{location}/models/{parent_model.name}\" \
286+ )\n\n # List all versions of this model\n versions_request\
287+ \ = {\" name\" : parent_model.name}\n versions = list(client.list_model_versions(request=versions_request))\n \
288+ \n print(f\" Found {len(versions)} versions for this model\" )\n\n \
289+ \ for version in versions:\n print(f\" Version {version.version_id}:\
290+ \ Aliases = {list(version.version_aliases)}\" )\n if \" blessed\" \
291+ \ in version.version_aliases:\n blessed_model = version\n \
292+ \ print(f\" Found blessed version: {version.version_id}\" \
293+ )\n break\n\n if blessed_model:\n break\n \
294+ \n if not blessed_model:\n available_versions = [(m.resource_name,\
295+ \ m.version_id, list(m.version_aliases)) for m in models]\n raise\
296+ \ ValueError(f\" No blessed version found for model {model_name}. Available\
297+ \ versions: {available_versions}\" )\n\n print(f\" Found blessed model:\
298+ \ {blessed_model.name}\" )\n print(f\" Model URI: {blessed_model.artifact_uri}\" \
299+ )\n\n # 2. Download joblib model from blessed version\n gcs_uri =\
300+ \ blessed_model.artifact_uri\n if not gcs_uri.startswith('gs://'):\n \
301+ \ raise ValueError(f\" Expected GCS URI, got: {gcs_uri}\" )\n\n \
302+ \ bucket_name = gcs_uri.replace('gs://', '').split('/')[0]\n model_path\
303+ \ = '/'.join(gcs_uri.replace('gs://', '').split('/')[1:])\n\n print(f\" \
304+ Downloading model from gs://{bucket_name}/{model_path}\" )\n\n storage_client\
305+ \ = storage.Client()\n bucket = storage_client.bucket(bucket_name)\n\n \
306+ \ # Download and validate the model\n model_blob_path = f\" {model_path}/model.joblib\" \
297307 \n blob = bucket.blob(model_blob_path)\n\n if not blob.exists():\n \
298308 \ raise ValueError(f\" Model file not found at gs://{bucket_name}/{model_blob_path}\" \
299309 )\n\n with tempfile.NamedTemporaryFile(suffix='.joblib', delete=False)\
0 commit comments