Load a Model in code

There are a few different ways to load a ZenML Model in code:

Load the active model in a pipeline

You can also use the active model to get the model metadata, or the associated artifacts directly as described in the starter guide:

from zenml import step, pipeline, get_step_context, pipeline, Model

def my_pipeline():

def my_step():
    # Get model from active step context
    mv = get_step_context().model

    # Get metadata

    # Directly fetch an artifact that is attached to the model
    output = mv.get_artifact("my_dataset", "my_version")

Load any model via the Client

Alternatively, you can use the Client:

from zenml import step
from zenml.client import Client
from zenml.enums import ModelStages

def model_evaluator_step()
    # Get staging model version 
        staging_zenml_model = Client().get_model_version(
    except KeyError:
        staging_zenml_model = None
ZenML Scarf

Last updated