Skip to content

fix: make 'ModelInput' field optional for inference recommendation #3220

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 47 additions & 24 deletions src/sagemaker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,32 +749,55 @@ def update_container_with_inference_params(
dict: dict with inference recommender params
"""

if (
framework is not None
and framework_version is not None
and nearest_model_name is not None
and data_input_configuration is not None
):
if framework is not None and framework_version is not None and nearest_model_name is not None:
if container_list is not None:
for obj in container_list:
obj.update(
{
"Framework": framework,
"FrameworkVersion": framework_version,
"NearestModelName": nearest_model_name,
"ModelInput": {
"DataInputConfig": data_input_configuration,
},
}
construct_container_object(
obj, data_input_configuration, framework, framework_version, nearest_model_name
)
if container_obj is not None:
container_obj.update(
{
"Framework": framework,
"FrameworkVersion": framework_version,
"NearestModelName": nearest_model_name,
"ModelInput": {
"DataInputConfig": data_input_configuration,
},
}
construct_container_object(
container_obj,
data_input_configuration,
framework,
framework_version,
nearest_model_name,
)


def construct_container_object(
obj, data_input_configuration, framework, framework_version, nearest_model_name
):
"""Function to construct container object.

Args:
framework (str): Machine learning framework of the model package container image
(default: None).
framework_version (str): Framework version of the Model Package Container Image
(default: None).
nearest_model_name (str): Name of a pre-trained machine learning benchmarked by
Amazon SageMaker Inference Recommender (default: None).
data_input_configuration (str): Input object for the model (default: None).
container_obj (dict): object to be updated.
container_list (list): list to be updated.

Returns:
dict: container object
"""

obj.update(
{
"Framework": framework,
"FrameworkVersion": framework_version,
"NearestModelName": nearest_model_name,
}
)

if data_input_configuration is not None:
obj.update(
{
"ModelInput": {
"DataInputConfig": data_input_configuration,
},
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def test_conditional_pytorch_training_model_registration(
framework = "TENSORFLOW"
framework_version = "2.9"
nearest_model_name = "resnet50"
data_input_configuration = '{"input_1":[1,224,224,3]}'

# If image_uri is not provided, the instance_type should not be a pipeline variable
# since instance_type is used to retrieve image_uri in compile time (PySDK)
Expand Down Expand Up @@ -132,7 +131,6 @@ def test_conditional_pytorch_training_model_registration(
framework=framework,
framework_version=framework_version,
nearest_model_name=nearest_model_name,
data_input_configuration=data_input_configuration,
)

model = Model(
Expand Down Expand Up @@ -219,7 +217,6 @@ def test_mxnet_model_registration(
framework = "TENSORFLOW"
framework_version = "2.9"
nearest_model_name = "resnet50"
data_input_configuration = '{"input_1":[1,224,224,3]}'

model = MXNetModel(
entry_point=entry_point,
Expand All @@ -244,7 +241,6 @@ def test_mxnet_model_registration(
framework=framework,
framework_version=framework_version,
nearest_model_name=nearest_model_name,
data_input_configuration=data_input_configuration,
)

pipeline = Pipeline(
Expand Down Expand Up @@ -293,7 +289,6 @@ def test_sklearn_xgboost_sip_model_registration(
framework = "TENSORFLOW"
framework_version = "2.9"
nearest_model_name = "resnet50"
data_input_configuration = '{"input_1":[1,224,224,3]}'

# The instance_type should not be a pipeline variable
# since it is used to retrieve image_uri in compile time (PySDK)
Expand Down Expand Up @@ -450,7 +445,6 @@ def test_sklearn_xgboost_sip_model_registration(
framework=framework,
framework_version=framework_version,
nearest_model_name=nearest_model_name,
data_input_configuration=data_input_configuration,
)

pipeline = Pipeline(
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/sagemaker/workflow/test_pipeline_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def test_pipeline_session_context_for_model_step_without_instance_types(
framework="TENSORFLOW",
framework_version="2.9",
nearest_model_name="resnet50",
data_input_configuration='{"input_1":[1,224,224,3]}',
)

expected_output = {
Expand All @@ -173,9 +172,6 @@ def test_pipeline_session_context_for_model_step_without_instance_types(
"Framework": "TENSORFLOW",
"FrameworkVersion": "2.9",
"NearestModelName": "resnet50",
"ModelInput": {
"DataInputConfig": '{"input_1":[1,224,224,3]}',
},
}
],
"SupportedContentTypes": ["text/csv"],
Expand Down
9 changes: 0 additions & 9 deletions tests/unit/sagemaker/workflow/test_step_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ def test_register_model_tf(estimator_tf, model_metrics, drift_check_baselines):
framework="TENSORFLOW",
framework_version="2.9",
nearest_model_name="resnet50",
data_input_configuration='{"input_1":[1,224,224,3]}',
)
assert ordered(register_model.request_dicts()) == ordered(
[
Expand Down Expand Up @@ -523,7 +522,6 @@ def test_register_model_sip(estimator, model_metrics, drift_check_baselines):
framework="TENSORFLOW",
framework_version="2.9",
nearest_model_name="resnet50",
data_input_configuration='{"input_1":[1,224,224,3]}',
)
assert ordered(register_model.request_dicts()) == ordered(
[
Expand All @@ -542,9 +540,6 @@ def test_register_model_sip(estimator, model_metrics, drift_check_baselines):
"Framework": "TENSORFLOW",
"FrameworkVersion": "2.9",
"NearestModelName": "resnet50",
"ModelInput": {
"DataInputConfig": '{"input_1":[1,224,224,3]}',
},
},
{
"Image": "fakeimage2",
Expand All @@ -553,9 +548,6 @@ def test_register_model_sip(estimator, model_metrics, drift_check_baselines):
"Framework": "TENSORFLOW",
"FrameworkVersion": "2.9",
"NearestModelName": "resnet50",
"ModelInput": {
"DataInputConfig": '{"input_1":[1,224,224,3]}',
},
},
],
"SupportedContentTypes": ["content_type"],
Expand Down Expand Up @@ -619,7 +611,6 @@ def test_register_model_with_model_repack_with_estimator(
framework="TENSORFLOW",
framework_version="2.9",
nearest_model_name="resnet50",
data_input_configuration='{"input_1":[1,224,224,3]}',
)

request_dicts = register_model.request_dicts()
Expand Down
4 changes: 0 additions & 4 deletions tests/unit/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3260,7 +3260,6 @@ def test_register_default_image_without_instance_type_args(sagemaker_session):
framework = "TENSORFLOW"
framework_version = "2.9"
nearest_model_name = "resnet50"
data_input_config = '{"input_1":[1,224,224,3]}'

estimator.register(
content_types=content_types,
Expand All @@ -3271,7 +3270,6 @@ def test_register_default_image_without_instance_type_args(sagemaker_session):
framework=framework,
framework_version=framework_version,
nearest_model_name=nearest_model_name,
data_input_configuration=data_input_config,
)
sagemaker_session.create_model.assert_not_called()

Expand Down Expand Up @@ -3319,7 +3317,6 @@ def test_register_inference_image(sagemaker_session):
framework = "TENSORFLOW"
framework_version = "2.9"
nearest_model_name = "resnet50"
data_input_config = '{"input_1":[1,224,224,3]}'
Copy link
Contributor

Choose a reason for hiding this comment

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

Have atleast 1 new test where we check for data_input_config if not already present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is already present in the existing test files.


estimator.register(
content_types=content_types,
Expand All @@ -3333,7 +3330,6 @@ def test_register_inference_image(sagemaker_session):
framework=framework,
framework_version=framework_version,
nearest_model_name=nearest_model_name,
data_input_configuration=data_input_config,
)
sagemaker_session.create_model.assert_not_called()

Expand Down