-
Notifications
You must be signed in to change notification settings - Fork 1.2k
change: handle image_uri rename for Session methods #1681
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
Merged
laurenyu
merged 4 commits into
aws:zwei
from
laurenyu:migration-tool-create-model-image-uri
Jul 8, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
62 changes: 62 additions & 0 deletions
62
tests/unit/sagemaker/cli/compatibility/v2/modifiers/test_estimator_create_model.py
This file contains hidden or 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,62 @@ | ||
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file 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 __future__ import absolute_import | ||
|
||
import pasta | ||
|
||
from sagemaker.cli.compatibility.v2.modifiers import renamed_params | ||
from tests.unit.sagemaker.cli.compatibility.v2.modifiers.ast_converter import ast_call | ||
|
||
ESTIMATORS = ( | ||
"estimator", | ||
"chainer", | ||
"mxnet", | ||
"mx", | ||
"pytorch", | ||
"rl", | ||
"sklearn", | ||
"tensorflow", | ||
"tf", | ||
"xgboost", | ||
"xgb", | ||
) | ||
|
||
|
||
def test_node_should_be_modified(): | ||
modifier = renamed_params.EstimatorCreateModelImageURIRenamer() | ||
|
||
for estimator in ESTIMATORS: | ||
call = "{}.create_model(image='my-image:latest')".format(estimator) | ||
assert modifier.node_should_be_modified(ast_call(call)) | ||
|
||
|
||
def test_node_should_be_modified_no_distribution(): | ||
modifier = renamed_params.EstimatorCreateModelImageURIRenamer() | ||
|
||
for estimator in ESTIMATORS: | ||
call = "{}.create_model()".format(estimator) | ||
assert not modifier.node_should_be_modified(ast_call(call)) | ||
|
||
|
||
def test_node_should_be_modified_random_function_call(): | ||
modifier = renamed_params.EstimatorCreateModelImageURIRenamer() | ||
assert not modifier.node_should_be_modified(ast_call("create_model()")) | ||
|
||
|
||
def test_modify_node(): | ||
node = ast_call("estimator.create_model(image=my_image)") | ||
modifier = renamed_params.EstimatorCreateModelImageURIRenamer() | ||
modifier.modify_node(node) | ||
|
||
expected = "estimator.create_model(image_uri=my_image)" | ||
assert expected == pasta.dump(node) |
94 changes: 94 additions & 0 deletions
94
tests/unit/sagemaker/cli/compatibility/v2/modifiers/test_session_image_uri.py
This file contains hidden or 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,94 @@ | ||
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file 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 __future__ import absolute_import | ||
|
||
import pasta | ||
|
||
from sagemaker.cli.compatibility.v2.modifiers import renamed_params | ||
from tests.unit.sagemaker.cli.compatibility.v2.modifiers.ast_converter import ast_call | ||
|
||
CREATE_MODEL_TEMPLATES = ( | ||
"sagemaker_session.create_model_from_job({})", | ||
"sess.create_model_from_job({})", | ||
) | ||
|
||
CREATE_ENDPOINT_TEMPLATES = ( | ||
"sagemaker_session.endpoint_from_job({})", | ||
"sagemaker_session.endpoint_from_model_data({})", | ||
"sess.endpoint_from_job({})", | ||
"sess.endpoint_from_model_data({})", | ||
) | ||
|
||
|
||
def test_create_model_node_should_be_modified(): | ||
modifier = renamed_params.SessionCreateModelImageURIRenamer() | ||
|
||
for template in CREATE_MODEL_TEMPLATES: | ||
call = ast_call(template.format("primary_container_image=my_image")) | ||
assert modifier.node_should_be_modified(call) | ||
|
||
|
||
def test_create_model_node_should_be_modified_no_image(): | ||
modifier = renamed_params.SessionCreateModelImageURIRenamer() | ||
|
||
for template in CREATE_MODEL_TEMPLATES: | ||
call = ast_call(template.format("")) | ||
assert not modifier.node_should_be_modified(call) | ||
|
||
|
||
def test_create_model_node_should_be_modified_random_function_call(): | ||
modifier = renamed_params.SessionCreateModelImageURIRenamer() | ||
assert not modifier.node_should_be_modified(ast_call("create_model()")) | ||
|
||
|
||
def test_create_model_modify_node(): | ||
modifier = renamed_params.SessionCreateModelImageURIRenamer() | ||
|
||
for template in CREATE_MODEL_TEMPLATES: | ||
call = ast_call(template.format("primary_container_image=my_image")) | ||
modifier.modify_node(call) | ||
|
||
expected = template.format("image_uri=my_image") | ||
assert expected == pasta.dump(call) | ||
|
||
|
||
def test_create_endpoint_node_should_be_modified(): | ||
modifier = renamed_params.SessionCreateEndpointImageURIRenamer() | ||
|
||
for template in CREATE_ENDPOINT_TEMPLATES: | ||
call = ast_call(template.format("deployment_image=my_image")) | ||
assert modifier.node_should_be_modified(call) | ||
|
||
|
||
def test_create_endpoint_node_should_be_modified_no_image(): | ||
modifier = renamed_params.SessionCreateEndpointImageURIRenamer() | ||
|
||
for template in CREATE_ENDPOINT_TEMPLATES: | ||
call = ast_call(template.format("")) | ||
assert not modifier.node_should_be_modified(call) | ||
|
||
|
||
def test_create_endpoint_node_should_be_modified_random_function_call(): | ||
modifier = renamed_params.SessionCreateEndpointImageURIRenamer() | ||
assert not modifier.node_should_be_modified(ast_call("create_endpoint()")) | ||
|
||
|
||
def test_create_endpoint_modify_node(): | ||
modifier = renamed_params.SessionCreateEndpointImageURIRenamer() | ||
|
||
for template in CREATE_ENDPOINT_TEMPLATES: | ||
call = ast_call(template.format("deployment_image=my_image")) | ||
modifier.modify_node(call) | ||
|
||
expected = template.format("image_uri=my_image") | ||
assert expected == pasta.dump(call) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
fft: although i don't like promoting deep class inheritance hierarchy, this method is common to all
*ImageURIRenamer
and may benefit from some inheritanceThere 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.
(talked offline) I'd also noticed the duplication too, but agree that too many layers of inheritance also isn't great