-
Notifications
You must be signed in to change notification settings - Fork 1.2k
change: handle image_uri rename for estimators and models in v2 migration tool #1675
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9921a07
change: handle image_uri rename for estimators and models in v2 migra…
laurenyu 43caa0b
Merge branch 'zwei' into migration-tool-image-name
laurenyu 621f2f7
Merge branch 'zwei' into migration-tool-image-name
laurenyu 2130f0b
fix
laurenyu 30180d4
Merge branch 'zwei' into migration-tool-image-name
laurenyu 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
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
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
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
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
118 changes: 118 additions & 0 deletions
118
tests/unit/sagemaker/cli/compatibility/v2/modifiers/test_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,118 @@ | ||
# 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 = { | ||
"Chainer": ("sagemaker.chainer", "sagemaker.chainer.estimator"), | ||
"Estimator": ("sagemaker.estimator",), | ||
"Framework": ("sagemaker.estimator",), | ||
"MXNet": ("sagemaker.mxnet", "sagemaker.mxnet.estimator"), | ||
"PyTorch": ("sagemaker.pytorch", "sagemaker.pytorch.estimator"), | ||
"RLEstimator": ("sagemaker.rl", "sagemaker.rl.estimator"), | ||
"SKLearn": ("sagemaker.sklearn", "sagemaker.sklearn.estimator"), | ||
"TensorFlow": ("sagemaker.tensorflow", "sagemaker.tensorflow.estimator"), | ||
"XGBoost": ("sagemaker.xgboost", "sagemaker.xgboost.estimator"), | ||
} | ||
|
||
MODELS = { | ||
"ChainerModel": ("sagemaker.chainer", "sagemaker.chainer.model"), | ||
"Model": ("sagemaker.model",), | ||
"MultiDataModel": ("sagemaker.multidatamodel",), | ||
"FrameworkModel": ("sagemaker.model",), | ||
"MXNetModel": ("sagemaker.mxnet", "sagemaker.mxnet.model"), | ||
"PyTorchModel": ("sagemaker.pytorch", "sagemaker.pytorch.model"), | ||
"SKLearnModel": ("sagemaker.sklearn", "sagemaker.sklearn.model"), | ||
"TensorFlowModel": ("sagemaker.tensorflow", "sagemaker.tensorflow.model"), | ||
"XGBoostModel": ("sagemaker.xgboost", "sagemaker.xgboost.model"), | ||
} | ||
|
||
|
||
def test_estimator_node_should_be_modified(): | ||
modifier = renamed_params.EstimatorImageURIRenamer() | ||
|
||
for estimator, namespaces in ESTIMATORS.items(): | ||
call = "{}(image_name='my-image:latest')".format(estimator) | ||
assert modifier.node_should_be_modified(ast_call(call)) | ||
|
||
for namespace in namespaces: | ||
call = "{}.{}(image_name='my-image:latest')".format(namespace, estimator) | ||
assert modifier.node_should_be_modified(ast_call(call)) | ||
|
||
|
||
def test_estimator_node_should_be_modified_no_distribution(): | ||
modifier = renamed_params.EstimatorImageURIRenamer() | ||
|
||
for estimator, namespaces in ESTIMATORS.items(): | ||
call = "{}()".format(estimator) | ||
assert not modifier.node_should_be_modified(ast_call(call)) | ||
|
||
for namespace in namespaces: | ||
call = "{}.{}()".format(namespace, estimator) | ||
assert not modifier.node_should_be_modified(ast_call(call)) | ||
|
||
|
||
def test_estimator_node_should_be_modified_random_function_call(): | ||
modifier = renamed_params.EstimatorImageURIRenamer() | ||
assert not modifier.node_should_be_modified(ast_call("Session()")) | ||
|
||
|
||
def test_estimator_modify_node(): | ||
node = ast_call("TensorFlow(image_name=my_image)") | ||
modifier = renamed_params.EstimatorImageURIRenamer() | ||
modifier.modify_node(node) | ||
|
||
expected = "TensorFlow(image_uri=my_image)" | ||
assert expected == pasta.dump(node) | ||
|
||
|
||
def test_model_node_should_be_modified(): | ||
modifier = renamed_params.ModelImageURIRenamer() | ||
|
||
for model, namespaces in MODELS.items(): | ||
call = "{}(image='my-image:latest')".format(model) | ||
assert modifier.node_should_be_modified(ast_call(call)) | ||
|
||
for namespace in namespaces: | ||
call = "{}.{}(image='my-image:latest')".format(namespace, model) | ||
assert modifier.node_should_be_modified(ast_call(call)) | ||
|
||
|
||
def test_model_node_should_be_modified_no_distribution(): | ||
modifier = renamed_params.ModelImageURIRenamer() | ||
|
||
for model, namespaces in MODELS.items(): | ||
call = "{}()".format(model) | ||
assert not modifier.node_should_be_modified(ast_call(call)) | ||
|
||
for namespace in namespaces: | ||
call = "{}.{}()".format(namespace, model) | ||
assert not modifier.node_should_be_modified(ast_call(call)) | ||
|
||
|
||
def test_model_node_should_be_modified_random_function_call(): | ||
modifier = renamed_params.ModelImageURIRenamer() | ||
assert not modifier.node_should_be_modified(ast_call("Session()")) | ||
|
||
|
||
def test_model_modify_node(): | ||
node = ast_call("TensorFlowModel(image=my_image)") | ||
modifier = renamed_params.ModelImageURIRenamer() | ||
modifier.modify_node(node) | ||
|
||
expected = "TensorFlowModel(image_uri=my_image)" | ||
assert expected == pasta.dump(node) |
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
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.
@ignorable
nit pep-0257There 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 blame our 100-character line limit 😂