In KFP v2, why does a weekly run's ingest step show as cached and reuse last week's articles, and which settings stop it at task, run or compile level?
answer
- on unless something turns it off
- same component, same inputs, outputs still there
- nothing in ingest's inputs changes
- set_caching_options on that one task
- enable_caching at submit, env var at compile
basics
~20 sKFP compiles every task with caching on, and an ingest step whose inputs never change matches last week's execution, so its old output is reused. Disable caching on that task with set_caching_options, or override it per run or at compile time.
solid answer
~40 sIn KFP v2 every task is compiled with caching enabled unless something turns it off. When the same component runs again with the same inputs and parameters, and the earlier outputs are still available, the backend reuses them and the UI marks the task as cached. An ingest step that queries 'the latest articles' has no input that changes from week to week, especially in a recurring run, whose parameter values are fixed. So it matches last week's execution. The narrowest fix is `ingest_task.set_caching_options(enable_caching=False)` on the step that reads mutable outside data. `enable_caching=False` on `create_run_from_pipeline_func` or `create_recurring_run` overrides every task in that run. Compiling with `--disable-execution-caching-by-default`, or with `KFP_DISABLE_EXECUTION_CACHING_BY_DEFAULT=true` set before the components are imported, flips the default for tasks that set nothing explicitly.
code
python · 9 linesfrom kfp import dsl
@dsl.pipeline(name='article-topics-weekly')
def article_topics(test_fraction: float = 0.2):
ingest_task = ingest_articles() # reads the live newsroom export
ingest_task.set_caching_options(enable_caching=False)
split_task = split_dataset(articles=ingest_task.outputs['articles'],
test_fraction=test_fraction)
train_classifier(train=split_task.outputs['train'])go deeper
Recall that KFP caches every task by default and that set_caching_options(enable_caching=False) turns it off for one task.
Explain when the backend reuses a step: same component, same inputs and parameters, earlier outputs still available, and the three places the setting can change.
Diagnose the silent stale run: a step whose real input is outside KFP, fixed recurring-run parameters, and pick the narrowest switch rather than disabling caching everywhere.
Set the team rule: which steps may cache, how external data snapshots become explicit inputs, and whether caching is opt-in or opt-out by default.
## The default: every task caches In Kubeflow Pipelines (KFP) v2 each task is compiled with **execution caching** enabled. The SDK fixes that default when it is imported. A task's `enable_caching` starts out true unless the environment variable `KFP_DISABLE_EXECUTION_CACHING_BY_DEFAULT` holds a truthy value (`1`, `true`, `t`, `yes`, `y`, `on`), or unless the CLI compile is given `--disable-execution-caching-by-default`. The resulting setting is written into the IR YAML as each task's caching options, and the backend acts on it. ## When the backend reuses a step The KFP docs state the rule plainly. A cached result is reused when: - the **same component** is executed again, - with the **same inputs and parameters**, - and the earlier **output is still available**. The backend then skips the execution and hands downstream tasks the earlier outputs, and the run graph marks the task with a green "arrow from cloud" icon. A `cache_key` set on the task or at submission replaces the key the backend would otherwise use, which changes what counts as "the same". ## Why the weekly ingest matched 1. `ingest_articles` queries the newsroom export for "the latest" articles. The data it reads lives outside KFP. 2. Its declared inputs are either empty or a parameter such as `week`. In a recurring run, parameter values are fixed when the recurring run is created, so `week` holds the same value every Monday. 3. The component definition has not changed since last week. 4. KFP therefore sees an identical execution, and the backend reuses last week's `Dataset` artifact. New articles exist, but nothing among the step's inputs says so. KFP is not misbehaving here. The step hides its real input, the state of an external system, from the only thing caching compares. ## Where caching can be switched | Level | Setting | Scope | |---|---|---| | Task | `task.set_caching_options(enable_caching=False)` | that one task | | Run | `enable_caching=False` on `create_run_from_pipeline_func`, `create_run_from_pipeline_package` or `create_recurring_run` | every task in that run; overrides the compile-time settings | | Compile default | `kfp dsl compile ... --disable-execution-caching-by-default`, or `KFP_DISABLE_EXECUTION_CACHING_BY_DEFAULT=true` | every task that sets nothing itself | ```bash KFP_DISABLE_EXECUTION_CACHING_BY_DEFAULT=true \ kfp dsl compile --py pipeline.py --output article_topics.yaml ``` The environment variable must be set **before** the KFP components are imported, because the default is read at import time. Exporting it halfway through a notebook session does nothing. The variable works for `Compiler().compile()` as well as for the CLI. ## How the switches interact The three levels stack in a fixed order, and it helps to trace one pipeline through them: 1. At compile time each task gets the default: on, unless the environment variable or the flag turned it off. 2. A `set_caching_options(...)` call on a task replaces that default for the task. 3. At submission, `enable_caching=True` or `False` on the client call, if given, replaces every task's setting for that run, including explicit per-task ones. The docs' own example re-enables caching for a task that had called `set_caching_options(False)`. 4. Leaving `enable_caching` unset on the client call keeps whatever was compiled. So a run-level `enable_caching=True`, perhaps added to make a development loop faster, silently undoes the per-task opt-out that protects the ingest step. Prefer leaving it unset in recurring runs. ## Choosing the narrowest fix - **Task-level off** for steps that read mutable external state: ingest, or a step that fetches the current production model's score. The rest of the graph keeps its caching. - **Run-level override** for a deliberate one-off rebuild of everything, without recompiling. - **Default off at compile** when a team wants caching to be opt-in, after which the deterministic steps opt back in with `set_caching_options(enable_caching=True)`. - Once ingest really executes again, it writes a fresh artifact, so the steps downstream receive different inputs and do not match last week's executions. ## What does not help - **A fixed parameter in a recurring run.** Its value is identical in every run, so it changes nothing about the match. - **Setting the environment variable after import.** The default has already been read by then. - **A constant `cache_key`.** The backend uses your string as the key, so a constant makes later runs match earlier ones more easily, which is the opposite of what the ingest step needs.
- What does a custom cache_key do?`set_caching_options(enable_caching=True, cache_key='...')`, or `cache_key=` at submission, makes the backend use your string as the task's cache key instead of one it derives. That helps when reuse should follow a version label you control. A constant key works against the ingest step, because every run then presents the same key.
- How do you confirm in the UI that a step was reused rather than executed?A task whose results came from the cache carries the green 'arrow from cloud' icon in the run graph. Its outputs are the earlier execution's artifacts rather than new ones written by this run, so their URIs point back to last week's run.
- KFP caching is off unless a task opts in
- Passing a fixed week parameter in a recurring run makes each run's ingest unique
- Exporting the caching environment variable after importing components still flips the default
- Run-level enable_caching only touches tasks that left caching unset
- A constant cache_key forces a fresh execution on every run
Assumes KFP SDK 2.17.0 and a 2.17 backend; the compile flag and KFP_DISABLE_EXECUTION_CACHING_BY_DEFAULT and the cache_key argument are KFP 2.x SDK features.