Skip to content

Commit 371df7e

Browse files
committed
fix versions
1 parent 2d58802 commit 371df7e

3 files changed

Lines changed: 521 additions & 29 deletions

File tree

pipeline.yaml

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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: {parent_model.name}\")\n\n \
286+
\ # List all versions of this model\n versions_request = {\"name\"\
287+
: 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)\

src/ml_pipelines_kfp/iris_xgboost/pipelines/components/deploy.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,38 @@ def deploy_blessed_model_to_fastapi(
3434
client = aiplatform_v1.ModelServiceClient(
3535
client_options={"api_endpoint": f"{location}-aiplatform.googleapis.com"}
3636
)
37-
request = {
38-
"parent": f"projects/{project_id}/locations/{location}",
39-
"filter": f"display_name={model_name}"
40-
}
4137

42-
models = list(client.list_models(request=request))
38+
print(f"Searching for blessed model with name: {model_name}")
39+
40+
# Use the high-level aiplatform library to list all model versions
41+
models = aiplatform.Model.list(filter=f"display_name={model_name}")
4342
blessed_model = None
4443

45-
print(f"Found {len(models)} models with name {model_name}")
44+
print(f"Found {len(models)} model versions with name {model_name}")
4645

47-
for model in models:
48-
print(f"Model: {model.name}, Aliases: {list(model.version_aliases)}")
49-
if "blessed" in model.version_aliases:
50-
blessed_model = model
46+
# Search through all model versions (each item in models is already a version)
47+
for parent_model in models:
48+
print(f"Checking parent model: projects/{project_id}/locations/{location}/models/{parent_model.name}")
49+
50+
# List all versions of this model
51+
versions_request = {"name": parent_model.name}
52+
versions = list(client.list_model_versions(request=versions_request))
53+
54+
print(f"Found {len(versions)} versions for this model")
55+
56+
for version in versions:
57+
print(f"Version {version.version_id}: Aliases = {list(version.version_aliases)}")
58+
if "blessed" in version.version_aliases:
59+
blessed_model = version
60+
print(f"Found blessed version: {version.version_id}")
61+
break
62+
63+
if blessed_model:
5164
break
5265

5366
if not blessed_model:
54-
raise ValueError(f"No blessed version found for model {model_name}. Available models: {[(m.name, list(m.version_aliases)) for m in models]}")
67+
available_versions = [(m.resource_name, m.version_id, list(m.version_aliases)) for m in models]
68+
raise ValueError(f"No blessed version found for model {model_name}. Available versions: {available_versions}")
5569

5670
print(f"Found blessed model: {blessed_model.name}")
5771
print(f"Model URI: {blessed_model.artifact_uri}")

0 commit comments

Comments
 (0)