forked from kubeflow/pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…ow#5447) * added resource request at runtime * fixed things * Update to use read only parameter insteadt * added test case and better example * Updated again * add the validation * add to the test suit * work in progress * update after feedback * fix the test * clean up * clean up * fix the path * add the test again * clean up * fix tests * feedback fix * comment out and clean up
- Loading branch information
Showing
6 changed files
with
151 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2021 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. | ||
|
||
import kfp | ||
from kfp import dsl, components | ||
from typing import NamedTuple | ||
|
||
@components.create_component_from_func | ||
def training_op(n: int) -> int: | ||
# quickly allocate a lot of memory to verify memory is enough | ||
a = [i for i in range(n)] | ||
return len(a) | ||
|
||
@components.create_component_from_func | ||
def generate_resouce_request() -> NamedTuple('output', [('memory', str), ('cpu', str)]): | ||
'''Returns the memory and cpu request''' | ||
from collections import namedtuple | ||
|
||
resouce_output = namedtuple('output', ['memory', 'cpu']) | ||
return resouce_output('500Mi', '200m') | ||
|
||
@dsl.pipeline( | ||
name='Runtime resource request pipeline', | ||
description='An example on how to make resource requests at runtime.' | ||
) | ||
def resource_request_pipeline(n: int = 11234567): | ||
resouce_task = generate_resouce_request() | ||
traning_task = training_op(n)\ | ||
.set_memory_limit(resouce_task.outputs['memory'])\ | ||
.set_cpu_limit(resouce_task.outputs['cpu'])\ | ||
.set_cpu_request('200m') | ||
|
||
# Disable cache for KFP v1 mode. | ||
traning_task.execution_options.caching_strategy.max_cache_staleness = 'P0D' | ||
|
||
if __name__ == '__main__': | ||
kfp.compiler.Compiler().compile(resource_request_pipeline, __file__ + '.yaml') |
48 changes: 48 additions & 0 deletions
48
samples/core/resource_spec/runtime_resource_request_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2021 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. | ||
|
||
import kfp | ||
from .runtime_resource_request import resource_request_pipeline | ||
from ...test.util import run_pipeline_func, TestCase | ||
|
||
|
||
def EXPECTED_OOM(run_id, run, **kwargs): | ||
'''confirms a sample test case is failing, because of OOM ''' | ||
assert run.status == 'Failed' | ||
|
||
|
||
run_pipeline_func([ | ||
TestCase( | ||
pipeline_func=resource_request_pipeline, | ||
mode=kfp.dsl.PipelineExecutionMode.V1_LEGACY, | ||
), | ||
# TODO: blocked by https://github.com/kubeflow/pipelines/issues/5835 | ||
# TestCase( | ||
# pipeline_func=resource_request_pipeline, | ||
# mode=kfp.dsl.PipelineExecutionMode.V2_COMPATIBLE, | ||
# ), | ||
TestCase( | ||
pipeline_func=resource_request_pipeline, | ||
mode=kfp.dsl.PipelineExecutionMode.V1_LEGACY, | ||
arguments={'n': 21234567}, | ||
verify_func=EXPECTED_OOM, | ||
), | ||
# TODO: blocked by https://github.com/kubeflow/pipelines/issues/5835 | ||
# TestCase( | ||
# pipeline_func=resource_request_pipeline, | ||
# mode=kfp.dsl.PipelineExecutionMode.V2_COMPATIBLE, | ||
# arguments={'n': 21234567}, | ||
# verify_func=EXPECTED_OOM, | ||
# ), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters