-
Notifications
You must be signed in to change notification settings - Fork 559
Follow-up on the run_metadata changes
#3193
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
Merged
Merged
Changes from 146 commits
Commits
Show all changes
162 commits
Select commit
Hold shift + click to select a range
697a93f
Initial commit, nuking all metadata responses and seeing what breaks
AlexejPenner 733a6c8
Removed last remnant of LazyLoader
AlexejPenner 3ce54ef
Merge branch 'develop' into feature/better-metadata
AlexejPenner ae71757
Reintroducing the lazy loaders.
AlexejPenner 01b5179
Merge branch 'feature/better-metadata' of github.com:zenml-io/zenml i…
AlexejPenner 7d0ff82
Add LazyRunMetadataResponse to EntrypointFunctionDefinition
avishniakov d7a9f83
Test for lazy loaders works now
AlexejPenner bccb4d2
Merge branch 'develop' into feature/better-metadata
AlexejPenner 9a0e0b2
Fixed tests, reformatted
AlexejPenner 145b90b
Use updated template
AlexejPenner 1e1991a
Auto-update of Starter template
actions-user adab934
Merge branch 'develop' into feature/better-metadata
AlexejPenner d83628a
Updated more templates
AlexejPenner 6d13071
Merge branch 'feature/better-metadata' of github.com:zenml-io/zenml i…
AlexejPenner c4febf3
Fixed failing test
AlexejPenner 5aef8ab
Fixed step run schemas
AlexejPenner 0b66f07
Auto-update of E2E template
actions-user 4b2434a
Auto-update of NLP template
actions-user 8f4af6e
Fixed tests, removed additional .value access
AlexejPenner cc6902b
Merge branch 'feature/better-metadata' of github.com:zenml-io/zenml i…
AlexejPenner edba625
Further fixing
AlexejPenner 7d5cfb7
Merge branch 'develop' into feature/better-metadata
AlexejPenner c2b6955
Fixed linting issues
AlexejPenner e2bd53a
Merge branch 'develop' into feature/better-metadata
AlexejPenner a582836
Merge branch 'feature/better-metadata' of github.com:zenml-io/zenml i…
AlexejPenner 4f82ade
Merge branch 'develop' into feature/better-metadata
AlexejPenner 58293bb
Merge branch 'feature/better-metadata' of github.com:zenml-io/zenml i…
AlexejPenner 8f6d305
Reformatted
AlexejPenner 6b18322
Linted, formatted and tested again
AlexejPenner 8b3a1bd
Typing
AlexejPenner b34f18b
Merge branch 'develop' into feature/better-metadata
AlexejPenner 5cc7b44
Maybe fix everything
schustmi c368dec
Apply some feedback
schustmi 62e8d6e
merged develop
bcdurak 050f5b5
resolved conflicts
bcdurak 74c1a42
new operation
bcdurak 53dc8e8
new log_metadata function
bcdurak 68a455c
changes to the base filters
bcdurak 4af4165
new filters
bcdurak fdf8945
adding log_metadata to __all__
bcdurak 39f5bf8
checkpoint with float casting
bcdurak 1c051ec
adding tests
bcdurak e284808
final touches and formatting
bcdurak d5bbf72
formatting
bcdurak 3a0d4c8
moved the utils
bcdurak 5b3b217
modified log metadata function
bcdurak 3d5a9f0
checkpoint
bcdurak e3079a3
deprecating the old functions
bcdurak c3e69c2
linting and final fixes
bcdurak 2d4c723
better error message
bcdurak 206340c
merged develop
bcdurak 2debd9e
merged develop
bcdurak 7e20409
merged develop
bcdurak fbd0200
fixing the client method
bcdurak ec7dc02
better error message
bcdurak 1fafb7e
consistent creation\
bcdurak ad4a4f7
merged develop
bcdurak d90f55d
adjusting tests
bcdurak e0db418
linting
bcdurak 14dfdea
changes for step metadata
bcdurak d89358d
more test adjustments
bcdurak 7d90305
testing unit tests
bcdurak b060987
linting
bcdurak 43a7034
fixing more tests
bcdurak 28ecdc1
fixing more tests
bcdurak e0c5e4f
more test fixes
bcdurak 6edc16e
fixing the test
bcdurak 030d530
fixing per comments
bcdurak 929fba4
added validation, constant error message
bcdurak be79553
merged develop
bcdurak e07b777
Merge branch 'develop' into feature/best-metadata
bcdurak c1bcb00
linting
bcdurak 57ba4f9
new changes
bcdurak a68f3c2
second checkpoint
bcdurak 0b5eb12
fixes and merged develop
bcdurak 64fd8b8
Merge branch 'develop' into feature/followup-run-metadata
bcdurak 07ece0c
fixing revisions
bcdurak 4b6f84a
adding overlap to remove warnings
bcdurak dca5913
complete docs changes
bcdurak b767269
adding a parameter to control the related entity behaviour
bcdurak 3b1ee3a
fixing the toc
bcdurak 6f2e224
fixed the description
bcdurak bb21a07
docstring
bcdurak 791ddc0
spellcheck
bcdurak bf771f7
metadata creation during artifact version creation
bcdurak 9ceedde
allowing artifact metadata with name for external artifact
bcdurak 52fdba4
update the template versions
bcdurak 1855edf
Auto-update of LLM Finetuning template
actions-user a2462b5
Auto-update of Starter template
actions-user 4283966
Auto-update of E2E template
actions-user a915e62
Auto-update of NLP template
actions-user f679fea
fixing the migration script
bcdurak 64b0a0b
formatting
bcdurak 3969ede
merged template changes
bcdurak 6fef781
merged develop
bcdurak df0fbda
redirects
bcdurak 324e67f
minor fixes
bcdurak 20f4e38
Merge branch 'develop' into feature/followup-run-metadata
bcdurak f966b0f
working pipelines again
bcdurak 18e5f1e
small fix
bcdurak 060ec23
merged develop
bcdurak 45fa324
merged develop
bcdurak 5832f80
merged develop
bcdurak 05f8ab5
working checkpoint
bcdurak 8a353b8
fixes, linting, docstrings
bcdurak af009b0
fixing unit tests
bcdurak fac74c9
docs updates 1
bcdurak 4370bdc
docs update 2
bcdurak 6b06a90
fixing integration tests
bcdurak 59d9867
spellcheck
bcdurak e482c61
formatting
bcdurak ffc5787
Auto-update of E2E template
actions-user dd69dd7
docs changes
bcdurak eab5ba5
review comments
bcdurak 424dc57
merged develop
bcdurak 4ea0740
Merge branch 'develop' into feature/followup-run-metadata
bcdurak 81e5920
added the batch rbac call
bcdurak bd53796
merged develop and resolved conflicts
bcdurak 0f785ff
added a validator to check the name of the keys
bcdurak 0988141
small adjustments
bcdurak cc297f2
base schema added
bcdurak b411aca
merge develop
bcdurak 4512ac7
formatting
bcdurak 5824195
Merge branch 'develop' into feature/followup-run-metadata
bcdurak ff695c4
new functionalities
bcdurak 5e34213
breaking circular imports
bcdurak be6ea07
spellchecker
bcdurak ee68112
other minor fixes
bcdurak 1b8a6f1
covering the uncovered case
bcdurak f343acd
adjusting tests
bcdurak a36ab49
fixing the quickstart again
bcdurak 77b2310
minor change
bcdurak 94c26fd
going back to publisher step id
bcdurak aabb2ba
updating github refs
bcdurak dc1df13
Auto-update of LLM Finetuning template
actions-user 0a7e26a
Auto-update of Starter template
actions-user d6de5cf
fixing tests
bcdurak e04b03b
merged develop
bcdurak 2a5feb2
updated docs
bcdurak 94bb86a
Auto-update of E2E template
actions-user 4997e3a
Auto-update of NLP template
actions-user 2953f06
formatting
bcdurak 759b98c
merge develop
bcdurak 88e247c
review comments
bcdurak 4cd155a
merged develop
bcdurak 755c36f
adding some tests in
bcdurak c1b5a4c
review comments
bcdurak 93dccd8
Update src/zenml/zen_stores/migrations/versions/cc269488e5a9_separate…
bcdurak 6bc0002
Update src/zenml/zen_stores/migrations/versions/cc269488e5a9_separate…
bcdurak 852d99d
Update src/zenml/zen_stores/migrations/versions/cc269488e5a9_separate…
bcdurak e142836
Update src/zenml/zen_stores/migrations/versions/cc269488e5a9_separate…
bcdurak ded49db
Update src/zenml/zen_stores/migrations/versions/cc269488e5a9_separate…
bcdurak bedb364
changed assert to value error
bcdurak 6cdc3a7
merged develop
bcdurak dcc8aa9
fixed the alembic head
bcdurak 772f639
changed the interaction with the models
bcdurak d13a909
trimmed down
bcdurak 169b4c6
small bugfix
bcdurak ba131c0
naming recommendations
bcdurak e05fb98
linting
bcdurak d662ac3
fixing the test
bcdurak ac18b53
Merge branch 'develop' into feature/followup-run-metadata
bcdurak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
71 changes: 51 additions & 20 deletions
71
...o/model-management-metrics/track-metrics-metadata/attach-metadata-to-a-model.md
This file contains hidden or 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 |
|---|---|---|
| @@ -1,62 +1,93 @@ | ||
| --- | ||
| description: >- | ||
| Attach any metadata as key-value pairs to your models for future reference and | ||
| auditability. | ||
| description: Learn how to attach metadata to a model. | ||
| --- | ||
|
|
||
| # Attach metadata to a model | ||
avishniakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ZenML allows you to log metadata for models, which provides additional context | ||
| that goes beyond individual artifact details. Model metadata can represent | ||
| high-level insights, such as evaluation results, deployment information, | ||
| or customer-specific details, making it easier to manage and interpret | ||
| the model's usage and performance across different versions. | ||
|
|
||
| ## Logging Metadata for Models | ||
|
|
||
| While artifact metadata is specific to individual outputs of steps, model metadata encapsulates broader and more general information that spans across multiple artifacts. For example, evaluation results or the name of a customer for whom the model is intended could be logged with the model. | ||
| To log metadata for a model, use the `log_metadata` function. This function | ||
| lets you attach key-value metadata to a model, which can include metrics and | ||
| other JSON-serializable values, such as custom ZenML types like `Uri`, | ||
| `Path`, and `StorageSize`. | ||
|
|
||
| Here's an example of logging metadata for a model: | ||
|
|
||
| ```python | ||
| from zenml import step, log_model_metadata, ArtifactConfig, get_step_context | ||
| from typing import Annotated | ||
|
|
||
| import pandas as pd | ||
| from sklearn.ensemble import RandomForestClassifier | ||
| from sklearn.base import ClassifierMixin | ||
| from sklearn.ensemble import RandomForestClassifier | ||
|
|
||
| from zenml import step, log_metadata, ArtifactConfig, get_step_context | ||
|
|
||
|
|
||
| @step | ||
| def train_model(dataset: pd.DataFrame) -> Annotated[ClassifierMixin, ArtifactConfig(name="sklearn_classifier")]: | ||
| """Train a model""" | ||
| # Fit the model and compute metrics | ||
| def train_model(dataset: pd.DataFrame) -> Annotated[ | ||
| ClassifierMixin, ArtifactConfig(name="sklearn_classifier") | ||
| ]: | ||
| """Train a model and log model metadata.""" | ||
| classifier = RandomForestClassifier().fit(dataset) | ||
| accuracy, precision, recall = ... | ||
|
|
||
| # Log metadata for the model | ||
| # This associates the metadata with the ZenML model, not the artifact | ||
| log_model_metadata( | ||
|
|
||
| log_metadata( | ||
| metadata={ | ||
| "evaluation_metrics": { | ||
| "accuracy": accuracy, | ||
| "precision": precision, | ||
| "recall": recall | ||
| } | ||
| }, | ||
| # Omitted model_name will use the model in the current context | ||
| model_name="zenml_model_name", | ||
| # Omitted model_version will default to 'latest' | ||
| model_version="zenml_model_version", | ||
| infer_model=True, | ||
| ) | ||
|
|
||
| return classifier | ||
| ``` | ||
|
|
||
| In this example, the metadata is associated with the model rather than the specific classifier artifact. This is particularly useful when the metadata reflects an aggregation or summary of various steps and artifacts in the pipeline. | ||
| In this example, the metadata is associated with the model rather than the | ||
| specific classifier artifact. This is particularly useful when the metadata | ||
| reflects an aggregation or summary of various steps and artifacts in the | ||
| pipeline. | ||
|
|
||
|
|
||
| ### Selecting Models with `log_metadata` | ||
|
|
||
| When using `log_metadata`, ZenML provides flexible options of attaching | ||
| metadata to model versions: | ||
|
|
||
| 1. **Using `infer_model`**: If used within a step, ZenML will use the step | ||
| context to infer the model it is using and attach the metadata to it. | ||
| 2. **Model Name and Version Provided**: If both a model name and version are | ||
| provided, ZenML will use these to identify and attach metadata to the | ||
| specific model version. | ||
| 3. **Model Version ID Provided**: If a model version ID is directly provided, | ||
| ZenML will use it to fetch and attach the metadata to that specific model | ||
| version. | ||
|
|
||
| ## Fetching logged metadata | ||
|
|
||
| Once metadata has been logged in an [artifact](attach-metadata-to-an-artifact.md), model, or [step](attach-metadata-to-steps.md), we can easily fetch the metadata with the ZenML Client: | ||
| Once metadata has been attached to a model, it can be retrieved for inspection | ||
| or analysis using the ZenML Client. | ||
|
|
||
| ```python | ||
| from zenml.client import Client | ||
|
|
||
| client = Client() | ||
| model = client.get_model_version("my_model", "my_version") | ||
|
|
||
| print(model.run_metadata["metadata_key"].value) | ||
| print(model.run_metadata["metadata_key"]) | ||
| ``` | ||
|
|
||
| {% hint style="info" %} | ||
| When you are fetching metadata using a specific key, the returned value will | ||
| always reflect the latest entry. | ||
| {% endhint %} | ||
hyperlint-ai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| <figure><img src="https://static.scarf.sh/a.png?x-pxid=f0b4f458-0a54-4fcd-aa95-d5ee424815bc" alt="ZenML Scarf"><figcaption></figcaption></figure> | ||
87 changes: 87 additions & 0 deletions
87
...-to/model-management-metrics/track-metrics-metadata/attach-metadata-to-a-run.md
This file contains hidden or 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,87 @@ | ||
| --- | ||
| description: Learn how to attach metadata to a run. | ||
| --- | ||
|
|
||
| # Attach Metadata to a Run | ||
|
|
||
| In ZenML, you can log metadata directly to a pipeline run, either during or | ||
| after execution, using the `log_metadata` function. This function allows you | ||
| to attach a dictionary of key-value pairs as metadata to a pipeline run, | ||
| with values that can be any JSON-serializable data type, including ZenML | ||
| custom types like `Uri`, `Path`, `DType`, and `StorageSize`. | ||
|
|
||
| ## Logging Metadata Within a Run | ||
|
|
||
| If you are logging metadata from within a step that’s part of a pipeline run, | ||
| calling `log_metadata` will attach the specified metadata to the current | ||
| pipeline run where the metadata key will have the `step_name::metadata_key` | ||
| pattern. This allows you to use the same metadata key from different steps | ||
| while the run's still executing. | ||
|
|
||
| ```python | ||
| from typing import Annotated | ||
|
|
||
| import pandas as pd | ||
| from sklearn.base import ClassifierMixin | ||
| from sklearn.ensemble import RandomForestClassifier | ||
|
|
||
| from zenml import step, log_metadata, ArtifactConfig | ||
|
|
||
|
|
||
| @step | ||
| def train_model(dataset: pd.DataFrame) -> Annotated[ | ||
| ClassifierMixin, | ||
| ArtifactConfig(name="sklearn_classifier", is_model_artifact=True) | ||
| ]: | ||
| """Train a model and log run-level metadata.""" | ||
| classifier = RandomForestClassifier().fit(dataset) | ||
| accuracy, precision, recall = ... | ||
|
|
||
| # Log metadata at the run level | ||
| log_metadata( | ||
| metadata={ | ||
| "run_metrics": { | ||
| "accuracy": accuracy, | ||
| "precision": precision, | ||
| "recall": recall | ||
| } | ||
| } | ||
| ) | ||
| return classifier | ||
| ``` | ||
|
|
||
| ## Manually Logging Metadata to a Pipeline Run | ||
|
|
||
| You can also attach metadata to a specific pipeline run without needing a step, | ||
| using identifiers like the run ID. This is useful when logging information or | ||
| metrics that were calculated post-execution. | ||
|
|
||
| ```python | ||
| from zenml import log_metadata | ||
|
|
||
| log_metadata( | ||
| metadata={"post_run_info": {"some_metric": 5.0}}, | ||
| run_id_name_or_prefix="run_id_name_or_prefix" | ||
| ) | ||
| ``` | ||
|
|
||
| ## Fetching Logged Metadata | ||
|
|
||
| Once metadata has been logged in a pipeline run, you can retrieve it using | ||
| the ZenML Client: | ||
|
|
||
| ```python | ||
| from zenml.client import Client | ||
|
|
||
| client = Client() | ||
| run = client.get_pipeline_run("run_id_name_or_prefix") | ||
|
|
||
| print(run.run_metadata["metadata_key"]) | ||
| ``` | ||
|
|
||
| {% hint style="info" %} | ||
| When you are fetching metadata using a specific key, the returned value will | ||
| always reflect the latest entry. | ||
| {% endhint %} | ||
|
|
||
| <figure><img src="https://static.scarf.sh/a.png?x-pxid=f0b4f458-0a54-4fcd-aa95-d5ee424815bc" alt="ZenML Scarf"><figcaption></figcaption></figure> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.