-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(sdk): add retry policy support to kfp v2 #7867
Changes from all commits
ef4c39c
4826ef6
aa35ecb
417426b
531a54a
942bd55
b337a73
97ccf8d
bd76c4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2022 The Kubeflow Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from kfp import compiler | ||
from kfp import dsl | ||
|
||
|
||
@dsl.component | ||
def add(a: float, b: float) -> float: | ||
return a + b | ||
|
||
|
||
@dsl.pipeline(name='test-pipeline') | ||
def my_pipeline(a: float = 1, b: float = 7): | ||
add_task = add(a=a, b=b) | ||
add_task.set_retry(num_retries=3) | ||
|
||
|
||
if __name__ == '__main__': | ||
compiler.Compiler().compile( | ||
pipeline_func=my_pipeline, | ||
package_path=__file__.replace('.py', '.yaml')) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
components: | ||
comp-add: | ||
executorLabel: exec-add | ||
inputDefinitions: | ||
parameters: | ||
a: | ||
parameterType: NUMBER_DOUBLE | ||
b: | ||
parameterType: NUMBER_DOUBLE | ||
outputDefinitions: | ||
parameters: | ||
Output: | ||
parameterType: NUMBER_DOUBLE | ||
deploymentSpec: | ||
executors: | ||
exec-add: | ||
container: | ||
args: | ||
- --executor_input | ||
- '{{$}}' | ||
- --function_to_execute | ||
- add | ||
command: | ||
- sh | ||
- -c | ||
- "\nif ! [ -x \"$(command -v pip)\" ]; then\n python3 -m ensurepip ||\ | ||
\ python3 -m ensurepip --user || apt-get install python3-pip\nfi\n\nPIP_DISABLE_PIP_VERSION_CHECK=1\ | ||
\ python3 -m pip install --quiet --no-warn-script-location 'kfp==2.0.0-alpha.5'\ | ||
\ && \"$0\" \"$@\"\n" | ||
- sh | ||
- -ec | ||
- 'program_path=$(mktemp -d) | ||
|
||
printf "%s" "$0" > "$program_path/ephemeral_component.py" | ||
|
||
python3 -m kfp.components.executor_main --component_module_path "$program_path/ephemeral_component.py" "$@" | ||
|
||
' | ||
- "\nimport kfp\nfrom kfp import dsl\nfrom kfp.dsl import *\nfrom typing import\ | ||
\ *\n\ndef add(a: float, b: float) -> float:\n return a + b\n\n" | ||
image: python:3.7 | ||
pipelineInfo: | ||
name: test-pipeline | ||
root: | ||
dag: | ||
tasks: | ||
add: | ||
cachingOptions: | ||
enableCache: true | ||
componentRef: | ||
name: comp-add | ||
inputs: | ||
parameters: | ||
a: | ||
componentInputParameter: a | ||
b: | ||
componentInputParameter: b | ||
retryPolicy: | ||
backoffDuration: 0s | ||
backoffFactor: 2.0 | ||
backoffMaxDuration: 3600s | ||
maxRetryCount: 3 | ||
taskInfo: | ||
name: add | ||
inputDefinitions: | ||
parameters: | ||
a: | ||
defaultValue: 1.0 | ||
parameterType: NUMBER_DOUBLE | ||
b: | ||
defaultValue: 7.0 | ||
parameterType: NUMBER_DOUBLE | ||
schemaVersion: 2.1.0 | ||
sdkVersion: kfp-2.0.0-alpha.5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -450,6 +450,30 @@ def set_memory_limit(self, memory: str) -> 'PipelineTask': | |
|
||
return self | ||
|
||
def set_retry(self, | ||
num_retries: int, | ||
backoff_duration: Optional[str] = None, | ||
backoff_factor: Optional[float] = None, | ||
backoff_max_duration: Optional[str] = None) -> 'PipelineTask': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: A Should we add here, but raise a cc: @chensun |
||
"""Sets task retry parameters. | ||
|
||
Args: | ||
num_retries (int): Number of times to retry on failure. | ||
backoff_duration (Optional[int]): The the number of seconds to wait before triggering a retry. Defaults to '0s' (immediate retry). | ||
backoff_factor (Optional[float]): The exponential backoff factor applied to backoff_duration. For example, if backoff_duration="60" (60 seconds) and backoff_factor=2, the first retry will happen after 60 seconds, then after 120, 240, and so on. Defaults to 2.0. | ||
backoff_max_duration (Optional[int]): The maximum duration during which the task will be retried. Maximum duration is 1 hour (3600s). Defaults to '3600s'. | ||
|
||
Returns: | ||
Self return to allow chained setting calls. | ||
""" | ||
self.task_spec.retry_policy = structures.RetryPolicy( | ||
max_retry_count=num_retries, | ||
backoff_duration=backoff_duration, | ||
backoff_factor=backoff_factor, | ||
backoff_max_duration=backoff_max_duration, | ||
) | ||
return self | ||
|
||
def add_node_selector_constraint(self, accelerator: str) -> 'PipelineTask': | ||
"""Sets accelerator type requirement for this task. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, remove the parameters that don't work on Vertex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on a second look, it's fine to keep this as-is, as long as the samples under
test_data/pipelines
doesn't show these no-op usage.