Skip to content
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

fix(sdk.v2): fix importer not taking output from upstream #6439

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,43 @@
}
}
},
"comp-importer-3": {
"executorLabel": "exec-importer-3",
"inputDefinitions": {
"parameters": {
"uri": {
"type": "STRING"
}
}
},
"outputDefinitions": {
"artifacts": {
"artifact": {
"artifactType": {
"schemaTitle": "system.Dataset",
"schemaVersion": "0.0.1"
}
}
}
}
},
"comp-pass-through-op": {
"executorLabel": "exec-pass-through-op",
"inputDefinitions": {
"parameters": {
"value": {
"type": "STRING"
}
}
},
"outputDefinitions": {
"parameters": {
"Output": {
"type": "STRING"
}
}
}
},
"comp-train": {
"executorLabel": "exec-train",
"inputDefinitions": {
Expand Down Expand Up @@ -154,6 +191,34 @@
}
}
}
},
"comp-train-3": {
"executorLabel": "exec-train-3",
"inputDefinitions": {
"artifacts": {
"dataset": {
"artifactType": {
"schemaTitle": "system.Dataset",
"schemaVersion": "0.0.1"
}
}
}
},
"outputDefinitions": {
"artifacts": {
"model": {
"artifactType": {
"schemaTitle": "system.Model",
"schemaVersion": "0.0.1"
}
}
},
"parameters": {
"scalar": {
"type": "STRING"
}
}
}
}
},
"deploymentSpec": {
Expand Down Expand Up @@ -182,6 +247,34 @@
}
}
},
"exec-importer-3": {
"importer": {
"artifactUri": {
"runtimeParameter": "uri"
},
"typeSchema": {
"schemaTitle": "system.Dataset",
"schemaVersion": "0.0.1"
}
}
},
"exec-pass-through-op": {
"container": {
"args": [
"--value",
"{{$.inputs.parameters['value']}}",
"----output-paths",
"{{$.outputs.parameters['Output'].output_file}}"
],
"command": [
"sh",
"-ec",
"program_path=$(mktemp)\nprintf \"%s\" \"$0\" > \"$program_path\"\npython3 -u \"$program_path\" \"$@\"\n",
"def pass_through_op(value):\n return value\n\ndef _serialize_str(str_value: str) -> str:\n if not isinstance(str_value, str):\n raise TypeError('Value \"{}\" has type \"{}\" instead of str.'.format(str(str_value), str(type(str_value))))\n return str_value\n\nimport argparse\n_parser = argparse.ArgumentParser(prog='Pass through op', description='')\n_parser.add_argument(\"--value\", dest=\"value\", type=str, required=True, default=argparse.SUPPRESS)\n_parser.add_argument(\"----output-paths\", dest=\"_output_paths\", type=str, nargs=1)\n_parsed_args = vars(_parser.parse_args())\n_output_files = _parsed_args.pop(\"_output_paths\", [])\n\n_outputs = pass_through_op(**_parsed_args)\n\n_outputs = [_outputs]\n\n_output_serializers = [\n _serialize_str,\n\n]\n\nimport os\nfor idx, output_file in enumerate(_output_files):\n try:\n os.makedirs(os.path.dirname(output_file))\n except OSError:\n pass\n with open(output_file, 'w') as f:\n f.write(_output_serializers[idx](_outputs[idx]))\n"
],
"image": "python:3.7"
}
},
"exec-train": {
"container": {
"args": [
Expand All @@ -193,7 +286,7 @@
"command": [
"sh",
"-c",
"(python3 -m ensurepip || python3 -m ensurepip --user) && (PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location 'kfp==1.7.0' || PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location 'kfp==1.7.0' --user) && \"$0\" \"$@\"",
"(python3 -m ensurepip || python3 -m ensurepip --user) && (PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location 'kfp==1.7.1' || PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location 'kfp==1.7.1' --user) && \"$0\" \"$@\"",
"sh",
"-ec",
"program_path=$(mktemp -d)\nprintf \"%s\" \"$0\" > \"$program_path/ephemeral_component.py\"\npython3 -m kfp.v2.components.executor_main --component_module_path \"$program_path/ephemeral_component.py\" \"$@\"\n",
Expand All @@ -213,7 +306,27 @@
"command": [
"sh",
"-c",
"(python3 -m ensurepip || python3 -m ensurepip --user) && (PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location 'kfp==1.7.0' || PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location 'kfp==1.7.0' --user) && \"$0\" \"$@\"",
"(python3 -m ensurepip || python3 -m ensurepip --user) && (PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location 'kfp==1.7.1' || PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location 'kfp==1.7.1' --user) && \"$0\" \"$@\"",
"sh",
"-ec",
"program_path=$(mktemp -d)\nprintf \"%s\" \"$0\" > \"$program_path/ephemeral_component.py\"\npython3 -m kfp.v2.components.executor_main --component_module_path \"$program_path/ephemeral_component.py\" \"$@\"\n",
"\nfrom kfp.v2.dsl import *\nfrom typing import *\n\ndef train(\n dataset: Input[Dataset]\n) -> NamedTuple('Outputs', [\n ('scalar', str),\n ('model', Model),\n]):\n \"\"\"Dummy Training step.\"\"\"\n with open(dataset.path, 'r') as f:\n data = f.read()\n print('Dataset:', data)\n\n scalar = '123'\n model = 'My model trained using data: {}'.format(data)\n\n from collections import namedtuple\n output = namedtuple('Outputs', ['scalar', 'model'])\n return output(scalar, model)\n\n"
],
"image": "python:3.7"
}
},
"exec-train-3": {
"container": {
"args": [
"--executor_input",
"{{$}}",
"--function_to_execute",
"train"
],
"command": [
"sh",
"-c",
"(python3 -m ensurepip || python3 -m ensurepip --user) && (PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location 'kfp==1.7.1' || PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --quiet --no-warn-script-location 'kfp==1.7.1' --user) && \"$0\" \"$@\"",
"sh",
"-ec",
"program_path=$(mktemp -d)\nprintf \"%s\" \"$0\" > \"$program_path/ephemeral_component.py\"\npython3 -m kfp.v2.components.executor_main --component_module_path \"$program_path/ephemeral_component.py\" \"$@\"\n",
Expand Down Expand Up @@ -279,6 +392,48 @@
"name": "importer"
}
},
"importer-3": {
"cachingOptions": {
"enableCache": true
},
"componentRef": {
"name": "comp-importer-3"
},
"dependentTasks": [
"pass-through-op"
],
"inputs": {
"parameters": {
"uri": {
"taskOutputParameter": {
"outputParameterKey": "Output",
"producerTask": "pass-through-op"
}
}
}
},
"taskInfo": {
"name": "importer-3"
}
},
"pass-through-op": {
"cachingOptions": {
"enableCache": true
},
"componentRef": {
"name": "comp-pass-through-op"
},
"inputs": {
"parameters": {
"value": {
"componentInputParameter": "dataset2"
}
}
},
"taskInfo": {
"name": "pass-through-op"
}
},
"train": {
"cachingOptions": {
"enableCache": true
Expand All @@ -302,6 +457,30 @@
"taskInfo": {
"name": "train"
}
},
"train-3": {
"cachingOptions": {
"enableCache": true
},
"componentRef": {
"name": "comp-train-3"
},
"dependentTasks": [
"importer-3"
],
"inputs": {
"artifacts": {
"dataset": {
"taskOutputArtifact": {
"outputArtifactKey": "artifact",
"producerTask": "importer-3"
}
}
}
},
"taskInfo": {
"name": "train-3"
}
}
}
},
Expand All @@ -314,7 +493,7 @@
}
},
"schemaVersion": "2.0.0",
"sdkVersion": "kfp-1.7.0"
"sdkVersion": "kfp-1.7.1"
},
"runtimeConfig": {
"gcsOutputDirectory": "dummy_root",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def train(
return output(scalar, model)


@components.create_component_from_func
def pass_through_op(value: str) -> str:
return value


@dsl.pipeline(name='pipeline-with-importer', pipeline_root='dummy_root')
Expand All @@ -56,6 +59,10 @@ def my_pipeline(dataset2: str = 'gs://ml-pipeline-playground/shakespeare2.txt'):
artifact_uri=dataset2, artifact_class=Dataset, reimport=True)
train(dataset=importer2.output)

importer3 = importer(
artifact_uri=pass_through_op(dataset2).output, artifact_class=Dataset)
train(dataset=importer3.output)


if __name__ == '__main__':
compiler.Compiler().compile(
Expand Down
16 changes: 14 additions & 2 deletions sdk/python/kfp/v2/components/importer_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,20 @@ def _build_importer_task_spec(
importer_base_name)

if isinstance(artifact_uri, _pipeline_param.PipelineParam):
result.inputs.parameters[
INPUT_KEY].component_input_parameter = artifact_uri.full_name
param = artifact_uri
if param.op_name:
result.inputs.parameters[
INPUT_KEY
].task_output_parameter.producer_task = (
dsl_utils.sanitize_task_name(param.op_name)
)
result.inputs.parameters[
INPUT_KEY
].task_output_parameter.output_parameter_key = param.name
else:
result.inputs.parameters[
INPUT_KEY
].component_input_parameter = param.full_name
elif isinstance(artifact_uri, str):
result.inputs.parameters[
INPUT_KEY].runtime_value.constant_value.string_value = artifact_uri
Expand Down