-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: fix instance_type assignment logic #4719
Conversation
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 change does not look correct, let's hold till SME is back in office please.
@@ -322,7 +322,7 @@ def get_deploy_kwargs( | |||
model_id=model_id, | |||
model_from_estimator=True, | |||
model_version=model_version, | |||
instance_type=model_deploy_kwargs.instance_type if training_instance_type is None else None, | |||
instance_type=model_deploy_kwargs.instance_type or training_instance_type, |
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 change doesn't look right, the attribute is referring to the hosting instance type, it should not be passed a training instance type.
I think it should just be something like:
# if passed an instance type, use it
deploy_instance_type = instance_type
# otherwise, if passed a training instance, derive from training instance
if not instance_type and training_instance_type
deploy_instance_type = instance_types.retrieve_default(
model_id,
model_version,
training_instance_type=training_instance_type
)
else:
deploy_instance_type = model_deploy_kwargs.instance_type
Can we wait for SME @evakravi to look at this code change before merging?
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 based the above change on the commit where it was introduced, which also added:
training_instance_type (str): In the case of a model fine-tuned on SageMaker, the training
instance type used for the training job that produced the fine-tuned weights.
Optionally supply this to get a inference instance type conditioned
on the training instance, to ensure compatability of training artifact to inference
instance. (Default: None).
Which I now notice should also:
- compatability
+ compatibility
Happy to wait for @evakravi to be back in office to discuss what is the best approach here.
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.
@JGuinegagne The logic you have looks right. But let's definitely add unit tests so there's no doubt that this fixes the problem at hand.
Issue #, if available:
4666 - aws/amazon-sagemaker-examples#4666
Description of changes:
In this code change, the logic for assigning the
instance_type
variable has been improved by using the Pythonor
operator instead of a ternary conditional expression.The original code:
This line checks if
training_instance_type
isNone
. If it isNone
, it assignsmodel_deploy_kwargs.instance_type
toinstance_type
. Otherwise, it assignsNone
toinstance_type
, which seems counterintuitive and results in it ignoring a passed ininstance_type
if atraining_instance_type
also exists.The new code:
This line uses the
or
operator to assign the value ofmodel_deploy_kwargs.instance_type
toinstance_type
if it is a "truthy" value (i.e., notNone
,0
,False
, or an empty collection). Ifmodel_deploy_kwargs.instance_type
is a "falsy" value (i.e.,None
,0
,False
, or an empty collection), it will assign the value oftraining_instance_type
toinstance_type
.This change improves the logic by ensuring that
instance_type
is assigned a non-None
value if eithermodel_deploy_kwargs.instance_type
ortraining_instance_type
has a valid value.Testing done:
No new tests added, ran with existing unit tests locally and results remain the same.
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.