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

Add an environment variable and CLI option to enable/disable default caching #11142

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions sdk/python/kfp/cli/compile_.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,34 @@ def parse_parameters(parameters: Optional[str]) -> Dict:
is_flag=True,
default=False,
help='Whether to disable type checking.')
@click.option(
'--execution-caching-enabled-by-default',
type=click.Choice(['enabled', 'disabled'], case_sensitive=False),
default=None,
help='Enable task-level caching. Enabled by default, set it to disabled to disable caching.'
)
def compile_(
py: str,
output: str,
function_name: Optional[str] = None,
pipeline_parameters: Optional[str] = None,
disable_type_check: bool = False,
execution_caching_enabled_by_default: Optional[bool] = None,
) -> None:
"""Compiles a pipeline or component written in a .py file."""

env_enable_caching = os.getenv('KFP_EXECUTION_CACHING_ENABLED_BY_DEFAULT',
'enabled').lower() == 'enabled'
if execution_caching_enabled_by_default is None:
execution_caching_enabled_by_default = env_enable_caching
else:
execution_caching_enabled_by_default = execution_caching_enabled_by_default.lower(
) == 'enabled'
if execution_caching_enabled_by_default:
os.environ['KFP_EXECUTION_CACHING_ENABLED_BY_DEFAULT'] = 'enabled'
else:
os.environ['KFP_EXECUTION_CACHING_ENABLED_BY_DEFAULT'] = 'disabled'

pipeline_func = collect_pipeline_or_component_func(
python_file=py, function_name=function_name)
parsed_parameters = parse_parameters(parameters=pipeline_parameters)
Expand Down
4 changes: 3 additions & 1 deletion sdk/python/kfp/dsl/pipeline_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import functools
import inspect
import itertools
import os
import re
from typing import Any, Dict, List, Mapping, Optional, Union
import warnings
Expand Down Expand Up @@ -130,7 +131,8 @@ def __init__(
inputs=dict(args.items()),
dependent_tasks=[],
component_ref=component_spec.name,
enable_caching=True)
enable_caching=os.getenv('KFP_EXECUTION_CACHING_ENABLED_BY_DEFAULT',
'enabled').lower() == 'enabled')
self._run_after: List[str] = []

self.importer_spec = None
Expand Down
4 changes: 3 additions & 1 deletion sdk/python/kfp/dsl/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import collections
import dataclasses
import itertools
import os
import re
from typing import Any, Dict, List, Mapping, Optional, Tuple, Union
import uuid
Expand Down Expand Up @@ -420,7 +421,8 @@ class TaskSpec:
trigger_strategy: Optional[str] = None
iterator_items: Optional[Any] = None
iterator_item_input: Optional[str] = None
enable_caching: bool = True
enable_caching: bool = os.getenv('KFP_EXECUTION_CACHING_ENABLED_BY_DEFAULT',
'enabled').lower() == 'enabled'
display_name: Optional[str] = None
retry_policy: Optional[RetryPolicy] = None

Expand Down
Loading