Skip to content

change: add modifier for s3_input class #1699

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 17 commits into from
Jul 13, 2020
Merged

change: add modifier for s3_input class #1699

merged 17 commits into from
Jul 13, 2020

Conversation

chuyang-deng
Copy link
Contributor

Issue #, if available:
breaking changes brought in #1680

Description of changes:
Add s3_input modifier to v2 cli.
Convert:

  • sagemaker.s3_input --> sagemaker.TrainingInput
  • s3_input --> TrainingInput

Testing done:
Unit test

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

  • I have read the CONTRIBUTING doc
  • I used the commit message format described in CONTRIBUTING
  • I have passed the region in to all S3 and STS clients that I've initialized as part of this change.
  • I have updated any necessary documentation, including READMEs and API docs (if appropriate)

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)
  • I have used unique_name_from_base to create resource names in integ tests (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: e1a0eed
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: 083da46
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-notebook-tests
  • Commit ID: 083da46
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-notebook-tests
  • Commit ID: e1a0eed
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-zwei-pr
  • Commit ID: 083da46
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-local-mode-tests
  • Commit ID: 083da46
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-local-mode-tests
  • Commit ID: e1a0eed
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Comment on lines 13 to 14
"""Classes to modify Predictor code to be compatible
with version 2.0 and later of the SageMaker Python SDK.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to update this


BASE_S3_INPUT = "s3_input"
SESSION = "session"
S3_INPUT = {"s3_input": ("sagemaker", "sagemaker.session")}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also include sagemaker.inputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the namespaces and added a test case.

from sagemaker.cli.compatibility.v2.modifiers.modifier import Modifier

BASE_S3_INPUT = "s3_input"
SESSION = "session"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks to be unused

from sagemaker.cli.compatibility.v2.modifiers import matching
from sagemaker.cli.compatibility.v2.modifiers.modifier import Modifier

BASE_S3_INPUT = "s3_input"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe S3_INPUT_NAME instead? I don't think "base" gives much info here.

Returns:
bool: If the import statement imports ``RealTimePredictor`` from the correct module.
"""
return node.module in S3_INPUT[BASE_S3_INPUT] and any(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seeing this, I think it might be better to define the list of namespaces separately. S3_INPUT[BASE_S3_INPUT] is a little unintuitive to read on its own here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I got rid of the dict and used namespaces to check the module.

"""A class to update import statements of ``s3_input``."""

def node_should_be_modified(self, node):
"""Checks if the import statement imports ``RealTimePredictor`` from the correct module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to update the docstring

_rename_class(node)


def _rename_class(node):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if you need to make this a standalone function, unless maybe if you're refactoring it so that it can be used elsewhere too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there's no need to make it a function. I've moved the logic to modify_node

@laurenyu
Copy link
Contributor

also don't forget to update ast_transformer.py

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: 99a9652
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: daff7ac
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository


node = ast_import("from sagemaker.session import s3_input as training_input")
modifier.modify_node(node)
expected_result = "from sagemaker.session import TrainingInput as training_input"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expected_result = "from sagemaker.session import TrainingInput as training_input"
expected_result = "from sagemaker.inputs import TrainingInput as training_input"

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-notebook-tests
  • Commit ID: 99a9652
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-notebook-tests
  • Commit ID: daff7ac
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-zwei-pr
  • Commit ID: daff7ac
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-local-mode-tests
  • Commit ID: 99a9652
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-local-mode-tests
  • Commit ID: daff7ac
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: 13e1f7d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-notebook-tests
  • Commit ID: 13e1f7d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: 04cdc7b
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-local-mode-tests
  • Commit ID: 13e1f7d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-notebook-tests
  • Commit ID: 04cdc7b
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-zwei-pr
  • Commit ID: 04cdc7b
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-local-mode-tests
  • Commit ID: 04cdc7b
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Comment on lines +35 to +37
- ``sagemaker.s3_input``
- ``sagemaker.session.s3_input``
- ``s3_input``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- ``sagemaker.s3_input``
- ``sagemaker.session.s3_input``
- ``s3_input``
- ``sagemaker.s3_input``
- ``sagemaker.inputs.s3_input``
- ``sagemaker.session.s3_input``
- ``s3_input``

Comment on lines +59 to +81
node = ast_call("s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "TrainingInput(s3_data='s3://a')" == pasta.dump(node)

node = ast_call("sagemaker.s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "sagemaker.TrainingInput(s3_data='s3://a')" == pasta.dump(node)

node = ast_call("session.s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node)

node = ast_call("inputs.s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node)

node = ast_call("sagemaker.inputs.s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "sagemaker.inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node)

node = ast_call("sagemaker.session.s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "sagemaker.inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional - you could also make an iterable of tuples to reduce how much code is repeated

Suggested change
node = ast_call("s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "TrainingInput(s3_data='s3://a')" == pasta.dump(node)
node = ast_call("sagemaker.s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "sagemaker.TrainingInput(s3_data='s3://a')" == pasta.dump(node)
node = ast_call("session.s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node)
node = ast_call("inputs.s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node)
node = ast_call("sagemaker.inputs.s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "sagemaker.inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node)
node = ast_call("sagemaker.session.s3_input(s3_data='s3://a')")
modifier.modify_node(node)
assert "sagemaker.inputs.TrainingInput(s3_data='s3://a')" == pasta.dump(node)
calls = (
("s3_input(s3_data='s3://a')", TrainingInput(s3_data='s3://a')"),
("sagemaker.s3_input(s3_data='s3://a')", "sagemaker.TrainingInput(s3_data='s3://a')"),
("session.s3_input(s3_data='s3://a')", "inputs.TrainingInput(s3_data='s3://a')"),
("inputs.s3_input(s3_data='s3://a')", "inputs.TrainingInput(s3_data='s3://a')"),
("sagemaker.inputs.s3_input(s3_data='s3://a')", "sagemaker.inputs.TrainingInput(s3_data='s3://a')"),
("sagemaker.session.s3_input(s3_data='s3://a')", "sagemaker.inputs.TrainingInput(s3_data='s3://a')"),
)
for call, expected in calls:
node = ast_call(call)
modifier.modify_node(node)
assert expected == pasta.dump(node)

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-unit-tests
  • Commit ID: de40298
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-notebook-tests
  • Commit ID: de40298
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-local-mode-tests
  • Commit ID: de40298
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@sagemaker-bot
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: sagemaker-python-sdk-zwei-pr
  • Commit ID: de40298
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@chuyang-deng chuyang-deng merged commit 24b2ab9 into aws:zwei Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants