-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: zazulam <m.zazula@gmail.com>
- Loading branch information
Showing
6 changed files
with
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from kfp import Client, dsl | ||
|
||
|
||
@dsl.component | ||
def print_op(message: str) -> str: | ||
print(message) | ||
return message | ||
|
||
|
||
@dsl.pipeline() | ||
def loop_with_after_dependency_set(): | ||
with dsl.ParallelFor([1, 2, 3]): | ||
one = print_op(message='foo') | ||
# Ensure that the dependecy is set downstream for all loop iterations | ||
two = print_op(message='bar').after(one) | ||
three = print_op(message='baz').after(one) | ||
|
||
|
||
if __name__ == '__main__': | ||
client = Client() | ||
run = client.create_run_from_pipeline_func(loop_with_after_dependency_set) |
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,39 @@ | ||
from kfp import Client | ||
from kfp import dsl | ||
from kfp.dsl import Artifact, Input, Output | ||
|
||
|
||
@dsl.component | ||
def split_input(input: str) -> list: | ||
return input.split(',') | ||
|
||
|
||
@dsl.component | ||
def create_file(file: Output[Artifact], content: str): | ||
with open(file.path, 'w') as f: | ||
f.write(content) | ||
|
||
|
||
@dsl.component | ||
def read_file(file: Input[Artifact]) -> str: | ||
with open(file.path, 'r') as f: | ||
print(f.read()) | ||
return file.path | ||
|
||
|
||
@dsl.pipeline() | ||
def loop_consume_upstream(): | ||
model_ids_split_op = split_input(input='component1,component2,component3') | ||
model_ids_split_op.set_caching_options(False) | ||
|
||
with dsl.ParallelFor(model_ids_split_op.output) as model_id: | ||
create_file_op = create_file(content=model_id) | ||
create_file_op.set_caching_options(False) | ||
# Consume the output from a op in the loop iteration DAG context | ||
read_file_op = read_file(file=create_file_op.outputs['file']) | ||
read_file_op.set_caching_options(False) | ||
|
||
|
||
if __name__ == '__main__': | ||
client = Client() | ||
run = client.create_run_from_pipeline_func(loop_consume_upstream) |
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