|
1 | | -# Apache Software License 2.0 |
2 | | -# |
3 | | -# Copyright (c) ZenML GmbH 2023. All rights reserved. |
4 | | -# |
5 | | -# Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | -# you may not use this file except in compliance with the License. |
7 | | -# You may obtain a copy of the License at |
8 | | -# |
9 | | -# http://www.apache.org/licenses/LICENSE-2.0 |
10 | | -# |
11 | | -# Unless required by applicable law or agreed to in writing, software |
12 | | -# distributed under the License is distributed on an "AS IS" BASIS, |
13 | | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | -# See the License for the specific language governing permissions and |
15 | | -# limitations under the License. |
16 | | -# |
17 | | - |
18 | | -from typing import Any |
19 | | - |
20 | 1 | from typing_extensions import Annotated |
| 2 | + |
21 | 3 | from zenml import ArtifactConfig, get_step_context, step |
22 | 4 | from zenml.client import Client |
23 | 5 | from zenml.integrations.gcp.services.vertex_deployment import ( |
24 | | - VertexAIDeploymentConfig, |
| 6 | + VertexDeploymentConfig, |
25 | 7 | VertexDeploymentService, |
26 | 8 | ) |
27 | 9 | from zenml.logger import get_logger |
|
32 | 14 | @step(enable_cache=False) |
33 | 15 | def model_deployer( |
34 | 16 | model_registry_uri: str, |
| 17 | + is_promoted: bool = False, |
35 | 18 | ) -> Annotated[ |
36 | | - VertexDeploymentService, ArtifactConfig(name="vertex_deployment", is_deployment_artifact=True) |
| 19 | + VertexDeploymentService, |
| 20 | + ArtifactConfig(name="vertex_deployment", is_deployment_artifact=True), |
37 | 21 | ]: |
38 | 22 | """Model deployer step. |
39 | | - |
| 23 | +
|
40 | 24 | Args: |
41 | 25 | model_registry_uri: URI of the model in the model registry. |
42 | | - |
| 26 | + is_promoted: Whether the model was promoted to production. |
| 27 | +
|
43 | 28 | Returns: |
44 | 29 | The deployed model service. |
45 | 30 | """ |
46 | | - zenml_client = Client() |
47 | | - current_model = get_step_context().model |
48 | | - model_deployer = zenml_client.active_stack.model_deployer |
49 | | - vertex_deployment_config = VertexAIDeploymentConfig( |
50 | | - location="europe-west1", |
51 | | - name="zenml-vertex-quickstart", |
52 | | - model_name=current_model.name, |
53 | | - description="An example of deploying a model using the MLflow Model Deployer", |
54 | | - model_id=model_registry_uri, |
55 | | - ) |
56 | | - service = model_deployer.deploy_model( |
57 | | - config=vertex_deployment_config, |
58 | | - service_type=VertexDeploymentService.SERVICE_TYPE, |
59 | | - ) |
| 31 | + if not is_promoted: |
| 32 | + logger.info("Model not promoted, skipping deployment") |
| 33 | + return None |
| 34 | + else: |
| 35 | + zenml_client = Client() |
| 36 | + current_model = get_step_context().model |
| 37 | + model_deployer = zenml_client.active_stack.model_deployer |
| 38 | + |
| 39 | + # Create deployment configuration with proper model name and version |
| 40 | + vertex_deployment_config = VertexDeploymentConfig( |
| 41 | + location="europe-west1", |
| 42 | + name=current_model.name, |
| 43 | + display_name="zenml-vertex-quickstart", |
| 44 | + model_name=model_registry_uri, # This is the full resource name from registration |
| 45 | + model_version=current_model.version, # Specify the version explicitly |
| 46 | + description="An example of deploying a model using the Vertex AI Model Deployer", |
| 47 | + sync=True, # Wait for deployment to complete |
| 48 | + traffic_percentage=100, # Route all traffic to this version |
| 49 | + ) |
| 50 | + |
| 51 | + service = model_deployer.deploy_model( |
| 52 | + config=vertex_deployment_config, |
| 53 | + service_type=VertexDeploymentService.SERVICE_TYPE, |
| 54 | + ) |
60 | 55 |
|
61 | | - logger.info( |
62 | | - f"The deployed service info: {model_deployer.get_model_server_info(service)}" |
63 | | - ) |
64 | | - return service |
| 56 | + logger.info( |
| 57 | + f"The deployed service info: {model_deployer.get_model_server_info(service)}" |
| 58 | + ) |
| 59 | + return service |
0 commit comments