chore(sdk.v2): Support explicit task dependency (#4824)

This commit is contained in:
Chen Sun 2020-11-24 12:10:40 -08:00 committed by GitHub
parent 6931fe84f5
commit 6b8bd4c7ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 166 additions and 0 deletions

View File

@ -93,6 +93,11 @@ class Compiler(object):
deployment_config.executors[task.executor_label].container.CopyFrom(
op.container_spec)
# A task may have explicit depdency on other tasks even though they may
# not have inputs/outputs dependency. e.g.: op2.after(op1)
if op.dependent_names:
task.dependent_tasks.extend(op.dependent_names)
# Check if need to insert importer node
for input_name in task.inputs.artifacts:
if not task.inputs.artifacts[input_name].producer_task:

View File

@ -75,5 +75,9 @@ class CompilerCliTests(unittest.TestCase):
def test_pipeline_with_reused_component(self):
self._test_compile_py_to_json('pipeline_with_reused_component')
def test_pipeline_with_after(self):
self._test_compile_py_to_json('pipeline_with_after')
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,110 @@
{
"pipelineSpec": {
"deploymentConfig": {
"@type": "type.googleapis.com/ml_pipelines.PipelineDeploymentConfig",
"executors": {
"Print Text": {
"container": {
"command": [
"sh",
"-c",
"set -e -x\necho \"$0\"\n",
"{{$.inputs.parameters['text']}}"
],
"image": "alpine"
}
},
"Print Text 3": {
"container": {
"image": "alpine",
"command": [
"sh",
"-c",
"set -e -x\necho \"$0\"\n",
"{{$.inputs.parameters['text']}}"
]
}
},
"Print Text 2": {
"container": {
"command": [
"sh",
"-c",
"set -e -x\necho \"$0\"\n",
"{{$.inputs.parameters['text']}}"
],
"image": "alpine"
}
}
}
},
"pipelineInfo": {
"name": "pipeline-with-after"
},
"sdkVersion": "kfp-1.1.1",
"tasks": [
{
"executorLabel": "Print Text",
"taskInfo": {
"name": "Print Text"
},
"inputs": {
"parameters": {
"text": {
"runtimeValue": {
"constantValue": {
"stringValue": "1st task"
}
}
}
}
}
},
{
"inputs": {
"parameters": {
"text": {
"runtimeValue": {
"constantValue": {
"stringValue": "2nd task"
}
}
}
}
},
"dependentTasks": [
"Print Text"
],
"taskInfo": {
"name": "Print Text 2"
},
"executorLabel": "Print Text 2"
},
{
"dependentTasks": [
"Print Text",
"Print Text 2"
],
"inputs": {
"parameters": {
"text": {
"runtimeValue": {
"constantValue": {
"stringValue": "3rd task"
}
}
}
}
},
"executorLabel": "Print Text 3",
"taskInfo": {
"name": "Print Text 3"
}
}
],
"schemaVersion": "v2alpha1"
},
"runtimeConfig": {
"gcsOutputDirectory": "dummy_root"
}
}

View File

@ -0,0 +1,47 @@
# 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 kfp.v2 import components
from kfp.v2 import dsl
import kfp.v2.compiler as compiler
component_op = components.load_component_from_text("""
name: Print Text
inputs:
- {name: text, type: String}
implementation:
container:
image: alpine
command:
- sh
- -c
- |
set -e -x
echo "$0"
- {inputValue: text}
""")
@dsl.pipeline(name='pipeline-with-after')
def my_pipeline():
task1 = component_op(text='1st task')
task2 = component_op(text='2nd task').after(task1)
task3 = component_op(text='3rd task').after(task1, task2)
if __name__ == '__main__':
compiler.Compiler().compile(
pipeline_func=my_pipeline,
pipeline_root='dummy_root',
output_path=__file__ + '.json')