-
Notifications
You must be signed in to change notification settings - Fork 354
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): enable loading both JSON and YAML pipelines IR #1089
feat(sdk): enable loading both JSON and YAML pipelines IR #1089
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding some YAML snippets here along side the existing JSON one?
python-aiplatform/tests/unit/aiplatform/test_pipeline_jobs.py
Lines 67 to 104 in 52273c2
_TEST_PIPELINE_SPEC_LEGACY = { | |
"pipelineInfo": {"name": "my-pipeline"}, | |
"root": { | |
"dag": {"tasks": {}}, | |
"inputDefinitions": {"parameters": {"string_param": {"type": "STRING"}}}, | |
}, | |
"schemaVersion": "2.0.0", | |
"components": {}, | |
} | |
_TEST_PIPELINE_SPEC = { | |
"pipelineInfo": {"name": "my-pipeline"}, | |
"root": { | |
"dag": {"tasks": {}}, | |
"inputDefinitions": { | |
"parameters": { | |
"string_param": {"parameterType": "STRING"}, | |
"bool_param": {"parameterType": "BOOLEAN"}, | |
"double_param": {"parameterType": "NUMBER_DOUBLE"}, | |
"int_param": {"parameterType": "NUMBER_INTEGER"}, | |
"list_int_param": {"parameterType": "LIST"}, | |
"list_string_param": {"parameterType": "LIST"}, | |
"struct_param": {"parameterType": "STRUCT"}, | |
} | |
}, | |
}, | |
"schemaVersion": "2.1.0", | |
"components": {}, | |
} | |
_TEST_TFX_PIPELINE_SPEC = { | |
"pipelineInfo": {"name": "my-pipeline"}, | |
"root": { | |
"dag": {"tasks": {}}, | |
"inputDefinitions": {"parameters": {"string_param": {"type": "STRING"}}}, | |
}, | |
"schemaVersion": "2.0.0", | |
"sdkVersion": "tfx-1.4.0", | |
"components": {}, | |
} |
@@ -1,6 +1,6 @@ | |||
# -*- coding: utf-8 -*- | |||
|
|||
# Copyright 2020 Google LLC | |||
# Copyright 2022 Google LLC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: preserve the initial year, or leave it untouched.
https://opensource.google/documentation/reference/copyright#the_year
11066e1
to
78fb331
Compare
from typing import Any, Dict, Optional | ||
|
||
import yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is an optional dependency is should be wrapped with an informative exception on import:
python-aiplatform/google/cloud/aiplatform/explain/lit.py
Lines 35 to 41 in 74ffa19
try: | |
import tensorflow as tf | |
except ImportError: | |
raise ImportError( | |
"Tensorflow is not installed and is required to load saved model. " | |
'Please install the SDK using "pip install google-cloud-aiplatform[lit]"' | |
) |
Preference to import in the function that uses this package so it doesn't raise on module import.
tests/unit/aiplatform/test_utils.py
Outdated
class TestYamlUtils: | ||
def test_load_yaml_from_local_file__with_json(self, yaml_file): | ||
data = yaml_utils.load_yaml(yaml_file) | ||
assert data["key"] == "val" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think pytest supports dict equality with assert d1 == d2
yield mock_load_json | ||
def mock_load_yaml_and_json(job_spec): | ||
with patch.object(storage.Blob, "download_as_bytes") as mock_load_yaml_and_json: | ||
job_spec_str = json.dumps(job_spec) if isinstance(job_spec, dict) else job_spec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems inconsistent to handle the json case as job_spec
being deserialized and the yaml case as job_spec
being serialized. Preference to add a comment describing this for future reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely. That originates from the inconsistent starting point of the two representations in the tests: the JSON starts as a dict and the YAML starts as a string. In real usage, they would likely both be read in as strings from a file.
One option to make it more consistent is to put the json/dicts into strings as well, either literally with """
or programmatically (my preference) by wrapping in json.dumps
at definition. If not one of those two options, I'll add a comment. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json.dumps
SGTM. Thanks!
@sasha-gitg, can you please re-add the automerge label if all looks good? |
Merge-on-green attempted to merge your PR for 6 hours, but it was not mergeable because either one of your required status checks failed, one of your required reviews was not approved, or there is a do not merge label. Learn more about your required status checks here: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks. You can remove and reapply the label to re-run the bot. |
Merge-on-green attempted to merge your PR for 6 hours, but it was not mergeable because either one of your required status checks failed, one of your required reviews was not approved, or there is a do not merge label. Learn more about your required status checks here: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks. You can remove and reapply the label to re-run the bot. |
ec57bd7
to
3914dd0
Compare
Merge-on-green attempted to merge your PR for 6 hours, but it was not mergeable because either one of your required status checks failed, one of your required reviews was not approved, or there is a do not merge label. Learn more about your required status checks here: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks. You can remove and reapply the label to re-run the bot. |
Fixes #1088
Main changes
This PR switches
load_json
toload_yaml
. This change is backward-compatible, as YAML is a superset of JSON.Other changes
load_yaml
to demonstrate that is reads both JSON and YAML.pyyaml
as a library dependency.tests/unit/aiplatform/test_utils.py
withblack
.Manually tested the four primary codepaths
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
cc: @chensun @ji-yaqi