Skip to content
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

[DRAFT] Support CustomAttributes / request context in handler function overrides #111

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

athewsey
Copy link

Issue #, if available: #110

Description of changes:

Initial draft of a non-breaking option to support passing an extra "request context" parameter to handler override functions (transform_fn, input_fn, predict_fn, output_fn), ONLY when the signature of the provided function includes the extra parameter.

This should allow script mode users to access additional request context (such as the SageMaker CustomAttributes header) without breaking implementations using the existing function APIs.

Outstanding TODOs (hoping for input from reviewers!) include:

  • Agree the scope of the additional "context" object - the raw context object as per Transformer.transform() seems maybe too broad & not very user-friendly? I'm not even sure what API it offers
  • Validate the approach
  • Understand & complete relevant doc updates & downstream library updates (e.g. add the parameter in default handler fns here and in other libraries like the PyTorch and HuggingFace toolkits too? Update SageMaker Python SDK docs when new DLCs are available with this change built in?)

Testing done:

Added some unit tests to show initial non-breaking-ness, but would be nice to get an integration test too maybe?

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 used the regional endpoint when creating S3 and/or STS clients (if appropriate)
  • I have updated any necessary documentation, including READMEs

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)

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

Initial draft of a non-breaking option to support receiving an extra
request context parameter in handler override functions (e.g.
transform_fn, input_fn, predict_fn, output_fn) when the signature of
the provided function includes the extra parameter. This should allow
script mode users to access additional request context (such as the
SageMaker CustomAttributes header) without breaking implementations
using the existing function APIs.
Copy link
Contributor

@nskool nskool left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, could you resolve conflicts and mark it ready for review?

@@ -90,12 +97,46 @@ def test_transform(validate, retrieve_content_type_header, accept_key):

validate.assert_called_once()
retrieve_content_type_header.assert_called_once_with(request_property)
# Since Mock()'s callable signature has only 2 args ('args', 'kwargs'), the extra 'context' arg
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this comment can be removed, the test is self-explanatory.

@lopesdaniel09
Copy link

lopesdaniel09 commented Sep 1, 2023

Hello, I was also looking for this feature. Any progress?
Do you need help?

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.

None yet

3 participants