def model(): model_data = { "model_name": MODEL_NAME, "url": "/opt/ml/models/half_plus_three/model/half_plus_three" } make_load_model_request(json.dumps(model_data)) return MODEL_NAME
def model(): model_data = { 'model_name': MODEL_NAME, 'url': '/opt/ml/models/half_plus_three' } make_load_model_request(json.dumps(model_data)) return MODEL_NAME
def test_load_one_model_two_times(): model_name = 'cifar' model_data = {'model_name': model_name, 'url': '/opt/ml/models/cifar'} code_load, res = make_load_model_request(json.dumps(model_data)) assert code_load == 200 assert 'Successfully loaded model {}'.format(model_name) in res code_load2, res2 = make_load_model_request(json.dumps(model_data)) assert code_load2 == 409 assert 'Model {} is already loaded'.format(model_name) in res2
def test_load_one_model_two_times(): model_name = "cifar" model_data = {"model_name": model_name, "url": "/opt/ml/models/cifar"} code_load, res = make_load_model_request(json.dumps(model_data)) assert code_load == 200 assert "Successfully loaded model {}".format(model_name) in res code_load2, res2 = make_load_model_request(json.dumps(model_data)) assert code_load2 == 409 assert "Model {} is already loaded".format(model_name) in res2
def test_bad_model_reqeust(): bad_model_data = { 'model_name': 'model_name', 'uri': '/opt/ml/models/non-existing' } code, _ = make_load_model_request(json.dumps(bad_model_data)) assert code == 500
def test_bad_model_reqeust(): bad_model_data = { "model_name": "model_name", "uri": "/opt/ml/models/non-existing" } code, _ = make_load_model_request(json.dumps(bad_model_data)) assert code == 500
def test_invalid_model_version(): model_name = 'invalid_version' base_path = '/opt/ml/models/invalid_version' invalid_model_version_data = {'model_name': model_name, 'url': base_path} code, res = make_load_model_request(json.dumps(invalid_model_version_data)) assert code == 404 assert 'Could not find valid base path {} for servable {}'.format( base_path, model_name) in str(res)
def test_load_non_existing_model(): model_name = 'non-existing' base_path = '/opt/ml/models/non-existing' model_data = {'model_name': model_name, 'url': base_path} code, res = make_load_model_request(json.dumps(model_data)) assert code == 404 assert 'Could not find valid base path {} for servable {}'.format( base_path, model_name) in str(res)
def test_invalid_model_version(): model_name = "invalid_version" base_path = "/opt/ml/models/invalid_version" invalid_model_version_data = {"model_name": model_name, "url": base_path} code, res = make_load_model_request(json.dumps(invalid_model_version_data)) assert code == 404 assert "Could not find valid base path {} for servable {}".format( base_path, model_name) in str(res)
def test_load_non_existing_model(): model_name = "non-existing" base_path = "/opt/ml/models/non-existing" model_data = {"model_name": model_name, "url": base_path} code, res = make_load_model_request(json.dumps(model_data)) assert code == 404 assert "Could not find valid base path {} for servable {}".format( base_path, model_name) in str(res)
def test_load_two_models(): model_name_1 = "half_plus_two" model_data_1 = { "model_name": model_name_1, "url": "/opt/ml/models/half_plus_two" } code1, res1 = make_load_model_request(json.dumps(model_data_1)) assert code1 == 200 assert "Successfully loaded model {}".format(model_name_1) in res1 # load second model model_name_2 = "half_plus_three" model_data_2 = { "model_name": model_name_2, "url": "/opt/ml/models/half_plus_three" } code2, res2 = make_load_model_request(json.dumps(model_data_2)) assert code2 == 200 assert "Successfully loaded model {}".format(model_name_2) in res2 # make invocation request to the first model x = {"instances": [1.0, 2.0, 5.0]} code_invoke1, y1 = make_invocation_request(json.dumps(x), model_name_1) y1 = json.loads(y1) assert code_invoke1 == 200 assert y1 == {"predictions": [2.5, 3.0, 4.5]} # make invocation request to the second model for ver in ("123", "124"): code_invoke2, y2 = make_invocation_request(json.dumps(x), "half_plus_three", version=ver) y2 = json.loads(y2) assert code_invoke2 == 200 assert y2 == {"predictions": [3.5, 4.0, 5.5]} code_list, res3 = make_list_model_request() res3 = json.loads(res3) assert len(res3) == 2
def test_load_two_models(): model_name_1 = 'half_plus_two' model_data_1 = { 'model_name': model_name_1, 'url': '/opt/ml/models/half_plus_two' } code1, res1 = make_load_model_request(json.dumps(model_data_1)) assert code1 == 200 assert 'Successfully loaded model {}'.format(model_name_1) in res1 # load second model model_name_2 = 'half_plus_three' model_data_2 = { 'model_name': model_name_2, 'url': '/opt/ml/models/half_plus_three' } code2, res2 = make_load_model_request(json.dumps(model_data_2)) assert code2 == 200 assert 'Successfully loaded model {}'.format(model_name_2) in res2 # make invocation request to the first model x = {'instances': [1.0, 2.0, 5.0]} code_invoke1, y1 = make_invocation_request(json.dumps(x), model_name_1) y1 = json.loads(y1) assert code_invoke1 == 200 assert y1 == {'predictions': [2.5, 3.0, 4.5]} # make invocation request to the second model code_invoke2, y2 = make_invocation_request(json.dumps(x), 'half_plus_three') y2 = json.loads(y2) assert code_invoke2 == 200 assert y2 == {'predictions': [3.5, 4.0, 5.5]} code_list, res3 = make_list_model_request() res3 = json.loads(res3) assert len(res3) == 2
def test_delete_model(): model_name = 'half_plus_three' model_data = { 'model_name': model_name, 'url': '/opt/ml/models/half_plus_three' } code, res = make_load_model_request(json.dumps(model_data)) assert code == 200 assert 'Successfully loaded model {}'.format(model_name) in res x = {'instances': [1.0, 2.0, 5.0]} _, y = make_invocation_request(json.dumps(x), model_name) y = json.loads(y) assert y == {'predictions': [3.5, 4.0, 5.5]} code_unload, res2 = make_unload_model_request(model_name) assert code_unload == 200 code_invoke, y2 = make_invocation_request(json.dumps(x), model_name) y2 = json.loads(y2) assert code_invoke == 404 assert 'Model {} is not loaded yet.'.format(model_name) in str(y2)
def test_delete_model(): model_name = "half_plus_two" model_data = { "model_name": model_name, "url": "/opt/ml/models/half_plus_two" } code, res = make_load_model_request(json.dumps(model_data)) assert code == 200 assert "Successfully loaded model {}".format(model_name) in res x = {"instances": [1.0, 2.0, 5.0]} _, y = make_invocation_request(json.dumps(x), model_name) y = json.loads(y) assert y == {"predictions": [2.5, 3.0, 4.5]} code_unload, res2 = make_unload_model_request(model_name) assert code_unload == 200 code_invoke, y2 = make_invocation_request(json.dumps(x), model_name) y2 = json.loads(y2) assert code_invoke == 404 assert "Model {} is not loaded yet.".format(model_name) in str(y2)