Repository navigation
Add update_endpoint support to session class and add optional flag to… - #606
Conversation
Codecov Report
@@ Coverage Diff @@
## master #606 +/- ##
==========================================
+ Coverage 92.7% 92.72% +0.01%
==========================================
Files 71 71
Lines 5418 5428 +10
==========================================
+ Hits 5023 5033 +10
Misses 395 395
Continue to review full report at Codecov.
|
ChoiByungWook
left a comment
There was a problem hiding this comment.
Nice!
Please update the changelog with your feature addition.
Let's add an integration test!
|
Address previous comments and add integration tests. New integration tests passed. |
| ========= | ||
|
|
||
|
|
||
| 1.18.1 |
There was a problem hiding this comment.
Let's append .dev to the end, since this hasn't been released to PyPI yet.
| self.wait_for_endpoint(endpoint_name) | ||
| return endpoint_name | ||
|
|
||
| def update_endpoint(self, endpoint_name, config_name): |
There was a problem hiding this comment.
I didn't catch this earlier either.
Can we rename config_name parameter to endpoint-config-name, so that we are consistent with https://docs.aws.amazon.com/cli/latest/reference/sagemaker/update-endpoint.html
|
|
||
| Args: | ||
| endpoint_name (str): Name of the Amazon SageMaker ``Endpoint`` to update. | ||
| config_name (str): Name of the Amazon SageMaker endpoint configuration to deploy. |
There was a problem hiding this comment.
same thing here. Thanks!
| predictor.delete_endpoint() | ||
|
|
||
|
|
||
| def test_local_deploy_with_update_endpoint(tmpdir, sagemaker_local_session, mxnet_model): |
There was a problem hiding this comment.
You can remove this integration test. I don't think this is necessary, as the unit test already catches this use case.
If you want to keep the test, let's assert on the exception message and catch the specific exception as well.
| local_sagemaker_client = sagemaker.local.local_session.LocalSagemakerClient() | ||
| endpoint_name = 'my-endpoint' | ||
| endpoint_config = 'my-endpoint-config' | ||
| with pytest.raises(Exception) as exception: |
| predictor = model.deploy(1, 'ml.m4.xlarge', update_endpoint=True, endpoint_name=endpoint_name) | ||
| new_endpoint_config = sagemaker_session.describe_endpoint(EndpointName=endpoint_name) | ||
| data = numpy.zeros(shape=(1, 1, 28, 28)) | ||
| predictor.predict(data) |
There was a problem hiding this comment.
We don't have to do a prediction, since we are only testing the update_functionality. This use case is also fulfilled with the other deploy tests.
| py_version=PYTHON_VERSION, sagemaker_session=sagemaker_session) | ||
| model.deploy(1, 'ml.t2.medium', endpoint_name=endpoint_name) | ||
| old_endpoint_config = sagemaker_session.describe_endpoint(EndpointName=endpoint_name) | ||
| predictor = model.deploy(1, 'ml.m4.xlarge', update_endpoint=True, endpoint_name=endpoint_name) |
There was a problem hiding this comment.
Up to you on this one as it is just a styling issue, however can we add a space here?
I think it will become a little easier to read, since we are splitting from the first deploy to the update.
Thanks!
| data = numpy.zeros(shape=(1, 1, 28, 28)) | ||
| predictor.predict(data) | ||
|
|
||
| print(old_endpoint_config) |
There was a problem hiding this comment.
I would personally not include these print statements. If you do plan on leaving them, please prepend a description of what is being printed. For example:
print('old endpoint configuration: {}'.format(old_endpoint_config))
There was a problem hiding this comment.
ohh, this is unintentional.
| print() | ||
| print(new_endpoint_config) | ||
|
|
||
| if old_endpoint_config['EndpointConfigName'] == new_endpoint_config['EndpointConfigName']: |
There was a problem hiding this comment.
Let's add some assertions that the new_endpoint_config, the one that was deployed as part of the update, has the values that are expected.
You can either call describe_endpoint_config or do an assertion against the production variant which I believe should be a part of output for describe_endpoint done above.
https://docs.aws.amazon.com/cli/latest/reference/sagemaker/describe-endpoint-config.html
https://docs.aws.amazon.com/cli/latest/reference/sagemaker/describe-endpoint.html
| endpoint.serve() | ||
|
|
||
| def update_endpoint(self, EndpointName, EndpointConfigName): | ||
| del EndpointName, EndpointConfigName |
There was a problem hiding this comment.
You don't have to call del here.
There was a problem hiding this comment.
pylint will complain if EndpointName, EndpointConfigName are not used.
There was a problem hiding this comment.
Good call!
You can follow this line:
There was a problem hiding this comment.
Please remove the del.
| new_production_variants = sagemaker_session.describe_endpoint(EndpointName=endpoint_name)['ProductionVariants'] | ||
|
|
||
| assert new_production_variants['InstanceType'] == 'ml.m4.xlarge' | ||
| assert old_production_variants['VariantName'] != new_production_variants['VariantName'] |
There was a problem hiding this comment.
Let's assert that the sagemaker_session.describe_endpoint(EndpointName=endpoint_name)['EndpointConfigName'] aren't the same.
Other than that, I think doing the assertion of the values such as: assert new_production_variants['InstanceType'] == 'ml.m4.xlarge' would be better then doing a comparison.
| model.deploy(1, 'ml.t2.medium', endpoint_name=endpoint_name) | ||
| sagemaker_session.describe_endpoint(EndpointName=endpoint_name) | ||
| model.deploy(1, 'ml.m4.xlarge', update_endpoint=True, endpoint_name='non-existing-endpoint') | ||
| except ValueError: |
There was a problem hiding this comment.
I think using the pytest.raises might look cleaner here.
Let's assert that the exception has the right error message.
|
|
||
| assert old_config_name != new_config_name | ||
| assert new_production_variants['InstanceType'] == 'ml.m4.xlarge' | ||
| assert old_production_variants['InitialInstanceCount'] == 1 |
There was a problem hiding this comment.
Let's assert on the new_production_variants. Since that is the endpoint config we want to verify is being used.
mvsusp
left a comment
There was a problem hiding this comment.
We are getting there ! Thanks for the hard work on this.
Please add a section on the documentation on how to use update endpoints as well.
| py_version=PYTHON_VERSION, sagemaker_session=sagemaker_session) | ||
| model.deploy(1, 'ml.t2.medium', endpoint_name=endpoint_name) | ||
| sagemaker_session.describe_endpoint(EndpointName=endpoint_name) | ||
| model.deploy(1, 'ml.m4.xlarge', update_endpoint=True, endpoint_name='non-existing-endpoint') |
There was a problem hiding this comment.
Your test is missing assertions.
There was a problem hiding this comment.
This test expects an error, which is asserted with pytest.raises(ValueError, message=error_message) here.
There was a problem hiding this comment.
I would make the pytest.raiser more explicitly then. Leaving under model.deploy under the pytest.raises denotes that the error can be raise only from that specific method.
|
|
||
|
|
||
| def test_deploy_with_update_endpoint(sagemaker_session): | ||
| e = Estimator(IMAGE_NAME, ROLE, INSTANCE_COUNT, INSTANCE_TYPE, output_path=OUTPUT_PATH, |
There was a problem hiding this comment.
Avoid one letter variables.
There was a problem hiding this comment.
Updated. Do we need to update all other 1-letter variable names in this test? Many of the tests here use 'e' for estimator.
|
|
||
|
|
||
| def test_update_endpoint_non_existing_endpoint(sagemaker_session): | ||
| ims = sagemaker_session |
| def test_update_endpoint_non_existing_endpoint(sagemaker_session): | ||
| ims = sagemaker_session | ||
| error = ClientError({'Error': {'Code': 'ValidationException', 'Message': 'Could not find entity'}}, 'foo') | ||
| error_message = 'Endpoint with name "non-existing-endpoint" does not exist; please use an existing endpoint name' |
There was a problem hiding this comment.
Is this error message necessary? I don't see any assertion about it.
There was a problem hiding this comment.
Add the error message to pytest.raises(ValueError, message=error_message)
There was a problem hiding this comment.
Got it, I got confused with the order of statements. nit: rename it to expected_error_msg or something like that.
There was a problem hiding this comment.
Done. Also changed the naming in test_local_session and test_mxnet_train.
| e.fit({'train': 's3://bucket/training-prefix'}) | ||
| e.deploy(INSTANCE_COUNT, INSTANCE_TYPE, endpoint_name="endpoint-name", update_endpoint=True) | ||
| sagemaker_session.create_endpoint_config.assert_called() | ||
| sagemaker_session.update_endpoint.assert_called() |
There was a problem hiding this comment.
Please use assert_called_with instead.
There was a problem hiding this comment.
Updated with using call_args and assert with argument values. The model_name/endpoint_config_name is not accessible from estimator, so not able to use assert_called_with directly.
| If not specified, a unique endpoint name will be created. | ||
| update_endpoint (bool): Flag to update the model in an existing Amazon SageMaker endpoint. | ||
| If True, this will deploy a new EndpointConfig to an already existing endpoint and delete resources | ||
| corresponding to the previous EndpointConfig. Default: False |
There was a problem hiding this comment.
Please docstring what happens when this flag is false as well. Is it possible to throw an exception for example?
There was a problem hiding this comment.
Updated documentation. The error is raised in session.update_endpoint so the corresponding information is documented there.
ChoiByungWook
left a comment
There was a problem hiding this comment.
LGTM! Waiting on @mvsusp for approval.
mvsusp
left a comment
There was a problem hiding this comment.
Is it possible to add the new feature in the documentation?
|
@mvsusp Are you referring to adding the new feature to the GitHub README (and do we want to add this new feature in the README?) or docs.aws.amazon.com? |
@ChuyangDeng , the GitHub README (and other readme pages about the estimators) include documentation about the deploy method. Ideally we should review these, and update if necessary. The same should be done for notebook examples, although I understand that is outside the scope of this PR. |
|
@mvsusp I added a code snippet under 'Using Estimators' to demonstrate this function because there's no sections for the method |
| mxnet_estimator.delete_endpoint() | ||
|
|
||
|
|
||
| Or, if you want to deploy to an existing endpoint instead of letting SageMaker creating a new one, you can specify to update an endpoint. |
There was a problem hiding this comment.
Up to you, I think the wording below might be more specific.
Additionally, it is possible to deploy a different endpoint configuration, which links to your model, to an already existing SageMaker endpoint. This can be done by specifying the existing endpoint name for the endpoint_name parameter along with the update_endpoint parameter as True within your deploy() call. For more information.
Issue #, if available:
#58
Description of changes:
Add update_endpoint to support session class to update endpoint instead of creating new one. Add an optional flag in .deploy method accordingly.
Merge Checklist
Put an
xin 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.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.