forked from kubeflow/pipelines
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK - Compiler - Fixed ParallelFor argument resolving (kubeflow#3029)
* SDK - Compiler - Fixed ParallelFor name clashes The ParallelFor argument reference resolving was really broken. The logic "worked" like this - of the name of the referenced output contained the name of the loop collection source output, then it was considered to be the reference to the loop item. This broke lots of scenarios especially in cases where there were multiple components with same output name (e.g. the default "Output" output name). The logic also did not distinguish between references to the loop collection item vs. references to the loop collection source itself. I've rewritten the argument resolving logic, to fix the issues. * Argo cannot use {{item}} when withParams items are dicts * Stabilize the loop template names * Renamed the test case
- Loading branch information
Showing
10 changed files
with
879 additions
and
49 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
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
84 changes: 84 additions & 0 deletions
84
sdk/python/tests/compiler/testdata/parallelfor_item_argument_resolving.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,84 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2020 Google LLC | ||
# | ||
# 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 typing import NamedTuple | ||
|
||
import kfp | ||
from kfp.components import func_to_container_op | ||
|
||
|
||
# Stabilizing the test output | ||
class StableIDGenerator: | ||
def __init__(self, ): | ||
self._index = 0 | ||
|
||
def get_next_id(self, ): | ||
self._index += 1 | ||
return '{code:0{num_chars:}d}'.format(code=self._index, num_chars=kfp.dsl._for_loop.LoopArguments.NUM_CODE_CHARS) | ||
|
||
kfp.dsl.ParallelFor._get_unique_id_code = StableIDGenerator().get_next_id | ||
|
||
|
||
@func_to_container_op | ||
def produce_str() -> str: | ||
return "Hello" | ||
|
||
|
||
@func_to_container_op | ||
def produce_list_of_dicts() -> list: | ||
return ([{"aaa": "aaa1", "bbb": "bbb1"}, {"aaa": "aaa2", "bbb": "bbb2"}],) | ||
|
||
|
||
@func_to_container_op | ||
def produce_list_of_strings() -> list: | ||
return (["a", "z"],) | ||
|
||
|
||
@func_to_container_op | ||
def produce_list_of_ints() -> list: | ||
return ([1234567890, 987654321],) | ||
|
||
|
||
@func_to_container_op | ||
def consume(param1): | ||
print(param1) | ||
|
||
|
||
@kfp.dsl.pipeline() | ||
def parallelfor_item_argument_resolving(): | ||
produce_str_task = produce_str() | ||
produce_list_of_strings_task = produce_list_of_strings() | ||
produce_list_of_ints_task = produce_list_of_ints() | ||
produce_list_of_dicts_task = produce_list_of_dicts() | ||
|
||
with kfp.dsl.ParallelFor(produce_list_of_strings_task.output) as loop_item: | ||
consume(produce_list_of_strings_task.output) | ||
consume(loop_item) | ||
consume(produce_str_task.output) | ||
|
||
with kfp.dsl.ParallelFor(produce_list_of_ints_task.output) as loop_item: | ||
consume(produce_list_of_ints_task.output) | ||
consume(loop_item) | ||
|
||
with kfp.dsl.ParallelFor(produce_list_of_dicts_task.output) as loop_item: | ||
consume(produce_list_of_dicts_task.output) | ||
#consume(loop_item) # Cannot use the full loop item when it's a dict | ||
consume(loop_item.aaa) | ||
|
||
|
||
if __name__ == '__main__': | ||
import kfp.compiler as compiler | ||
compiler.Compiler().compile(parallelfor_item_argument_resolving, __file__ + '.yaml') | ||
|
Oops, something went wrong.