sagemaker-inference-toolkit icon indicating copy to clipboard operation
sagemaker-inference-toolkit copied to clipboard

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

Open athewsey opened this issue 3 years ago • 1 comments

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

  • [X] I have read the CONTRIBUTING doc
  • [X] 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

  • [X] I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • [X] 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.

athewsey avatar Aug 17 '22 14:08 athewsey

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

lopesdaniel09 avatar Sep 01 '23 09:09 lopesdaniel09