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

feat(sdk)!: Support submitting pipeline IR in yaml format via kfp.client #7458

Merged
merged 2 commits into from
Mar 23, 2022
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
1 change: 1 addition & 0 deletions sdk/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

* Fix wrong kfp import causes wrong sdk_version being set in pipeline_spec. [\#7433](https://github.com/kubeflow/pipelines/pull/7433)
* Use YAML as default serialization format for package IR [\#7431](https://github.com/kubeflow/pipelines/pull/7431)
* Support submitting pipeline IR in yaml format via `kfp.client`. [\#7458](https://github.com/kubeflow/pipelines/pull/7458)

## Documentation Updates

Expand Down
21 changes: 10 additions & 11 deletions sdk/python/kfp/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,20 +610,19 @@ def delete_experiment(self, experiment_id):
"""
return self._experiment_api.delete_experiment(id=experiment_id)

# TODO: support IR yaml
def _extract_pipeline_yaml(self, package_file):

def _choose_pipeline_file(file_list) -> str:
pipeline_files = [
file for file in file_list if file.endswith('.json')
file for file in file_list if file.endswith('.yaml')
]
if len(pipeline_files) == 0:
raise ValueError(
'Invalid package. Missing pipeline json file in the package.'
'Invalid package. Missing pipeline yaml file in the package.'
)

if 'pipeline.json' in pipeline_files:
return 'pipeline.json'
if 'pipeline.yaml' in pipeline_files:
return 'pipeline.yaml'
elif len(pipeline_files) == 1:
return pipeline_files[0]
else:
Expand All @@ -642,13 +641,13 @@ def _choose_pipeline_file(file_list) -> str:
pipeline_file = _choose_pipeline_file(zip.namelist())
with zip.open(pipeline_file) as f:
return yaml.safe_load(f)
elif package_file.endswith('.json'):
elif package_file.endswith('.yaml') or package_file.endswith('.yml'):
with open(package_file, 'r') as f:
return yaml.safe_load(f)
else:
raise ValueError(
f'The package_file {package_file} should end with one of the '
'following formats: [.tar.gz, .tgz, .zip, .json].')
'following formats: [.tar.gz, .tgz, .zip, .yaml, .yml].')

def _override_caching_options(self, workflow: dict, enable_caching: bool):
raise NotImplementedError('enable_caching is not supported yet.')
Expand Down Expand Up @@ -888,7 +887,7 @@ def _create_job_config(
experiment_id: The id of an experiment.
pipeline_package_path: Local path of the pipeline package (the
filename should end with one of the following .tar.gz, .tgz,
.zip, .json).
.zip, .yaml, .yml).
params: A dictionary with key as param name and value as param value.
pipeline_id: The id of a pipeline.
version_id: The id of a pipeline version.
Expand All @@ -914,7 +913,7 @@ def __init__(self, spec, resource_references):
self.resource_references = resource_references

params = params or {}
pipeline_json_string = None
pipeline_yaml_string = None
if pipeline_package_path:
pipeline_obj = self._extract_pipeline_yaml(pipeline_package_path)

Expand All @@ -923,7 +922,7 @@ def __init__(self, spec, resource_references):
if enable_caching is not None:
self._override_caching_options(pipeline_obj, enable_caching)

pipeline_json_string = json.dumps(pipeline_obj)
pipeline_yaml_string = yaml.dump(pipeline_obj)

runtime_config = kfp_server_api.models.PipelineSpecRuntimeConfig(
pipeline_root=pipeline_root,
Expand All @@ -948,7 +947,7 @@ def __init__(self, spec, resource_references):

spec = kfp_server_api.models.ApiPipelineSpec(
pipeline_id=pipeline_id,
pipeline_manifest=pipeline_json_string,
pipeline_manifest=pipeline_yaml_string,
runtime_config=runtime_config,
)
return JobConfig(spec=spec, resource_references=resource_references)
Expand Down