Skip to content

Add Local Mode Batch Inference support. #414

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 18 commits into from
Oct 11, 2018

Conversation

iquintero
Copy link
Contributor

@iquintero iquintero commented Oct 1, 2018

Add support for Local Mode Batch Inference (Local Transform Jobs).

Creating local transform jobs will perform all the steps locally. The serving container will be created the same way as it is for serving but then the data will be fed to it and written to the corresponding output location. Data splits and batch strategies are implemented as closely as possible to the behavior in SageMaker so that the end results are consistent.

Description of changes:

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.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have updated the changelog with a description of my changes (if appropriate)
  • I have updated any necessary documentation (if appropriate)

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

Ignacio Quintero added 5 commits September 28, 2018 10:52
basic stuff works
It is magic! No, it actually checks how to assemble the already split
data to feed into the container.
Fixed all broken tests and code complete. Need to add a few more tests
@codecov-io
Copy link

codecov-io commented Oct 1, 2018

Codecov Report

Merging #414 into master will increase coverage by 0.27%.
The diff coverage is 92.64%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #414      +/-   ##
==========================================
+ Coverage   93.44%   93.71%   +0.27%     
==========================================
  Files          53       55       +2     
  Lines        3737     4010     +273     
==========================================
+ Hits         3492     3758     +266     
- Misses        245      252       +7
Impacted Files Coverage Δ
src/sagemaker/amazon/common.py 97.01% <100%> (ø) ⬆️
src/sagemaker/transformer.py 100% <100%> (ø) ⬆️
src/sagemaker/local/local_session.py 88.88% <78.57%> (-2.13%) ⬇️
src/sagemaker/local/image.py 90.76% <83.33%> (+2.22%) ⬆️
src/sagemaker/utils.py 90.29% <83.87%> (-2.86%) ⬇️
src/sagemaker/local/entities.py 95.17% <93.7%> (+2.94%) ⬆️
src/sagemaker/local/data.py 94.64% <94.64%> (ø)
src/sagemaker/local/utils.py 96.66% <96.66%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80ba921...94c7ead. Read the comment docs.

@iquintero iquintero changed the title Local batch inference Add Local Mode Batch Inference support. Oct 1, 2018
@iquintero iquintero requested a review from laurenyu October 2, 2018 00:01
CHANGELOG.rst Outdated
@@ -6,6 +6,7 @@ CHANGELOG
=========

* enhancement: Local Mode: add training environment variables for AWS region and job name
* feature: Add support for Local Mode Batch Inference
Copy link
Contributor

Choose a reason for hiding this comment

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

feature: Local Mode: add support for Batch Transform


BUCKET_NAME = 'some-nice-bucket'


Copy link
Contributor

Choose a reason for hiding this comment

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

no tests for copy_directory_structure or recursive_copy?

Copy link
Contributor

@mvsusp mvsusp left a comment

Choose a reason for hiding this comment

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

Some docstrings are missing.

Copy link
Contributor

@laurenyu laurenyu left a comment

Choose a reason for hiding this comment

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

might want to just do a pass through all of the docstrings

else:
files = [self.root_path]

return files
Copy link
Contributor

Choose a reason for hiding this comment

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

bump (especially because you do it in get_root_dir)

environment['SAGEMAKER_BATCH_STRATEGY'] = strategy_env_value

# we only do 1 max concurrent transform in Local Mode
environment['SAGEMAKER_MAX_CONCURRENT_TRANSFORMS'] = '1'
Copy link
Contributor

Choose a reason for hiding this comment

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

bump

path = parsed_uri.path.strip('/')
sagemaker_session.upload_data(source, bucket, path)
else:
raise ValueError('Invalid destination URI, must be s3:// or file://')
Copy link
Contributor

Choose a reason for hiding this comment

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

include the URI in the error message


def describe_transform_job(self, TransformJobName):
if TransformJobName not in LocalSagemakerClient._transform_jobs:
error_response = {'Error': {'Code': 'ValidationException', 'Message': 'Could not find local transform job'}}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd include TransformJobName in the error message



@pytest.mark.continuous_testing
def test_local_transform_mxnet(sagemaker_local_session, tmpdir):
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: s/transform/batch_transform (just in case anyone thinks of transform as real-time inference since the input-predict-output cycle is "transform")

@pytest.mark.continuous_testing
def test_local_transform_mxnet(sagemaker_local_session, tmpdir):
data_path = os.path.join(DATA_DIR, 'mxnet_mnist')
script_path = os.path.join(data_path, 'mnist.py')
Copy link
Contributor

Choose a reason for hiding this comment

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

a lot of these tests seem to do the same boilerplate MXNet/MNIST setup - perhaps something can be refactored?



def test_recordio_splitter(tmpdir):

Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: remove the extra newline

def test_get_batch_strategy_instance_with_invalid_type():
with pytest.raises(ValueError):
# something invalid
sagemaker.local.data.get_batch_strategy_instance('NiceRecord', None)
Copy link
Contributor

Choose a reason for hiding this comment

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

personal preference - I'd just make the string 'SomethingInvalid' instead of writing a comment to explain it

else:
files = [self.root_path]

return files
Copy link
Contributor

Choose a reason for hiding this comment

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

you can remove the return files line now :)

laurenyu
laurenyu previously approved these changes Oct 10, 2018
mvsusp
mvsusp previously approved these changes Oct 10, 2018
@iquintero iquintero dismissed stale reviews from mvsusp and laurenyu via dd9851f October 11, 2018 18:53
laurenyu
laurenyu previously approved these changes Oct 11, 2018
@iquintero iquintero merged commit c8006fa into aws:master Oct 11, 2018
pdasamzn pushed a commit to pdasamzn/sagemaker-python-sdk that referenced this pull request Nov 1, 2018
Creating local batch transform jobs will perform all the steps locally. The serving container will be created the same way as it is for serving but then the data will be fed to it and written to the corresponding output location. Data splits and batch strategies are implemented as closely as possible to the behavior in SageMaker so that the end results are consistent.
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.

4 participants