Configuration
Configuring and customizing your pipeline runs.
ZenML provides several approaches to configure your pipelines and steps:
Understanding .configure() vs .with_options()
ZenML provides two primary methods to configure pipelines and steps: .configure() and .with_options(). While they accept the same parameters, they behave differently:
.configure(): Modifies the configuration in-place and returns the same object..with_options(): Creates a new copy with the applied configuration, leaving the original unchanged.
When to use each:
Use
.with_options()in most cases, especially inside pipeline definitions:@pipeline def my_pipeline(): # This creates a new configuration just for this instance my_step.with_options(parameters={"param": "value"})()Use
.configure()only when you intentionally want to modify a step globally, and are aware that the change will affect all subsequent invocations of that step.
Approaches to Configuration
Pipeline Configuration with configure
You can configure various aspects of a pipeline using the configure method:
from zenml import pipeline
# Assuming MyPipeline is your pipeline function
# @pipeline
# def MyPipeline():
# ...
# Create a pipeline
my_pipeline = MyPipeline()
# Configure the pipeline
my_pipeline.configure(
enable_cache=False,
enable_artifact_metadata=True,
settings={
"docker": {
"parent_image": "zenml-io/zenml-cuda:latest"
}
}
)
# Run the pipeline
my_pipeline()Runtime Configuration with with_options
You can configure a pipeline at runtime using the with_options method:
Step-Level Configuration
You can configure individual steps with the @step decorator:
Direct Component Assignment
If you have an experiment tracker or step operator in your active stack, you can enable them for specific steps like this:
If you want to make sure a step can only run with a specific experiment tracker/step operator, you can also specify the component names like this:
You can combine both approaches with settings to configure the specific behavior of those components:
This approach allows you to use different components for different steps in your pipeline while also customizing their runtime behavior.
Types of Settings
Settings in ZenML are categorized into three main types:
General settings that can be used on all ZenML pipelines:
DockerSettingsfor container configurationResourceSettingsfor CPU, memory, and GPU allocation (on ZenML Pro, the same fields drive resource pools for workspace quotas, queuing, and preemption)DeploymentSettingsfor pipeline deployment configuration - can only be set at the pipeline level
Stack-component-specific settings for configuring behaviors of components in your stack:
These use the pattern
<COMPONENT_CATEGORY>,<COMPONENT_CATEGORY>.<COMPONENT_FLAVOR>, or<COMPONENT_CATEGORY>:<COMPONENT_NAME>as keysUse
<COMPONENT_CATEGORY>to target the default attached component of that typeUse
.to select by flavor:<COMPONENT_CATEGORY>.<COMPONENT_FLAVOR>only works if exactly one attached component of that flavor exists in the stackUse
:to select an exact named instance:<COMPONENT_CATEGORY>:<COMPONENT_NAME>targets a specific attached component by nameExamples include
experiment_tracker,experiment_tracker.wandb, orstep_operator:vertex
Configuration Hierarchy
There are a few general rules when it comes to settings and configurations that are applied in multiple places. Generally the following is true:
Configurations in code override configurations made inside of the yaml file
Configurations at the step level override those made at the pipeline level
In case of attributes the dictionaries are merged
Common Setting Types
Resource Settings
Resource settings allow you to specify the CPU, memory, and GPU requirements for your steps.
On ZenML Pro, those declarations are also what the resource pool feature uses: for eligible dynamic pipelines, the server builds resource requests from your merged ResourceSettings (including pool_resources and preemptible), matches them against workspace pools and policies on your stack’s orchestrator or step operator, and may queue or preempt work accordingly. For more information on how this feature works, see ZenML Pro Resource Pools.
When both pipeline and step resource settings are specified, they are merged with step settings taking precedence:
Resource settings also allow you to configure scaling options - including minimum and maximum number of instances, and scaling policy - for your pipeline deployments, when used at the pipeline level:
Docker Settings
Docker settings allow you to customize the containerization process:
For more detailed information on containerization options, see the containerization guide.
Deployment Settings
Deployment settings allow you to customize the web server and ASGI application used to run your pipeline deployments. You can specify a range of options, including custom endpoints, middleware, extensions and even custom files used to serve an entire single-page application alongside your pipeline:
For more detailed information on deployment options, see the pipeline deployment guide, particularly the deployment settings section.
Stack Component Configuration
Registration-time vs Runtime Stack Component Settings
Stack components have two types of configuration:
Registration-time configuration: Static settings defined when registering a component
Runtime settings: Dynamic settings that can change between pipeline runs
Even for runtime settings, you can set default values during registration:
Using the Right Key for Stack Component Settings
When specifying stack-component-specific settings, the key follows this pattern:
If you specify just the category (e.g., step_operator), ZenML applies these settings to whatever flavor of component is in your stack. If the settings don't apply to that flavor, they are ignored.
Making Configurations Flexible with Environment Variables
You can make your configurations more flexible by referencing environment variables using the placeholder syntax ${ENV_VARIABLE_NAME}:
In code:
In configuration files:
This allows you to easily adapt your pipelines to different environments without changing code.
Using External Configuration Tools (Hydra)
For more advanced configuration management, you can use tools like Hydra to manage your pipeline parameters through composable YAML configs and CLI overrides, then pass the resolved values into ZenML.
The key idea: Hydra decides what to run (hyperparameters, model settings, data config) while ZenML decides where and when (orchestration, caching, artifact versioning). Neither needs to know about the other's internals.
For a complete working example, see the Hydra + ZenML configuration management example.
Autogenerate a template yaml file
If you want to generate a template yaml file of your specific pipeline, you can do so by using the .write_run_configuration_template() method. This will generate a yaml file with all options commented out. This way you can pick and choose the settings that are relevant to you.
Last updated
Was this helpful?