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

ModelConfig is ModelVersion! #2044

Merged
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
4a77b19
rename file
avishniakov Nov 10, 2023
70a9b97
rename file
avishniakov Nov 10, 2023
5518513
rename file
avishniakov Nov 10, 2023
5252b58
Merge branch 'develop' into feature/OSS-2609-model-config-is-model-ve…
avishniakov Nov 10, 2023
7cd672c
big rebranding
avishniakov Nov 10, 2023
26e0b3a
big rebranding
avishniakov Nov 10, 2023
ed5bb8f
deprecate method
avishniakov Nov 10, 2023
8aafc95
redesign context to return ModelVersion
avishniakov Nov 10, 2023
0ff4b21
add `linked_artifact_ids` property
avishniakov Nov 10, 2023
0138546
add `__eq__`
avishniakov Nov 10, 2023
c924456
fix typo
avishniakov Nov 10, 2023
e62100b
add number and name props
avishniakov Nov 13, 2023
3b4f1d5
rename artifact types
avishniakov Nov 13, 2023
f53dc24
prevent reserved mv names creation
avishniakov Nov 13, 2023
77f1155
typo
avishniakov Nov 13, 2023
ef25311
more logging
avishniakov Nov 13, 2023
3a13ccd
prevent reserved mv names creation
avishniakov Nov 13, 2023
1a23383
handle reserved names properly
avishniakov Nov 13, 2023
a4ae3c8
rework client calls
avishniakov Nov 13, 2023
052c3b8
remove `version_description`
avishniakov Nov 13, 2023
5490aa9
remove `version_name`
avishniakov Nov 13, 2023
5dd7c81
`delete_new_version_on_failure` > `with_recovery`
avishniakov Nov 13, 2023
cd211aa
Merge branch 'develop' into feature/OSS-2609-OSS-2575-model-config-is…
avishniakov Nov 13, 2023
18ac906
fix alembic false alarms
avishniakov Nov 13, 2023
ccd70ca
Merge branch 'feature/OSS-2609-OSS-2575-model-config-is-model-version…
avishniakov Nov 13, 2023
c477414
output alembic branches
avishniakov Nov 13, 2023
245df6e
resolve branching
avishniakov Nov 13, 2023
f2374a7
update test signature
avishniakov Nov 13, 2023
5d2f115
Temporarily fix quickstart until the certificate is renewed
stefannica Nov 13, 2023
2cda9ce
add existing_type
avishniakov Nov 14, 2023
3c2178e
Merge branch 'develop' into feature/OSS-2609-OSS-2575-model-config-is…
avishniakov Nov 14, 2023
4bc517d
enforce tags update
avishniakov Nov 14, 2023
5618d2e
update template tag
avishniakov Nov 14, 2023
b37eb19
after merge mess
avishniakov Nov 14, 2023
b433135
resolve branching
avishniakov Nov 14, 2023
3a94629
finish renaming
avishniakov Nov 14, 2023
e198a56
revert `log_artifact_metadata`
avishniakov Nov 14, 2023
1419daa
tagging bugfix
avishniakov Nov 14, 2023
6c630e0
Merge branch 'develop' into feature/OSS-2609-OSS-2575-model-config-is…
avishniakov Nov 14, 2023
1526b01
rework client methods
avishniakov Nov 14, 2023
9497958
sunset recovery and `running`
avishniakov Nov 14, 2023
e0c1c27
nits from review
avishniakov Nov 14, 2023
cf295cc
rename files
avishniakov Nov 14, 2023
c1fe73d
rename vars
avishniakov Nov 14, 2023
f27a8ae
remove `ReservedNameError`
avishniakov Nov 14, 2023
18aea92
Merge branch 'develop' into feature/OSS-2609-OSS-2575-model-config-is…
avishniakov Nov 14, 2023
b688b93
resolve branching
avishniakov Nov 14, 2023
a921efe
Auto-update of E2E template
actions-user Nov 14, 2023
0cf2a6d
fixing bugs caught by tests
avishniakov Nov 15, 2023
4b07b33
Merge branch 'feature/OSS-2609-OSS-2575-model-config-is-model-version…
avishniakov Nov 15, 2023
3c05cc2
Merge branch 'develop' into feature/OSS-2609-OSS-2575-model-config-is…
avishniakov Nov 15, 2023
bb42c2c
fix branching
avishniakov Nov 15, 2023
9ad0778
properly refresh template
avishniakov Nov 15, 2023
a7f991c
overcome pagination issue in all_model_versions
avishniakov Nov 15, 2023
6f069b6
rename misleading method
avishniakov Nov 15, 2023
4185808
remove `all_model_versions`
avishniakov Nov 15, 2023
c526d44
update `list_models`
avishniakov Nov 15, 2023
5d5c9fc
improve docstring
avishniakov Nov 15, 2023
1ddb941
rephrase docstring
avishniakov Nov 15, 2023
a95c3ad
nits
avishniakov Nov 15, 2023
1e0249f
Auto-update of E2E template
actions-user Nov 15, 2023
ce5c34d
stick to unified list interface
avishniakov Nov 16, 2023
374ca2f
Merge branch 'feature/OSS-2609-OSS-2575-model-config-is-model-version…
avishniakov Nov 16, 2023
7f1642c
Feature/revamp model endpoints (#2035)
AlexejPenner Nov 16, 2023
d37b423
resolve mess after merge
avishniakov Nov 16, 2023
19cfbe9
Merge branch 'develop' into feature/OSS-2609-OSS-2575-model-config-is…
avishniakov Nov 16, 2023
886fc10
after merge clean-up
avishniakov Nov 16, 2023
6819991
update outdated tests
avishniakov Nov 16, 2023
72d7412
Merge branch 'develop' into feature/OSS-2609-OSS-2575-model-config-is…
avishniakov Nov 16, 2023
2fd2a36
Auto-update of E2E template
actions-user Nov 16, 2023
b518dcc
deep update of template
avishniakov Nov 17, 2023
7586b02
Revert "deep update of template"
avishniakov Nov 17, 2023
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
3 changes: 2 additions & 1 deletion .github/workflows/update-templates-to-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
python-version: ${{ inputs.python-version }}
stack-name: local
ref-zenml: ${{ github.ref }}
ref-template: '2023.11.01' # Make sure it is aligned with ZENML_PROJECT_TEMPLATES from src/zenml/cli/base.py
ref-template: '2023.11.14' # Make sure it is aligned with ZENML_PROJECT_TEMPLATES from src/zenml/cli/base.py

- name: Clean-up
run: |
Expand All @@ -76,6 +76,7 @@ jobs:

- name: Check-out fresh E2E template
run: |
rm -rf examples/e2e
mkdir -p examples/e2e
printf '[email protected]' | zenml init --path examples/e2e --template e2e_batch --template-with-defaults
bash scripts/format.sh
Expand Down
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.11.01
_commit: 2023.11.14
_src_path: gh:zenml-io/template-e2e-batch
data_quality_checks: true
email: ''
Expand Down
2 changes: 1 addition & 1 deletion examples/e2e/configs/deployer_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ steps:
notify_on_success: False

# configuration of the Model Control Plane
model_config:
model_version:
name: e2e_use_case
version: staging

Expand Down
2 changes: 1 addition & 1 deletion examples/e2e/configs/inference_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ steps:
notify_on_success: False

# configuration of the Model Control Plane
model_config:
model_version:
name: e2e_use_case
version: staging

Expand Down
3 changes: 1 addition & 2 deletions examples/e2e/configs/train_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ steps:
notify_on_success: False

# configuration of the Model Control Plane
model_config:
model_version:
name: e2e_use_case
license: apache
description: e2e_use_case E2E Batch Use Case
Expand All @@ -61,7 +61,6 @@ model_config:
- sklearn
- from template
- ZenML delivered
create_new_model_version: true

# pipeline level extra configurations
extra:
Expand Down
2 changes: 1 addition & 1 deletion examples/e2e/pipelines/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def e2e_use_case_training(
target=target,
)
after.append(step_name)
best_model = hp_tuning_select_best_model(after=after)
best_model = hp_tuning_select_best_model(step_names=after, after=after)

########## Training stage ##########
model = model_trainer(
Expand Down
13 changes: 7 additions & 6 deletions examples/e2e/steps/deployment/deployment_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from typing import Optional

from typing_extensions import Annotated
from utils import get_model_registry_version

from zenml import get_step_context, step
from zenml.client import Client
Expand All @@ -30,7 +29,7 @@
mlflow_model_registry_deployer_step,
)
from zenml.logger import get_logger
from zenml.model import DeploymentArtifactConfig
from zenml.model import EndpointArtifactConfig

logger = get_logger(__name__)

Expand All @@ -40,7 +39,7 @@ def deployment_deploy() -> (
Annotated[
Optional[MLFlowDeploymentService],
"mlflow_deployment",
DeploymentArtifactConfig(),
EndpointArtifactConfig(),
]
):
"""Predictions step.
Expand All @@ -63,12 +62,14 @@ def deployment_deploy() -> (
"""
### ADD YOUR OWN CODE HERE - THIS IS JUST AN EXAMPLE ###
if Client().active_stack.orchestrator.flavor == "local":
model_version = get_step_context().model_config._get_model_version()
model_version = get_step_context().model_version

# deploy predictor service
deployment_service = mlflow_model_registry_deployer_step.entrypoint(
registry_model_name=model_version.model.name,
registry_model_version=get_model_registry_version(model_version),
registry_model_name=model_version.name,
registry_model_version=model_version.get_model_artifact("model")
.metadata["model_registry_version"]
.value,
replace_existing=True,
)
else:
Expand Down
4 changes: 2 additions & 2 deletions examples/e2e/steps/etl/inference_data_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from typing_extensions import Annotated

from zenml import step
from zenml.model import ArtifactConfig
from zenml.model import DataArtifactConfig


@step
Expand All @@ -32,7 +32,7 @@ def inference_data_preprocessor(
) -> Annotated[
pd.DataFrame,
"dataset_inf",
ArtifactConfig(overwrite=False, artifact_name="inference_dataset"),
DataArtifactConfig(overwrite=False, artifact_name="inference_dataset"),
]:
"""Data preprocessor step.

Expand Down
26 changes: 15 additions & 11 deletions examples/e2e/steps/hp_tuning/hp_tuning_select_best_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#


from typing import List

from sklearn.base import ClassifierMixin
from typing_extensions import Annotated

Expand All @@ -26,7 +28,9 @@


@step
def hp_tuning_select_best_model() -> Annotated[ClassifierMixin, "best_model"]:
def hp_tuning_select_best_model(
step_names: List[str],
) -> Annotated[ClassifierMixin, "best_model"]:
"""Find best model across all HP tuning attempts.

This is an example of a model hyperparameter tuning step that loops
Expand All @@ -37,19 +41,19 @@ def hp_tuning_select_best_model() -> Annotated[ClassifierMixin, "best_model"]:
The best possible model class and its' parameters.
"""
### ADD YOUR OWN CODE HERE - THIS IS JUST AN EXAMPLE ###
model_version = get_step_context().model_config._get_model_version()
model_version = get_step_context().model_version

best_model = None
best_metric = -1
# consume artifacts attached to current model version in Model Control Plane
for full_artifact_name in model_version.artifact_object_ids:
# if artifacts comes from one of HP tuning steps
if full_artifact_name.endswith("hp_result"):
hp_output = model_version.artifacts[full_artifact_name]["1"]
model: ClassifierMixin = hp_output.load()
# fetch metadata we attached earlier
metric = float(hp_output.metadata["metric"].value)
if best_model is None or best_metric < metric:
best_model = model
for step_name in step_names:
hp_output = model_version.get_data_artifact(
step_name=step_name, name="hp_result"
)
model: ClassifierMixin = hp_output.load()
# fetch metadata we attached earlier
metric = float(hp_output.metadata["metric"].value)
if best_model is None or best_metric < metric:
best_model = model
### YOUR CODE ENDS HERE ###
return best_model
10 changes: 5 additions & 5 deletions examples/e2e/steps/inference/inference_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
MLFlowDeploymentService,
)
from zenml.logger import get_logger
from zenml.model import ArtifactConfig
from zenml.model import DataArtifactConfig

logger = get_logger(__name__)


@step
def inference_predict(
dataset_inf: pd.DataFrame,
) -> Annotated[pd.Series, "predictions", ArtifactConfig(overwrite=False)]:
) -> Annotated[pd.Series, "predictions", DataArtifactConfig(overwrite=False)]:
"""Predictions step.

This is an example of a predictions step that takes the data in and returns
Expand All @@ -54,12 +54,12 @@ def inference_predict(
The predictions as pandas series
"""
### ADD YOUR OWN CODE HERE - THIS IS JUST AN EXAMPLE ###
model_version = get_step_context().model_config._get_model_version()
model_version = get_step_context().model_version

# get predictor
predictor_service: Optional[
MLFlowDeploymentService
] = model_version.get_deployment("mlflow_deployment").load()
] = model_version.get_endpoint_artifact("mlflow_deployment").load()
if predictor_service is not None:
# run prediction from service
predictions = predictor_service.predict(request=dataset_inf)
Expand All @@ -69,7 +69,7 @@ def inference_predict(
"as the orchestrator is not local."
)
# run prediction from memory
predictor = model_version.get_model_object("model").load()
predictor = model_version.get_model_artifact("model").load()
predictions = predictor.predict(dataset_inf)

predictions = pd.Series(predictions, name="predicted")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import pandas as pd
from sklearn.metrics import accuracy_score
from typing_extensions import Annotated
from utils import get_model_versions

from zenml import step
from zenml import get_step_context, step
from zenml.logger import get_logger
from zenml.model import ModelVersion

logger = get_logger(__name__)

Expand Down Expand Up @@ -61,23 +61,33 @@ def compute_performance_metrics_on_current_data(
logger.info("Evaluating model metrics...")

# Get model version numbers from Model Control Plane
latest_version, current_version = get_model_versions(target_env)
latest_version = get_step_context().model_version
current_version = ModelVersion(
name=latest_version.name, version=target_env
)

# Get predictors
predictors = {
latest_version.number: latest_version.get_model_object("model").load(),
current_version.number: current_version.get_model_object(
"model"
).load(),
}
latest_version_number = latest_version.number
current_version_number = current_version.number

if current_version_number is None:
current_version_number = -1
metrics = {latest_version_number: 1.0, current_version_number: 0.0}
else:
# Get predictors
predictors = {
latest_version_number: latest_version.get_model_artifact(
"model"
).load(),
current_version_number: current_version.get_model_artifact(
"model"
).load(),
}

if latest_version != current_version:
metrics = {}
for version in [latest_version.number, current_version.number]:
for version in [latest_version_number, current_version_number]:
# predict and evaluate
predictions = predictors[version].predict(X)
metrics[version] = accuracy_score(y, predictions)
else:
metrics = {latest_version.number: 1.0, current_version.number: 0.0}

### YOUR CODE ENDS HERE ###
return metrics[latest_version.number], metrics[current_version.number]
return metrics[latest_version_number], metrics[current_version_number]
46 changes: 34 additions & 12 deletions examples/e2e/steps/promotion/promote_with_metric_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
# limitations under the License.
#

from utils import (
get_model_registry_version,
get_model_versions,
promote_in_model_registry,
)
from utils import promote_in_model_registry

from zenml import get_step_context, step
from zenml.logger import get_logger
from zenml.model import ModelVersion

logger = get_logger(__name__)

Expand Down Expand Up @@ -62,9 +59,14 @@ def promote_with_metric_compare(
should_promote = True

# Get model version numbers from Model Control Plane
latest_version, current_version = get_model_versions(target_env)
latest_version = get_step_context().model_version
current_version = ModelVersion(
name=latest_version.name, version=target_env
)

current_version_number = current_version.number

if latest_version.number == current_version.number:
if current_version_number is None:
logger.info("No current model version found - promoting latest")
else:
logger.info(
Expand All @@ -81,21 +83,41 @@ def promote_with_metric_compare(
)
should_promote = False

promoted_version = get_model_registry_version(current_version)
if should_promote:
# Promote in Model Control Plane
model_version = get_step_context().model_config._get_model_version()
model_version = get_step_context().model_version
model_version.set_stage(stage=target_env, force=True)
logger.info(f"Current model version was promoted to '{target_env}'.")

# Promote in Model Registry
latest_version_model_registry_number = (
latest_version.get_model_artifact("model")
.metadata["model_registry_version"]
.value
)
if current_version_number is None:
current_version_model_registry_number = (
latest_version_model_registry_number
)
else:
current_version_model_registry_number = (
current_version.get_model_artifact("model")
.metadata["model_registry_version"]
.value
)
promote_in_model_registry(
latest_version=get_model_registry_version(latest_version),
current_version=get_model_registry_version(current_version),
latest_version=latest_version_model_registry_number,
current_version=current_version_model_registry_number,
model_name=mlflow_model_name,
target_env=target_env.capitalize(),
)
promoted_version = get_model_registry_version(latest_version)
promoted_version = latest_version_model_registry_number
else:
promoted_version = (
current_version.get_model_artifact("model")
.metadata["model_registry_version"]
.value
)

logger.info(
f"Current model version in `{target_env}` is `{promoted_version}` registered in Model Registry"
Expand Down
1 change: 0 additions & 1 deletion examples/e2e/steps/training/model_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# limitations under the License.
#


import mlflow
import pandas as pd
from sklearn.base import ClassifierMixin
Expand Down
1 change: 0 additions & 1 deletion examples/e2e/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@


from .get_model_from_config import get_model_from_config
from .model_versions import get_model_versions, get_model_registry_version
from .promote_in_model_registry import promote_in_model_registry
Loading
Loading