Skip to content

Commit

Permalink
Debugging issue
Browse files Browse the repository at this point in the history
  • Loading branch information
samruds committed Mar 19, 2024
1 parent 9153c40 commit 166e03b
Showing 1 changed file with 14 additions and 131 deletions.
145 changes: 14 additions & 131 deletions tests/integ/sagemaker/serve/test_serve_pt_happy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from sagemaker.serve.spec.inference_spec import InferenceSpec
from torchvision.transforms import transforms
from torchvision.models.squeezenet import squeezenet1_1

import tests.integ
from tests.integ.sagemaker.serve.constants import (
PYTORCH_SQUEEZENET_RESOURCE_DIR,
SERVE_SAGEMAKER_ENDPOINT_TIMEOUT,
Expand Down Expand Up @@ -148,42 +148,11 @@ def model_builder(request):
return request.getfixturevalue(request.param)


# @pytest.mark.skipif(
# PYTHON_VERSION_IS_NOT_310,
# reason="The goal of these test are to test the serving components of our feature",
# )
# @pytest.mark.parametrize(
# "model_builder", ["model_builder_inference_spec_schema_builder"], indirect=True
# )
# @pytest.mark.slow_test
# @pytest.mark.flaky(reruns=5, reruns_delay=2)
# def test_happy_pytorch_local_container(sagemaker_session, model_builder, test_image):
# logger.info("Running in LOCAL_CONTAINER mode...")
# caught_ex = None
#
# model = model_builder.build(mode=Mode.LOCAL_CONTAINER, sagemaker_session=sagemaker_session)
#
# with timeout(minutes=SERVE_LOCAL_CONTAINER_TIMEOUT):
# try:
# logger.info("Deploying and predicting in LOCAL_CONTAINER mode...")
# predictor = model.deploy()
# logger.info("Local container successfully deployed.")
# predictor.predict(test_image)
# except Exception as e:
# logger.exception("test failed")
# caught_ex = e
# finally:
# if model.modes[str(Mode.LOCAL_CONTAINER)].container:
# model.modes[str(Mode.LOCAL_CONTAINER)].container.kill()
# if caught_ex:
# assert (
# False
# ), f"{caught_ex} was thrown when running pytorch squeezenet local container test"


@pytest.mark.skipif(
PYTHON_VERSION_IS_NOT_310, # or NOT_RUNNING_ON_INF_EXP_DEV_PIPELINE,
reason="The goal of these test are to test the serving components of our feature",
PYTHON_VERSION_IS_NOT_310,
tests.integ.test_region() in tests.integ.TRAINING_NO_P2_REGIONS
and tests.integ.test_region() in tests.integ.TRAINING_NO_P3_REGIONS,
reason="no ml.p2 or ml.p3 instances in this region"
)
@pytest.mark.parametrize(
"model_builder", ["model_builder_inference_spec_schema_builder"], indirect=True
Expand All @@ -192,25 +161,25 @@ def model_builder(request):
def test_happy_pytorch_sagemaker_endpoint(
sagemaker_session,
model_builder,
cpu_instance_type,
test_image,
**kwargs
):
logger.info("Running in SAGEMAKER_ENDPOINT mode...")
caught_ex = None

# iam_client = sagemaker_session.boto_session.client("iam")
# role_arn = iam_client.get_role(RoleName=ROLE_NAME)["Role"]["Arn"]

model = model_builder.build(mode=Mode.LOCAL_CONTAINER, sagemaker_session=sagemaker_session)

iam_client = sagemaker_session.boto_session.client("iam")
role_arn = iam_client.get_role(RoleName=ROLE_NAME)["Role"]["Arn"]
model = model_builder.build(role_arn=role_arn, sagemaker_session=sagemaker_session)
with timeout(minutes=SERVE_SAGEMAKER_ENDPOINT_TIMEOUT):
try:
logger.info("Deploying and predicting in SAGEMAKER_ENDPOINT mode...")
predictor = model.deploy()
predictor = model.deploy(
mode=Mode.SAGEMAKER_ENDPOINT,
instance_type=kwargs["instance_type"],
initial_instance_count=1,
)
logger.info("Endpoint successfully deployed.")
predictor.predict(test_image)
except Exception as e:
logger.exception("test failed")
caught_ex = e
finally:
cleanup_model_resources(
Expand All @@ -223,89 +192,3 @@ def test_happy_pytorch_sagemaker_endpoint(
assert (
False
), f"{caught_ex} was thrown when running pytorch squeezenet sagemaker endpoint test"


# @pytest.mark.skipif(
# PYTHON_VERSION_IS_NOT_310,
# reason="The goal of these test are to test the serving components of our feature",
# )
# @pytest.mark.parametrize(
# "model_builder", ["model_builder_inference_spec_schema_builder"], indirect=True
# )
# @pytest.mark.slow_test
# def test_happy_pytorch_local_container_overwrite_to_sagemaker_endpoint(
# sagemaker_session, model_builder, cpu_instance_type, test_image
# ):
# logger.info("Building model in LOCAL_CONTAINER mode...")
# caught_ex = None
#
# iam_client = sagemaker_session.boto_session.client("iam")
# role_arn = iam_client.get_role(RoleName=ROLE_NAME)["Role"]["Arn"]
# logger.debug("Role arn: %s", role_arn)
#
# model = model_builder.build(
# mode=Mode.LOCAL_CONTAINER, role_arn=role_arn, sagemaker_session=sagemaker_session
# )
#
# with timeout(minutes=SERVE_SAGEMAKER_ENDPOINT_TIMEOUT):
# try:
# logger.info("Deploying and predicting in SAGEMAKER_ENDPOINT mode...")
# predictor = model.deploy(
# instance_type=cpu_instance_type,
# initial_instance_count=1,
# mode=Mode.SAGEMAKER_ENDPOINT,
# )
# logger.info("Endpoint successfully deployed.")
# predictor.predict(test_image)
# except Exception as e:
# caught_ex = e
# finally:
# cleanup_model_resources(
# sagemaker_session=model_builder.sagemaker_session,
# model_name=model.name,
# endpoint_name=model.endpoint_name,
# )
# if caught_ex:
# logger.exception(caught_ex)
# assert (
# False
# ), f"{caught_ex} was thrown when running pytorch squeezenet sagemaker endpoint test"


# @pytest.mark.skipif(
# PYTHON_VERSION_IS_NOT_310,
# reason="The goal of these test are to test the serving components of our feature",
# )
# @pytest.mark.parametrize(
# "model_builder", ["model_builder_inference_spec_schema_builder"], indirect=True
# )
# @pytest.mark.slow_test
# def test_happy_pytorch_sagemaker_endpoint_overwrite_to_local_container(
# sagemaker_session, model_builder, test_image
# ):
# logger.info("Building model in SAGEMAKER_ENDPOINT mode...")
# caught_ex = None
#
# iam_client = sagemaker_session.boto_session.client("iam")
# role_arn = iam_client.get_role(RoleName=ROLE_NAME)["Role"]["Arn"]
#
# model = model_builder.build(
# mode=Mode.SAGEMAKER_ENDPOINT, role_arn=role_arn, sagemaker_session=sagemaker_session
# )
#
# with timeout(minutes=SERVE_LOCAL_CONTAINER_TIMEOUT):
# try:
# logger.info("Deploying and predicting in LOCAL_CONTAINER mode...")
# predictor = model.deploy(mode=Mode.LOCAL_CONTAINER)
# logger.info("Local container successfully deployed.")
# predictor.predict(test_image)
# except Exception as e:
# logger.exception("test failed")
# caught_ex = e
# finally:
# if model.modes[str(Mode.LOCAL_CONTAINER)].container:
# model.modes[str(Mode.LOCAL_CONTAINER)].container.kill()
# if caught_ex:
# assert (
# False
# ), f"{caught_ex} was thrown when running pytorch squeezenet local container test"

0 comments on commit 166e03b

Please sign in to comment.