def _test_mnist_deploy(sagemaker_session, instance_type): model_path = 'test/resources/mnist/model.tar.gz' script_path = 'test/resources/mnist/mnist.py' endpoint_name = sagemaker.utils.unique_name_from_base( 'sagemaker-chainer-test') model_data = sagemaker_session.upload_data( path=model_path, key_prefix='sagemaker-chainer/models', ) with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session, minutes=30): chainer = ChainerModel( model_data=model_data, role='SageMakerRole', entry_point=script_path, sagemaker_session=sagemaker_session, ) predictor = chainer.deploy(initial_instance_count=1, instance_type=instance_type) batch_size = 100 data = np.zeros(shape=(batch_size, 1, 28, 28), dtype='float32') output = predictor.predict(data) assert len(output) == batch_size
def test_deploy_model(chainer_training_job, sagemaker_session): endpoint_name = 'test-chainer-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=chainer_training_job) model_data = desc['ModelArtifacts']['S3ModelArtifacts'] script_path = os.path.join(DATA_DIR, 'chainer_mnist', 'mnist.py') model = ChainerModel(model_data, 'SageMakerRole', entry_point=script_path, sagemaker_session=sagemaker_session) predictor = model.deploy(1, "ml.m4.xlarge", endpoint_name=endpoint_name) _predict_and_assert(predictor)
def test_deploy_model(chainer_training_job, sagemaker_session): endpoint_name = 'test-chainer-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=chainer_training_job) model_data = desc['ModelArtifacts']['S3ModelArtifacts'] script_path = os.path.join(DATA_DIR, 'chainer_mnist', 'mnist.py') model = ChainerModel(model_data, 'SageMakerRole', entry_point=script_path, sagemaker_session=sagemaker_session) predictor = model.deploy(1, "ml.m4.xlarge", endpoint_name=endpoint_name) _predict_and_assert(predictor)
def test_deploy_model(chainer_local_training_job, sagemaker_local_session): script_path = os.path.join(DATA_DIR, "chainer_mnist", "mnist.py") model = ChainerModel( chainer_local_training_job.model_data, "SageMakerRole", entry_point=script_path, sagemaker_session=sagemaker_local_session, ) predictor = model.deploy(1, "local") try: _predict_and_assert(predictor) finally: predictor.delete_endpoint()
def test_deploy_model(chainer_training_job, sagemaker_session): endpoint_name = unique_name_from_base("test-chainer-deploy-model") with timeout_and_delete_endpoint_by_name(endpoint_name, sagemaker_session): desc = sagemaker_session.sagemaker_client.describe_training_job( TrainingJobName=chainer_training_job) model_data = desc["ModelArtifacts"]["S3ModelArtifacts"] script_path = os.path.join(DATA_DIR, "chainer_mnist", "mnist.py") model = ChainerModel( model_data, "SageMakerRole", entry_point=script_path, sagemaker_session=sagemaker_session, ) predictor = model.deploy(1, "ml.m4.xlarge", endpoint_name=endpoint_name) _predict_and_assert(predictor)