Skip to content

Allow Local Serving of Models in S3 #217

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 8 commits into from
Jun 15, 2018
Merged

Conversation

iquintero
Copy link
Contributor

if a model is located in S3, download and extract it and then start
serving as usual. By overriding the SageMaker Session on any Model
Object, local serving is possible on pre-trained models.

Issue #, if available:

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.

@iquintero iquintero requested a review from winstonaws June 7, 2018 18:00
@@ -453,8 +488,8 @@ def _build_optml_volumes(self, host, subdirs):
volumes = []

# Ensure that model is in the subdirs
if 'model' not in subdirs:
subdirs.add('model')
#if 'model' not in subdirs:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

will get rid of this

data = numpy.zeros(shape=(1, 1, 28, 28))
predictor.predict(data)
finally:
mxnet_model.sagemaker_session.delete_endpoint('')
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the empty string passed here because that's the name we explicitly chose for the endpoint?

Can we add delete_endpoint to the predictor class to make this more intuitive? That's where it should be anyway, IMO.

key_prefix='integ-test-data/mxnet_mnist/test')

mx.fit({'train': train_input, 'test': test_input})
model = mx.create_model(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the argument necessary here?

model_data = mxnet_model.model_data
boto_session = sagemaker_local_session.boto_session
default_bucket = sagemaker_local_session.default_bucket()
uploaded_data = tar_and_upload_dir(boto_session, default_bucket,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only necessary to create the model data, right? In the normal use cases, the user would either do both training and deploy locally, or create the MXNetModel pointing to local model data, or already have an S3 url with model data, right?

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, this is because I wanted to make this faster by training using local mode instead of training on sagemaker like the chainer tests do for instance.


s3_model = MXNetModel(model_data=uploaded_data.s3_prefix, role='SageMakerRole',
entry_point=mxnet_model.entry_point, image=mxnet_model.image,
sagemaker_session=sagemaker_local_session)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to explicitly pass a LocalSession here, or is that only for our tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It used to be required, now its only for our tests.

uploaded_data = tar_and_upload_dir(boto_session, default_bucket,
'test_mxnet_local_mode', '', model_data)

s3_model = MXNetModel(model_data=uploaded_data.s3_prefix, role='SageMakerRole',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is role still necessary here?

Copy link
Contributor Author

@iquintero iquintero Jun 7, 2018

Choose a reason for hiding this comment

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

its not necessary, but the estimators/model expects one. For SageMaker this is a must have, on local mode its not even used but I dont know if we should make this optional.

volumes = []
if parsed_uri.scheme == 'file':
volumes.append(_Volume(parsed_uri.path, '/opt/ml/code'))
if sagemaker.estimator.DIR_PARAM_NAME.upper() in primary_container['Environment']:
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the case where this is false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BYO :) we only have sagemaker_submit_dir on our Frameworks.

iquintero and others added 2 commits June 11, 2018 11:10
if a model is located in S3, download and extract it and then start
serving as usual. By overriding the SageMaker Session on any Model
Object, local serving is possible on pre-trained models.
@codecov-io
Copy link

codecov-io commented Jun 13, 2018

Codecov Report

Merging #217 into master will increase coverage by 0.16%.
The diff coverage is 97.61%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #217      +/-   ##
=========================================
+ Coverage   91.53%   91.7%   +0.16%     
=========================================
  Files          45      45              
  Lines        3166    3194      +28     
=========================================
+ Hits         2898    2929      +31     
+ Misses        268     265       -3
Impacted Files Coverage Δ
src/sagemaker/model.py 95.45% <100%> (+0.37%) ⬆️
src/sagemaker/local/image.py 88.2% <100%> (+2.03%) ⬆️
src/sagemaker/predictor.py 96.25% <50%> (-0.59%) ⬇️

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 2e2e397...768e196. Read the comment docs.

@@ -93,6 +93,12 @@ def predict(self, data):
response_body.close()
return data

def delete_endpoint(self):
def delete_endpoint(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is there an inner function 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.

its unclear XD. Fixed

@@ -93,6 +93,12 @@ def predict(self, data):
response_body.close()
return data

def delete_endpoint(self):
def delete_endpoint(self):
"""Delete an Amazon SageMaker ``Endpoint``.
Copy link
Contributor

Choose a reason for hiding this comment

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

How about "Delete the Amazon SageMaker endpoint backing this predictor" or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

@iquintero iquintero merged commit c758362 into aws:master Jun 15, 2018
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