def test_xgboost_abalone_mme_with_transform_fn(docker_image, opt_ml): customer_script = "abalone_distributed.py" request_body = get_libsvm_request_body() additional_env_vars = [ "SAGEMAKER_BIND_TO_PORT=8080", "SAGEMAKER_SAFE_PORT_RANGE=9000-9999", "SAGEMAKER_MULTI_MODEL=true", ] model_name = "libsvm_pickled" model_data = json.dumps({ "model_name": model_name, "url": "/opt/ml/model/{}".format(model_name) }) with append_transform_fn_to_abalone_script( abalone_path, customer_script) as custom_script_path: with local_mode.serve( customer_script, models_dir, docker_image, opt_ml, source_dir=custom_script_path, additional_env_vars=additional_env_vars, ): load_status_code, _ = local_mode.request( model_data, content_type="application/json", request_url=MME_MODELS_URL.format(model_name), ) assert load_status_code == 200 invoke_status_code, invoke_response_body = local_mode.request( request_body, content_type="text/libsvm", request_url=MME_INVOKE_URL.format(model_name), ) assert invoke_status_code == 200 assert (len(invoke_response_body.split(",")) == len(request_body.split()) + 1 # final column is the bias term ) assert not local_mode.file_exists(opt_ml, "output/failure"), "Failure happened"
def test_xgboost_abalone_inference(docker_image, opt_ml): customer_script = "abalone_distributed.py" request_body = get_libsvm_request_body() with local_mode.serve(customer_script, libsvm_model_dir, docker_image, opt_ml, source_dir=abalone_path): response_status_code, response_body = local_mode.request( request_body, content_type="text/libsvm") assert response_status_code == 200 assert not local_mode.file_exists(opt_ml, "output/failure"), "Failure happened" assert len(response_body.split(",")) == 1
def test_xgboost_abalone_custom_inference_with_transform_fn( docker_image, opt_ml): customer_script = "abalone_distributed.py" request_body = get_libsvm_request_body() with append_transform_fn_to_abalone_script( abalone_path, customer_script) as custom_script_path: with local_mode.serve( customer_script, libsvm_model_dir, docker_image, opt_ml, source_dir=custom_script_path, ): response_status_code, response_body = local_mode.request( request_body, content_type="text/libsvm") assert response_status_code == 200 assert not local_mode.file_exists(opt_ml, "output/failure"), "Failure happened" assert (len(response_body.split(",")) == len(request_body.split()) + 1 # final column is the bias term )
def predict_and_assert_response_length(data, content_type): predict_response = localmode.request(data, content_type=content_type) assert len(predict_response) == len(data)