Skip to content

fix: Pop out ModelPackageName from pipeline definition #3472

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 1 commit into from
Dec 9, 2022
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
12 changes: 12 additions & 0 deletions src/sagemaker/workflow/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""Scrapper utilities to support repacking of models."""
from __future__ import absolute_import

import logging
import os
import shutil
import tarfile
Expand All @@ -37,6 +38,8 @@
if TYPE_CHECKING:
from sagemaker.workflow.step_collections import StepCollection

logger = logging.getLogger(__name__)

FRAMEWORK_VERSION = "0.23-1"
INSTANCE_TYPE = "ml.m5.large"
REPACK_SCRIPT = "_repack_model.py"
Expand Down Expand Up @@ -479,10 +482,19 @@ def arguments(self) -> RequestType:

request_dict = get_create_model_package_request(**model_package_args)
# these are not available in the workflow service and will cause rejection
warn_msg_template = (
"Popping out '%s' from the pipeline definition "
"since it will be overridden in pipeline execution time."
)
if "CertifyForMarketplace" in request_dict:
request_dict.pop("CertifyForMarketplace")
logger.warning(warn_msg_template, "CertifyForMarketplace")
if "Description" in request_dict:
request_dict.pop("Description")
logger.warning(warn_msg_template, "Description")
if "ModelPackageName" in request_dict:
request_dict.pop("ModelPackageName")
logger.warning(warn_msg_template, "ModelPackageName")

return request_dict

Expand Down
1 change: 1 addition & 0 deletions tests/integ/sagemaker/workflow/test_model_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def test_pytorch_training_model_registration_and_creation_without_custom_inferen
inference_instances=["ml.m5.xlarge"],
transform_instances=["ml.m5.xlarge"],
description="test-description",
model_package_name="model-pkg-name-will-be-popped-out",
)
step_model_regis = ModelStep(
name="pytorch-register-model",
Expand Down
75 changes: 75 additions & 0 deletions tests/unit/sagemaker/workflow/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from __future__ import absolute_import

from unittest.mock import Mock, PropertyMock

import pytest

from sagemaker import Session
from sagemaker.workflow.pipeline_context import PipelineSession

REGION = "us-west-2"
BUCKET = "my-bucket"
ROLE = "DummyRole"
IMAGE_URI = "fakeimage"


@pytest.fixture(scope="module")
def client():
"""Mock client.

Considerations when appropriate:

* utilize botocore.stub.Stubber
* separate runtime client from client
"""
client_mock = Mock()
client_mock._client_config.user_agent = (
"Boto3/1.14.24 Python/3.8.5 Linux/5.4.0-42-generic Botocore/1.17.24 Resource"
)
return client_mock


@pytest.fixture(scope="module")
def boto_session(client):
role_mock = Mock()
type(role_mock).arn = PropertyMock(return_value=ROLE)

resource_mock = Mock()
resource_mock.Role.return_value = role_mock

session_mock = Mock(region_name=REGION)
session_mock.resource.return_value = resource_mock
session_mock.client.return_value = client

return session_mock


@pytest.fixture(scope="module")
def pipeline_session(boto_session, client):
return PipelineSession(
boto_session=boto_session,
sagemaker_client=client,
default_bucket=BUCKET,
)


@pytest.fixture(scope="module")
def sagemaker_session(boto_session, client):
return Session(
boto_session=boto_session,
sagemaker_client=client,
sagemaker_runtime_client=client,
default_bucket=BUCKET,
)
Loading