def test_unique_name_reset_upon_build(): ray_dag, _ = get_multi_instantiation_class_deployment_in_init_args_dag() deployments = build(ray_dag) assert deployments[0].name == "Model" assert deployments[1].name == "Model_1" deployments = build(ray_dag) # Assert we don't keep increasing suffix id between build() calls assert deployments[0].name == "Model" assert deployments[1].name == "Model_1"
def test_model_wrappers_in_pipeline(serve_instance): _, path = tempfile.mkstemp() with open(path, "w") as f: json.dump(2, f) predictor_cls = "ray.serve.tests.test_model_wrappers.AdderPredictor" checkpoint_cls = "ray.serve.tests.test_model_wrappers.AdderCheckpoint" with InputNode() as dag_input: m1 = ModelWrapperDeployment.bind( predictor_cls=predictor_cls, # TODO: can't be the raw class right now? checkpoint={ # TODO: can't be the raw object right now? "checkpoint_cls": checkpoint_cls, "uri": path, }, ) dag = m1.predict.bind(dag_input) deployments = build(Ingress.bind(dag)) for d in deployments: d.deploy() resp = requests.post("http://127.0.0.1:8000/ingress", json={"array": [40]}) print(resp.text) resp.raise_for_status() return resp.json() == {"value": [42], "batch_size": 1}
def test_build_func_class_with_class_method_dag(serve_instance): ray_dag, _ = get_func_class_with_class_method_dag() deployments = build(ray_dag) for deployment in deployments: deployment.deploy() for _ in range(5): resp = requests.get("http://127.0.0.1:8000/ingress", data=json.dumps([1, 2, 3])) assert resp.text == "8"
def test_build_simple_class_with_class_method_dag(serve_instance): ray_dag, _ = get_simple_class_with_class_method_dag() deployments = build(ray_dag) for deployment in deployments: deployment.deploy() for _ in range(5): resp = requests.get("http://127.0.0.1:8000/ingress", data="1") assert resp.text == "0.6"
def test_build_shared_deployment_handle(serve_instance): """ Test we can re-use the same deployment handle multiple times or in multiple places, without incorrectly parsing duplicated deployments. """ ray_dag, _ = get_shared_deployment_handle_dag() deployments = build(ray_dag) for deployment in deployments: deployment.deploy() for _ in range(5): resp = requests.get("http://127.0.0.1:8000/ingress", data="1") assert resp.text == "4"
def test_build_multi_instantiation_class_nested_deployment_arg(serve_instance): """ Test we can pass deployments with **nested** init_arg or init_kwarg, instantiated multiple times for the same class, and we can still correctly replace args with deployment handle and parse correct deployment instances. """ ray_dag, _ = get_multi_instantiation_class_nested_deployment_arg_dag() deployments = build(ray_dag) for deployment in deployments: deployment.deploy() for _ in range(5): resp = requests.get("http://127.0.0.1:8000/ingress", data="1") assert resp.text == "5"