forked from zenml-io/zenml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Model links lazy evaluation in pipeline code (zenml-io#2205)
* MV data lazy loading in pipelines * add tests * new template ref * use `BaseModel` * Auto-update of Starter template * update to `v7` syntax * update test signatures * Auto-update of E2E template * update test signatures * wandb lint * lint * remove leftover * Apply suggestions from code review Co-authored-by: Alex Strick van Linschoten <[email protected]> * renaming * model lazy load in `model` * metadata lazy load in `metadata` * implement Michael's suggestions --------- Co-authored-by: GitHub Actions <[email protected]> Co-authored-by: Alex Strick van Linschoten <[email protected]>
- Loading branch information
Showing
23 changed files
with
460 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright (c) ZenML GmbH 2024. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
# or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
"""Run Metadata Lazy Loader definition.""" | ||
|
||
from typing import TYPE_CHECKING, Optional | ||
|
||
if TYPE_CHECKING: | ||
from zenml.model.model_version import ModelVersion | ||
from zenml.models import RunMetadataResponse | ||
|
||
|
||
class RunMetadataLazyGetter: | ||
"""Run Metadata Lazy Getter helper class. | ||
It serves the purpose to feed back to the user the metadata | ||
lazy loader wrapper for any given key, if called inside a pipeline | ||
design time context. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
_lazy_load_model_version: "ModelVersion", | ||
_lazy_load_artifact_name: Optional[str], | ||
_lazy_load_artifact_version: Optional[str], | ||
): | ||
"""Initialize a RunMetadataLazyGetter. | ||
Args: | ||
_lazy_load_model_version: The model version. | ||
_lazy_load_artifact_name: The artifact name. | ||
_lazy_load_artifact_version: The artifact version. | ||
""" | ||
self._lazy_load_model_version = _lazy_load_model_version | ||
self._lazy_load_artifact_name = _lazy_load_artifact_name | ||
self._lazy_load_artifact_version = _lazy_load_artifact_version | ||
|
||
def __getitem__(self, key: str) -> "RunMetadataResponse": | ||
"""Get the metadata for the given key. | ||
Args: | ||
key: The metadata key. | ||
Returns: | ||
The metadata lazy loader wrapper for the given key. | ||
""" | ||
from zenml.models.v2.core.run_metadata import LazyRunMetadataResponse | ||
|
||
return LazyRunMetadataResponse( | ||
_lazy_load_model_version=self._lazy_load_model_version, | ||
_lazy_load_artifact_name=self._lazy_load_artifact_name, | ||
_lazy_load_artifact_version=self._lazy_load_artifact_version, | ||
_lazy_load_metadata_name=key, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) ZenML GmbH 2024. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
# or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
"""Model Version Data Lazy Loader definition.""" | ||
|
||
from typing import Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
from zenml.model.model_version import ModelVersion | ||
|
||
|
||
class ModelVersionDataLazyLoader(BaseModel): | ||
"""Model Version Data Lazy Loader helper class. | ||
It helps the inner codes to fetch proper artifact, | ||
model version metadata or artifact metadata from the | ||
model version during runtime time of the step. | ||
""" | ||
|
||
model_version: ModelVersion | ||
artifact_name: Optional[str] = None | ||
artifact_version: Optional[str] = None | ||
metadata_name: Optional[str] = None |
Oops, something went wrong.