-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feature: script mode for model class #2841
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
feature: script mode for model class #2841
Conversation
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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.
Same comment as #2834 on unit tests to cover (if applicable):
git_config
dependencies
src/sagemaker/model.py
Outdated
) | ||
|
||
def _upload_code(self, key_prefix, repack=False): |
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.
i know you are only refactoring, but could you please add args and return typings?
src/sagemaker/model.py
Outdated
) | ||
|
||
def _upload_code(self, key_prefix, repack=False): | ||
"""Placeholder Docstring""" |
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.
Would you be able to update the docstring?
Codecov Report
@@ Coverage Diff @@
## master-jumpstart #2841 +/- ##
====================================================
- Coverage 89.16% 89.16% -0.01%
====================================================
Files 185 185
Lines 16043 16047 +4
====================================================
+ Hits 14305 14308 +3
- Misses 1738 1739 +1
Continue to review full report at Codecov.
|
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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.
non-blocking question: why moving **/test_model.py
to **/model/test_model.py
?
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
code_location (str): Name of the S3 bucket where custom code is | ||
uploaded (default: None). If not specified, default bucket | ||
created by ``sagemaker.session.Session`` is used. | ||
entry_point (str): Path (absolute or relative) to the Python source |
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.
need to add (default: None)
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
if self.source_dir or self.dependencies or self.entry_point or self.git_config: | ||
if self.key_prefix or self.git_config: | ||
self._upload_code(deploy_key_prefix, repack=False) | ||
elif self.source_dir and self.entry_point: | ||
self._upload_code(deploy_key_prefix, repack=True) | ||
else: | ||
self._upload_code(deploy_key_prefix, repack=False) | ||
deploy_env.update(self._script_mode_env_vars()) | ||
return sagemaker.container_def( |
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.
Can we concise this as:
if self.source_dir and self.entry_point:
self._upload_code(deploy_key_prefix, repack=True)
else:
self._upload_code(deploy_key_prefix, repack=False)
and with that you can even use ternary to condense it into a single line further
if repack and self.model_data is not None and self.entry_point is not None: | ||
if isinstance(self.model_data, sagemaker.workflow.properties.Properties): | ||
# model is not yet there, defer repacking to later during pipeline execution | ||
return |
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.
This feels similar to elsewhere in the code, can we in future pull this into a common utility?
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.
We have this logic only once in the code, though there's similar packaging code used for the Estimator
classes.
Issue #, if available:
Description of changes:
This PR adds script mode support to the
Model
class.This was basically done by adding the parameters
source_dir, code_location, entry_point, container_log_level, dependencies, git_config
to theModel
class.Testing done:
The changes to the
Model
class do not break any existing unit tests. In addition, new unit tests were added to simulate the script mode use case for theModel
class, and confirm that the calls tosagemaker.deploy_endpoint()
,sagemaker.create_model()
,sagemaker.create_endpoint_configuration()
ands3
are the same for theModel
class andFrameworkModel
class when both use script mode. In addition, this PR confirms thatgit_config
can be used with the newModel
class. Integration tests will be introduced in a subsequent PR.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
Tests
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.