Skip to content

Commit

Permalink
Endpoint artifacts rename to deployment artifacts (#2134)
Browse files Browse the repository at this point in the history
* `endpoint_artifact`>`deployment_artifact`

* migration

* migration

* updated template

* Auto-update of E2E template

* update test definition

* branching

* Auto-update of E2E template

* Auto-update of NLP template

* Apply suggestions from code review

Co-authored-by: Stefan Nica <[email protected]>

---------

Co-authored-by: GitHub Actions <[email protected]>
Co-authored-by: Stefan Nica <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2023
1 parent c0aba01 commit 6468a22
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 83 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/update-templates-to-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ jobs:
python-version: ${{ inputs.python-version }}
stack-name: local
ref-zenml: ${{ github.ref }}
ref-template: '2023.12.06' # Make sure it is aligned with ZENML_PROJECT_TEMPLATES from src/zenml/cli/base.py

ref-template: '2023.12.12' # Make sure it is aligned with ZENML_PROJECT_TEMPLATES from src/zenml/cli/base.py
- name: Clean-up
run: |
rm -rf ./local_checkout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ how artifacts are linked to models:
- `model_name`: The name of the model to link the artifact to.
- `model_version`: The version of the model to link the artifact to.
- `is_model_artifact`: Whether the artifact is a model artifact.
- `is_endpoint_artifact`: Whether the artifact is an endpoint artifact.
- `is_deployment_artifact`: Whether the artifact is a deployment artifact.

<!-- For scarf -->
<figure><img alt="ZenML Scarf" referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=f0b4f458-0a54-4fcd-aa95-d5ee424815bc" /></figure>
2 changes: 1 addition & 1 deletion examples/e2e/.copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 2023.12.06
_commit: 2023.12.06-4-g1e3edc6
_src_path: gh:zenml-io/template-e2e-batch
data_quality_checks: true
email: ''
Expand Down
2 changes: 1 addition & 1 deletion examples/e2e/steps/deployment/deployment_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
def deployment_deploy() -> (
Annotated[
Optional[MLFlowDeploymentService],
ArtifactConfig(name="mlflow_deployment", is_endpoint_artifact=True),
ArtifactConfig(name="mlflow_deployment", is_deployment_artifact=True),
]
):
"""Predictions step.
Expand Down
4 changes: 2 additions & 2 deletions src/zenml/artifacts/artifact_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def my_step() -> Annotated[
(42), stage (ModelStages.PRODUCTION or "production"), or
(ModelStages.LATEST or None) for the latest version (default).
is_model_artifact: Whether the artifact is a model artifact.
is_endpoint_artifact: Whether the artifact is an endpoint artifact.
is_deployment_artifact: Whether the artifact is a deployment artifact.
"""

name: Optional[str] = None
Expand All @@ -67,7 +67,7 @@ def my_step() -> Annotated[
model_name: Optional[str] = None
model_version: Optional[Union[ModelStages, str, int]] = None
is_model_artifact: bool = False
is_endpoint_artifact: bool = False
is_deployment_artifact: bool = False

@root_validator
def _root_validator(cls, values: Dict[str, Any]) -> Dict[str, Any]:
Expand Down
2 changes: 1 addition & 1 deletion src/zenml/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def copier_github_url(self) -> str:
ZENML_PROJECT_TEMPLATES = dict(
e2e_batch=ZenMLProjectTemplateLocation(
github_url="zenml-io/template-e2e-batch",
github_tag="2023.12.06", # Make sure it is aligned with .github/workflows/update-templates-to-examples.yml
github_tag="2023.12.12", # Make sure it is aligned with .github/workflows/update-templates-to-examples.yml
),
starter=ZenMLProjectTemplateLocation(
github_url="zenml-io/template-starter",
Expand Down
27 changes: 15 additions & 12 deletions src/zenml/cli/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def _model_version_to_print(
"tags": [t.name for t in model_version.tags],
"data_artifacts_count": len(model_version.data_artifact_ids),
"model_artifacts_count": len(model_version.model_artifact_ids),
"endpoint_artifacts_count": len(model_version.endpoint_artifact_ids),
"deployment_artifacts_count": len(
model_version.deployment_artifact_ids
),
"pipeline_runs_count": len(model_version.pipeline_run_ids),
"updated": model_version.updated.date(),
}
Expand Down Expand Up @@ -519,7 +521,7 @@ def _print_artifacts_links_generic(
model_name_or_id: str,
model_version_name_or_number_or_id: Optional[str] = None,
only_data_artifacts: bool = False,
only_endpoint_artifacts: bool = False,
only_deployment_artifacts: bool = False,
only_model_artifacts: bool = False,
**kwargs: Any,
) -> None:
Expand All @@ -529,7 +531,7 @@ def _print_artifacts_links_generic(
model_name_or_id: The ID or name of the model containing version.
model_version_name_or_number_or_id: The name, number or ID of the model version.
only_data_artifacts: If set, only print data artifacts.
only_endpoint_artifacts: If set, only print endpoint artifacts.
only_deployment_artifacts: If set, only print deployment artifacts.
only_model_artifacts: If set, only print model artifacts.
**kwargs: Keyword arguments to filter models.
"""
Expand All @@ -540,15 +542,16 @@ def _print_artifacts_links_generic(
type_ = (
"data artifacts"
if only_data_artifacts
else "endpoint artifacts"
if only_endpoint_artifacts
else "deployment artifacts"
if only_deployment_artifacts
else "model artifacts"
)

if (
(only_data_artifacts and not model_version.data_artifact_ids)
or (
only_endpoint_artifacts and not model_version.endpoint_artifact_ids
only_deployment_artifacts
and not model_version.deployment_artifact_ids
)
or (only_model_artifacts and not model_version.model_artifact_ids)
):
Expand All @@ -562,7 +565,7 @@ def _print_artifacts_links_generic(
links = Client().list_model_version_artifact_links(
model_version_id=model_version.id,
only_data_artifacts=only_data_artifacts,
only_endpoint_artifacts=only_endpoint_artifacts,
only_deployment_artifacts=only_deployment_artifacts,
only_model_artifacts=only_model_artifacts,
**kwargs,
)
Expand Down Expand Up @@ -630,18 +633,18 @@ def list_model_version_model_artifacts(


@model.command(
"endpoint_artifacts",
help="List endpoint artifacts linked to a model version.",
"deployment_artifacts",
help="List deployment artifacts linked to a model version.",
)
@click.argument("model_name")
@click.option("--model_version", "-v", default=None)
@cli_utils.list_options(ModelVersionArtifactFilter)
def list_model_version_endpoint_artifacts(
def list_model_version_deployment_artifacts(
model_name: str,
model_version: Optional[str] = None,
**kwargs: Any,
) -> None:
"""List endpoint artifacts linked to a model version in the Model Control Plane.
"""List deployment artifacts linked to a model version in the Model Control Plane.
Args:
model_name: The ID or name of the model containing version.
Expand All @@ -652,7 +655,7 @@ def list_model_version_endpoint_artifacts(
_print_artifacts_links_generic(
model_name_or_id=model_name,
model_version_name_or_number_or_id=model_version,
only_endpoint_artifacts=True,
only_deployment_artifacts=True,
**kwargs,
)

Expand Down
6 changes: 3 additions & 3 deletions src/zenml/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4816,7 +4816,7 @@ def list_model_version_artifact_links(
artifact_name: Optional[str] = None,
only_data_artifacts: Optional[bool] = None,
only_model_artifacts: Optional[bool] = None,
only_endpoint_artifacts: Optional[bool] = None,
only_deployment_artifacts: Optional[bool] = None,
) -> Page[ModelVersionArtifactResponse]:
"""Get model version to artifact links by filter in Model Control Plane.
Expand All @@ -4835,7 +4835,7 @@ def list_model_version_artifact_links(
artifact_name: Use the artifact name for filtering
only_data_artifacts: Use to filter by data artifacts
only_model_artifacts: Use to filter by model artifacts
only_endpoint_artifacts: Use to filter by endpoint artifacts
only_deployment_artifacts: Use to filter by deployment artifacts
Returns:
A page of all model version to artifact links.
Expand All @@ -4856,7 +4856,7 @@ def list_model_version_artifact_links(
artifact_name=artifact_name,
only_data_artifacts=only_data_artifacts,
only_model_artifacts=only_model_artifacts,
only_endpoint_artifacts=only_endpoint_artifacts,
only_deployment_artifacts=only_deployment_artifacts,
)
)

Expand Down
12 changes: 6 additions & 6 deletions src/zenml/model/model_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,24 @@ def get_data_artifact(
version=version,
)

def get_endpoint_artifact(
def get_deployment_artifact(
self,
name: str,
version: Optional[str] = None,
) -> Optional[Union["ArtifactVersionResponse", "ExternalArtifact"]]:
"""Get the endpoint artifact linked to this model version.
"""Get the deployment artifact linked to this model version.
Args:
name: The name of the endpoint artifact to retrieve.
version: The version of the endpoint artifact to retrieve (None for latest/non-versioned)
name: The name of the deployment artifact to retrieve.
version: The version of the deployment artifact to retrieve (None for latest/non-versioned)
Returns:
Inside pipeline context: ExternalArtifact object as a lazy loader
Outside of pipeline context: Specific version of the endpoint artifact or None
Outside of pipeline context: Specific version of the deployment artifact or None
"""
if response := self._try_get_as_external_artifact(name, version):
return response
return self._get_or_create_model_version().get_endpoint_artifact(
return self._get_or_create_model_version().get_deployment_artifact(
name=name,
version=version,
)
Expand Down
2 changes: 1 addition & 1 deletion src/zenml/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def link_artifact_config_to_model_version(
model=model_version_response.model.id,
model_version=model_version_response.id,
is_model_artifact=artifact_config.is_model_artifact,
is_endpoint_artifact=artifact_config.is_endpoint_artifact,
is_deployment_artifact=artifact_config.is_deployment_artifact,
)
client.zen_store.create_model_version_artifact_link(request)

Expand Down
34 changes: 17 additions & 17 deletions src/zenml/models/v2/core/model_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ class ModelVersionResponseBody(WorkspaceScopedResponseBody):
description="Data artifacts linked to the model version",
default={},
)
endpoint_artifact_ids: Dict[str, Dict[str, UUID]] = Field(
description="Endpoint artifacts linked to the model version",
deployment_artifact_ids: Dict[str, Dict[str, UUID]] = Field(
description="Deployment artifacts linked to the model version",
default={},
)
pipeline_run_ids: Dict[str, UUID] = Field(
Expand Down Expand Up @@ -238,13 +238,13 @@ def data_artifact_ids(self) -> Dict[str, Dict[str, UUID]]:
return self.get_body().data_artifact_ids

@property
def endpoint_artifact_ids(self) -> Dict[str, Dict[str, UUID]]:
"""The `endpoint_artifact_ids` property.
def deployment_artifact_ids(self) -> Dict[str, Dict[str, UUID]]:
"""The `deployment_artifact_ids` property.
Returns:
the value of the property.
"""
return self.get_body().endpoint_artifact_ids
return self.get_body().deployment_artifact_ids

@property
def pipeline_run_ids(self) -> Dict[str, UUID]:
Expand Down Expand Up @@ -391,20 +391,20 @@ def data_artifacts(
def endpoint_artifacts(
self,
) -> Dict[str, Dict[str, "ArtifactVersionResponse"]]:
"""Get all endpoint artifacts linked to this model version.
"""Get all deployment artifacts linked to this model version.
Returns:
Dictionary of endpoint artifacts with versions as
Dictionary of deployment artifacts with versions as
Dict[str, Dict[str, ArtifactResponse]]
"""
from zenml.client import Client

return {
name: {
version: Client().get_artifact_version(a)
for version, a in self.endpoint_artifact_ids[name].items()
for version, a in self.deployment_artifact_ids[name].items()
}
for name in self.endpoint_artifact_ids
for name in self.deployment_artifact_ids
}

@property
Expand Down Expand Up @@ -432,7 +432,7 @@ def _get_linked_object(
Args:
collection: The collection to search in (one of
self.model_artifact_ids, self.data_artifact_ids,
self.endpoint_artifact_ids)
self.deployment_artifact_ids)
name: The name of the artifact to retrieve.
version: The version of the artifact to retrieve (None for
latest/non-versioned)
Expand Down Expand Up @@ -468,7 +468,7 @@ def get_artifact(
all_artifact_ids = {
**self.model_artifact_ids,
**self.data_artifact_ids,
**self.endpoint_artifact_ids,
**self.deployment_artifact_ids,
}
return self._get_linked_object(all_artifact_ids, name, version)

Expand Down Expand Up @@ -510,23 +510,23 @@ def get_data_artifact(
version,
)

def get_endpoint_artifact(
def get_deployment_artifact(
self,
name: str,
version: Optional[str] = None,
) -> Optional["ArtifactVersionResponse"]:
"""Get the endpoint artifact linked to this model version.
"""Get the deployment artifact linked to this model version.
Args:
name: The name of the endpoint artifact to retrieve.
version: The version of the endpoint artifact to retrieve (None for
name: The name of the deployment artifact to retrieve.
version: The version of the deployment artifact to retrieve (None for
latest/non-versioned)
Returns:
Specific version of the endpoint artifact or None
Specific version of the deployment artifact or None
"""
return self._get_linked_object(
self.endpoint_artifact_ids,
self.deployment_artifact_ids,
name,
version,
)
Expand Down
26 changes: 13 additions & 13 deletions src/zenml/models/v2/core/model_version_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ class ModelVersionArtifactRequest(WorkspaceScopedRequest):
model_version: UUID
artifact_version: UUID
is_model_artifact: bool = False
is_endpoint_artifact: bool = False
is_deployment_artifact: bool = False

@validator("is_endpoint_artifact")
@validator("is_deployment_artifact")
def _validate_is_endpoint_artifact(
cls, is_endpoint_artifact: bool, values: Dict[str, Any]
cls, is_deployment_artifact: bool, values: Dict[str, Any]
) -> bool:
is_model_artifact = values.get("is_model_artifact", False)
if is_model_artifact and is_endpoint_artifact:
if is_model_artifact and is_deployment_artifact:
raise ValueError(
"Artifact cannot be a model artifact and endpoint artifact "
"Artifact cannot be a model artifact and deployment artifact "
"at the same time."
)
return is_endpoint_artifact
return is_deployment_artifact


# ------------------ Update Model ------------------
Expand All @@ -71,7 +71,7 @@ class ModelVersionArtifactResponseBody(BaseResponseBody):
model_version: UUID
artifact_version: "ArtifactVersionResponse"
is_model_artifact: bool = False
is_endpoint_artifact: bool = False
is_deployment_artifact: bool = False


class ModelVersionArtifactResponse(
Expand Down Expand Up @@ -117,13 +117,13 @@ def is_model_artifact(self) -> bool:
return self.get_body().is_model_artifact

@property
def is_endpoint_artifact(self) -> bool:
"""The `is_endpoint_artifact` property.
def is_deployment_artifact(self) -> bool:
"""The `is_deployment_artifact` property.
Returns:
the value of the property.
"""
return self.get_body().is_endpoint_artifact
return self.get_body().is_deployment_artifact


# ------------------ Filter Model ------------------
Expand All @@ -138,7 +138,7 @@ class ModelVersionArtifactFilter(WorkspaceScopedFilter):
"artifact_name",
"only_data_artifacts",
"only_model_artifacts",
"only_endpoint_artifacts",
"only_deployment_artifacts",
]

workspace_id: Optional[Union[UUID, str]] = Field(
Expand All @@ -162,13 +162,13 @@ class ModelVersionArtifactFilter(WorkspaceScopedFilter):
)
only_data_artifacts: Optional[bool] = False
only_model_artifacts: Optional[bool] = False
only_endpoint_artifacts: Optional[bool] = False
only_deployment_artifacts: Optional[bool] = False

CLI_EXCLUDE_FIELDS = [
*WorkspaceScopedFilter.CLI_EXCLUDE_FIELDS,
"only_data_artifacts",
"only_model_artifacts",
"only_endpoint_artifacts",
"only_deployment_artifacts",
"model_id",
"model_version_id",
"user_id",
Expand Down
Loading

0 comments on commit 6468a22

Please sign in to comment.