Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename log_model_version_metadata to log_model_metadata #2215

Merged
merged 4 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/zenml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
save_artifact,
load_artifact,
)
from zenml.model.utils import log_model_metadata
from zenml.artifacts.artifact_config import ArtifactConfig
from zenml.artifacts.external_artifact import ExternalArtifact
from zenml.model.model_version import ModelVersion
Expand All @@ -57,6 +58,7 @@
"get_step_context",
"load_artifact",
"log_artifact_metadata",
"log_model_metadata",
"ModelVersion",
"pipeline",
"save_artifact",
Expand Down
27 changes: 27 additions & 0 deletions src/zenml/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,33 @@ def log_model_version_metadata(

This function can be used to log metadata for existing model versions.

Args:
metadata: The metadata to log.
model_name: The name of the model to log metadata for. Can
be omitted when being called inside a step with configured
`model_version` in decorator.
model_version: The version of the model to log metadata for. Can
be omitted when being called inside a step with configured
`model_version` in decorator.
"""
logger.warning(
"`log_model_version_metadata` is deprecated. Please use "
"`log_model_metadata` instead."
)
log_model_metadata(
metadata=metadata, model_name=model_name, model_version=model_version
)


def log_model_metadata(
metadata: Dict[str, "MetadataType"],
model_name: Optional[str] = None,
model_version: Optional[Union[ModelStages, int, str]] = None,
) -> None:
"""Log model version metadata.

This function can be used to log metadata for existing model versions.

Args:
metadata: The metadata to log.
model_name: The name of the model to log metadata for. Can
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/functional/model/test_model_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from zenml.client import Client
from zenml.enums import ModelStages
from zenml.model.model_version import ModelVersion
from zenml.model.utils import log_model_version_metadata
from zenml.model.utils import log_model_metadata
from zenml.models import TagRequest

MODEL_NAME = "super_model"
Expand Down Expand Up @@ -64,7 +64,7 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
@step
def step_metadata_logging_functional():
"""Functional logging using implicit ModelVersion from context."""
log_model_version_metadata({"foo": "bar"})
log_model_metadata({"foo": "bar"})
assert get_step_context().model_version.metadata["foo"] == "bar"


Expand Down Expand Up @@ -357,17 +357,17 @@ def test_metadata_logging_functional(self, clean_client: "Client"):
)
mv._get_or_create_model_version()

log_model_version_metadata(
log_model_metadata(
{"foo": "bar"}, model_name=mv.name, model_version=mv.number
)

assert len(mv.metadata) == 1
assert mv.metadata["foo"] == "bar"

with pytest.raises(ValueError):
log_model_version_metadata({"foo": "bar"})
log_model_metadata({"foo": "bar"})

log_model_version_metadata(
log_model_metadata(
{"bar": "foo"}, model_name=mv.name, model_version="latest"
)

Expand Down
Loading