Skip to content

chore: telemetry for deployment configs #4806

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

Conversation

evakravi
Copy link
Member

Issue #, if available:

Description of changes:
No telemetry (user agent metadata) was being recorded for deployment configuration information for JumpStart models. This adds recording of deployment configuration information.

Testing done:
added tests

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 certify that the changes I am introducing will be backward compatible, and I have discussed concerns about this, if any, with the Python SDK team
  • I used the commit message format described in CONTRIBUTING
  • I have passed the region in to all S3 and STS clients that I've initialized as part of this change.
  • I have updated any necessary documentation, including READMEs and API docs (if appropriate)

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added unit and/or integration tests as appropriate to ensure backward compatibility of the changes
  • I have checked that my tests are not configured for a specific region or account (if appropriate)
  • I have used 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.

@evakravi evakravi requested a review from a team as a code owner July 26, 2024 13:26
@@ -903,20 +911,16 @@ def _add_config_name_to_kwargs(
) -> JumpStartEstimatorInitKwargs:
"""Sets tags in kwargs based on default or override, returns full kwargs."""

specs = verify_model_region_and_return_specs(
kwargs.config_name = kwargs.config_name or get_top_ranked_config_name(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for refactoring this!

)
# we need to create a default JS session (without custom user agent)
# in order to retrieve config name info
temp_session = kwargs.sagemaker_session or DEFAULT_JUMPSTART_SAGEMAKER_SESSION
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if I follow this, if kwargs.sagemaker_session is None, don't we fallback to the default session here?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, but the problem is we need a session in order to derive what the config name is.

For the session to get the config name, we use the DEFAULT_JUMPSTART_SAGEMAKER_SESSION without any special user agent, unless a custom session is provided

@@ -150,6 +150,7 @@ def __init__(
model. (Default: None).

"""
version = version or "*"
Copy link
Contributor

Choose a reason for hiding this comment

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

sanity check: this would change the behavior on line 157 right? Is that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was intentional since version was being supplied as None, not being omitted.
I'm going to try removing this tho

return headers


def get_top_ranked_config_name(
Copy link
Contributor

Choose a reason for hiding this comment

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

non-blocking: are we assuming overall ranking in this method? Wouldn't we need to be provided which ranking array to use?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's an excellent point. How about I make it an optional argument, the ranking name, with the default value being overall?

scope=JumpStartScriptScope.TRAINING,
region=kwargs.region,
tolerate_vulnerable_model=kwargs.tolerate_vulnerable_model,
model_type=kwargs.model_type[0],
Copy link
Contributor

Choose a reason for hiding this comment

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

sanity-check: any risk of getting an IndexError here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, i did this cause the typing said it was a tuple, but looking at other places of the code, we do kwargs.model_type.

@malav-shastri -- any idea what to do here?

kwargs: Union[JumpStartModelInitKwargs, JumpStartModelDeployKwargs]
) -> JumpStartModelInitKwargs:
"""Sets session in kwargs based on default or override, returns full kwargs."""

kwargs.sagemaker_session = (
kwargs.sagemaker_session
or get_default_jumpstart_session_with_user_agent_suffix(
kwargs.model_id, kwargs.model_version, kwargs.hub_arn
kwargs.model_id, kwargs.model_version, kwargs.config_name, kwargs.hub_arn
Copy link
Contributor

Choose a reason for hiding this comment

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

consider using named args here to avoid the risk of mixing them up.

return kwargs
supported_instance_types = resolved_config.get("supported_inference_instance_types", [])
if kwargs.instance_type not in supported_instance_types:
JUMPSTART_LOGGER.warning("Overriding instance type to %s", kwargs.instance_type)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit (I know it isn't from this PR): could we use f-string please, also update to Overriding instance type to %s even though it is not in the list of supported instances.

Copy link
Member Author

Choose a reason for hiding this comment

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

i think we did this cause there's some linters that complain

is_hub_content: Optional[bool] = False,
) -> Session:
"""Returns default JumpStart SageMaker Session with model-specific user agent suffix."""
botocore_session = botocore.session.get_session()
botocore_config = botocore.config.Config(
user_agent_extra=get_jumpstart_user_agent_extra_suffix(
model_id, model_version, is_hub_content
model_id, model_version, config_name, is_hub_content
Copy link
Contributor

Choose a reason for hiding this comment

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

consider using named args here.

session = model.sagemaker_session

with mock.patch("botocore.client.BaseClient._make_request") as mock_make_request:
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my understanding, what is this try/except ?

Copy link
Member Author

Choose a reason for hiding this comment

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

basically im trying to intercept the network call to make sure the user agent has the right tags applied

Copy link
Contributor

Choose a reason for hiding this comment

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

still, I'm not sure why you need a try / except, particularly since you are mocking this.

Consider either removing or adding an inline comment to explain that.

JGuinegagne
JGuinegagne previously approved these changes Aug 5, 2024
session = model.sagemaker_session

with mock.patch("botocore.client.BaseClient._make_request") as mock_make_request:
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

still, I'm not sure why you need a try / except, particularly since you are mocking this.

Consider either removing or adding an inline comment to explain that.

@sage-maker sage-maker merged commit ba7e6a9 into aws:master Aug 5, 2024
14 checks passed
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.

5 participants