Cache previous executions
Iterating quickly with ZenML through caching.
Developing machine learning pipelines is iterative in nature. ZenML speeds up development in this work with step caching.
In the logs of your previous runs, you might have noticed at this point that rerunning the pipeline a second time will use caching on the first step:
![](https://docs.zenml.io/~gitbook/image?url=https%3A%2F%2F3887786028-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252Fk4Kqsa0Fq0LRbACpSene%252Fuploads%252Fgit-blob-f142985e4c1b0a147f9956e89667c578ecc4e9e4%252FCachedDag.png%3Falt%3Dmedia&width=768&dpr=4&quality=100&sign=4a24dfda&sv=1)
ZenML understands that nothing has changed between subsequent runs, so it re-uses the output of the previous run (the outputs are persisted in the artifact store). This behavior is known as caching.
In ZenML, caching is enabled by default. Since ZenML automatically tracks and versions all inputs, outputs, and parameters of steps and pipelines, steps will not be re-executed within the same pipeline on subsequent pipeline runs as long as there is no change in the inputs, parameters, or code of a step.
The caching does not automatically detect changes within the file system or on external APIs. Make sure to manually set caching to False
on steps that depend on external inputs, file-system changes, or if the step should run regardless of caching.
Configuring the caching behavior of your pipelines
With caching as the default behavior, there will be times when you need to disable it.
There are levels at which you can take control of when and where caching is used.
Caching at the pipeline level
On a pipeline level, the caching policy can be set as a parameter within the @pipeline
decorator as shown below:
The setting above will disable caching for all steps in the pipeline unless a step explicitly sets enable_cache=True
( see below).
When writing your pipelines, be explicit. This makes it clear when looking at the code if caching is enabled or disabled for any given pipeline.
Dynamically configuring caching for a pipeline run
Sometimes you want to have control over caching at runtime instead of defaulting to the hard-coded pipeline and step decorator settings. ZenML offers a way to override all caching settings at runtime:
The code above disables caching for all steps of your pipeline, no matter what you have configured in the @step
or @pipeline
decorators.
The with_options
function allows you to configure all sorts of things this way. We will learn more about it in the coming chapters!
Caching at a step-level
Caching can also be explicitly configured at a step level via a parameter of the @step
decorator:
The code above turns caching off for this step only.
You can also use with_options
with the step, just as in the pipeline:
Code Example
This section combines all the code from this section into one simple script that you can use to see caching easily:
![ZenML Scarf](https://docs.zenml.io/~gitbook/image?url=https%3A%2F%2Fstatic.scarf.sh%2Fa.png%3Fx-pxid%3Df0b4f458-0a54-4fcd-aa95-d5ee424815bc&width=768&dpr=4&quality=100&sign=55709a31&sv=1)
Last updated