def test_deploy_model(mxnet_training_job, sagemaker_session):
    endpoint_name = 'test-mxnet-deploy-model-{}'.format(sagemaker_timestamp())

    with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
        desc = sagemaker_session.sagemaker_client.describe_training_job(
            TrainingJobName=mxnet_training_job)
        model_data = desc['ModelArtifacts']['S3ModelArtifacts']
        script_path = os.path.join(DATA_DIR, 'mxnet_mnist', 'mnist_neo.py')
        role = 'SageMakerRole'
        model = MXNetModel(model_data,
                           role,
                           entry_point=script_path,
                           py_version=PYTHON_VERSION,
                           sagemaker_session=sagemaker_session)

        model.compile(target_instance_family='ml_m4',
                      input_shape={'data': [1, 1, 28, 28]},
                      role=role,
                      job_name='test-deploy-model-compilation-job-{}'.format(
                          int(time.time())),
                      output_path='/'.join(model_data.split('/')[:-1]))
        predictor = model.deploy(1,
                                 'ml.m4.xlarge',
                                 endpoint_name=endpoint_name)

        predictor.content_type = "application/vnd+python.numpy+binary"
        data = numpy.zeros(shape=(1, 1, 28, 28))
        predictor.predict(data)
Exemple #2
0
def test_inferentia_deploy_model(mxnet_training_job, sagemaker_session,
                                 inf_instance_type, inf_instance_family):
    endpoint_name = unique_name_from_base("test-neo-deploy-model")

    with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
        desc = sagemaker_session.sagemaker_client.describe_training_job(
            TrainingJobName=mxnet_training_job)
        model_data = desc["ModelArtifacts"]["S3ModelArtifacts"]
        script_path = os.path.join(DATA_DIR, "mxnet_mnist", "mnist_neo.py")
        role = "SageMakerRole"
        model = MXNetModel(
            model_data,
            role,
            entry_point=script_path,
            framework_version=INF_MXNET_VERSION,
            sagemaker_session=sagemaker_session,
        )

        model.compile(
            target_instance_family=inf_instance_family,
            input_shape={"data": [1, 1, 28, 28]},
            role=role,
            job_name=unique_name_from_base(
                "test-deploy-model-compilation-job"),
            output_path="/".join(model_data.split("/")[:-1]),
        )
        predictor = model.deploy(1,
                                 inf_instance_type,
                                 endpoint_name=endpoint_name)

        predictor.content_type = "application/vnd+python.numpy+binary"
        data = numpy.zeros(shape=(1, 1, 28, 28))
        predictor.predict(data)
def test_deploy_model(mxnet_training_job, sagemaker_session, cpu_instance_type,
                      cpu_instance_family):
    endpoint_name = "test-mxnet-deploy-model-{}".format(sagemaker_timestamp())

    with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
        desc = sagemaker_session.sagemaker_client.describe_training_job(
            TrainingJobName=mxnet_training_job)
        model_data = desc["ModelArtifacts"]["S3ModelArtifacts"]
        script_path = os.path.join(DATA_DIR, "mxnet_mnist", "mnist_neo.py")
        role = "SageMakerRole"
        model = MXNetModel(
            model_data,
            role,
            entry_point=script_path,
            py_version=PYTHON_VERSION,
            sagemaker_session=sagemaker_session,
        )

        model.compile(
            target_instance_family=cpu_instance_family,
            input_shape={"data": [1, 1, 28, 28]},
            role=role,
            job_name="test-deploy-model-compilation-job-{}".format(
                int(time.time())),
            output_path="/".join(model_data.split("/")[:-1]),
        )
        predictor = model.deploy(1,
                                 cpu_instance_type,
                                 endpoint_name=endpoint_name)

        predictor.content_type = "application/vnd+python.numpy+binary"
        data = numpy.zeros(shape=(1, 1, 28, 28))
        predictor.predict(data)
def test_deploy_model(
    mxnet_training_job,
    sagemaker_session,
    cpu_instance_type,
    cpu_instance_family,
    neo_mxnet_latest_version,
    neo_mxnet_latest_py_version,
):
    endpoint_name = unique_name_from_base("test-neo-deploy-model")

    with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session):
        desc = sagemaker_session.sagemaker_client.describe_training_job(
            TrainingJobName=mxnet_training_job)
        model_data = desc["ModelArtifacts"]["S3ModelArtifacts"]
        script_path = os.path.join(DATA_DIR, "mxnet_mnist", "mnist_neo.py")
        role = "SageMakerRole"
        model = MXNetModel(
            model_data,
            role,
            entry_point=script_path,
            py_version=neo_mxnet_latest_py_version,
            framework_version=neo_mxnet_latest_version,
            sagemaker_session=sagemaker_session,
        )

        serializer = JSONSerializer()
        serializer.CONTENT_TYPE = "application/vnd+python.numpy+binary"

        model.compile(
            target_instance_family=cpu_instance_family,
            input_shape={
                "data": [1, 1, 28, 28],
                "softmax_label": [1]
            },
            role=role,
            job_name=unique_name_from_base(
                "test-deploy-model-compilation-job"),
            output_path="/".join(model_data.split("/")[:-1]),
        )
        predictor = model.deploy(1,
                                 cpu_instance_type,
                                 serializer=serializer,
                                 endpoint_name=endpoint_name)

        data = numpy.zeros(shape=(1, 1, 28, 28))
        predictor.predict(data)