def get_multi_instantiation_class_deployment_in_init_args_dag(): with InputNode() as dag_input: m1 = Model.bind(2) m2 = Model.bind(3) combine = Combine.bind(m1, m2=m2) ray_dag = combine.__call__.bind(dag_input) return ray_dag, dag_input
def get_multi_instantiation_class_nested_deployment_arg_dag(): with PipelineInputNode(preprocessor=request_to_data_int) as dag_input: m1 = Model.bind(2) m2 = Model.bind(3) combine = Combine.bind(m1, m2={NESTED_HANDLE_KEY: m2}, m2_nested=True) ray_dag = combine.__call__.bind(dag_input) return ray_dag, dag_input
def get_multi_instantiation_class_deployment_in_init_args_dag(): with PipelineInputNode(preprocessor=request_to_data_int) as dag_input: m1 = Model.bind(2) m2 = Model.bind(3) combine = Combine.bind(m1, m2=m2) ray_dag = combine.__call__.bind(dag_input) return ray_dag, dag_input
def test_simple_class_node_json_serde(serve_instance): """ Test the following behavior 1) Ray DAG node can go through full JSON serde cycle 2) Ray DAG node and deserialized DAG node produces same actor instances with same method call output 3) Ray DAG node can go through multiple rounds of JSON serde and still provides the same value as if it's only JSON serde once Against following test cases - Simple class with no args - Simple class with only args, all primitive types - Simple class with args + kwargs, all primitive types - Simple chain of class method calls, all primitive types """ original_dag_node = ClassHello.bind() _test_json_serde_helper( original_dag_node, executor_fn=_test_execution_class_node_ClassHello, expected_json_dict={ DAGNODE_TYPE_KEY: "ClassNode", "import_path": "ray.serve.pipeline.tests.resources.test_modules.ClassHello", "args": [], "kwargs": {}, "options": {}, "other_args_to_resolve": {}, "uuid": original_dag_node.get_stable_uuid(), }, ) original_dag_node = Model.bind(1) _test_json_serde_helper( original_dag_node, executor_fn=_test_execution_class_node_Model, expected_json_dict={ DAGNODE_TYPE_KEY: "ClassNode", "import_path": "ray.serve.pipeline.tests.resources.test_modules.Model", "args": [1], "kwargs": {}, "options": {}, "other_args_to_resolve": {}, "uuid": original_dag_node.get_stable_uuid(), }, ) original_dag_node = Model.bind(1, ratio=0.5) _test_json_serde_helper( original_dag_node, executor_fn=_test_execution_class_node_Model, expected_json_dict={ DAGNODE_TYPE_KEY: "ClassNode", "import_path": "ray.serve.pipeline.tests.resources.test_modules.Model", "args": [1], "kwargs": {"ratio": 0.5}, "options": {}, "other_args_to_resolve": {}, "uuid": original_dag_node.get_stable_uuid(), }, )
def get_func_class_with_class_method_dag(): with PipelineInputNode(preprocessor=request_to_data_obj) as dag_input: m1 = Model.bind(1) m2 = Model.bind(2) m1_output = m1.forward.bind(dag_input[0]) m2_output = m2.forward.bind(dag_input[1]) ray_dag = combine.bind(m1_output, m2_output, kwargs_output=dag_input[2]) return ray_dag, dag_input
def get_func_class_with_class_method_dag(): with InputNode() as dag_input: m1 = Model.bind(1) m2 = Model.bind(2) m1_output = m1.forward.bind(dag_input[0]) m2_output = m2.forward.bind(dag_input[1]) ray_dag = combine.bind(m1_output, m2_output, kwargs_output=dag_input[2]) return ray_dag, dag_input
def test_multi_instantiation_class_nested_deployment_arg(serve_instance): with InputNode() as dag_input: m1 = Model.bind(2) m2 = Model.bind(3) combine = Combine.bind(m1, m2={NESTED_HANDLE_KEY: m2}, m2_nested=True) ray_dag = combine.__call__.bind(dag_input) ( serve_root_dag, deserialized_serve_root_dag_node, ) = _test_deployment_json_serde_helper(ray_dag, input=1, expected_num_deployments=3) assert ray.get(serve_root_dag.execute(1)) == ray.get( deserialized_serve_root_dag_node.execute(1) )
def get_shared_deployment_handle_dag(): with PipelineInputNode(preprocessor=request_to_data_int) as dag_input: m = Model.bind(2) combine = Combine.bind(m, m2=m) ray_dag = combine.__call__.bind(dag_input) return ray_dag, dag_input
def get_shared_deployment_handle_dag(): with InputNode() as dag_input: m = Model.bind(2) combine = Combine.bind(m, m2=m) ray_dag = combine.__call__.bind(dag_input) return ray_dag, dag_input
def test_nested_deployment_node_json_serde(serve_instance): with InputNode() as dag_input: m1 = Model.bind(2) m2 = Model.bind(3) m1_output = m1.forward.bind(dag_input) m2_output = m2.forward.bind(dag_input) ray_dag = combine.bind(m1_output, m2_output) ( serve_root_dag, deserialized_serve_root_dag_node, ) = _test_deployment_json_serde_helper(ray_dag, input=1, expected_num_deployments=2) assert ray.get(serve_root_dag.execute(1)) == ray.get( deserialized_serve_root_dag_node.execute(1) )
def test_chain_of_values(): with InputNode() as dag_input: out = fn.bind(1) out_2 = fn.bind(out, incr=2) out_val = fn.bind(out_2, incr=3) model = Model.bind(out_val) ray_dag = model.forward.bind(dag_input) json_serialized = json.dumps(ray_dag, cls=DAGNodeEncoder) deserialized_dag_node = json.loads(json_serialized, object_hook=dagnode_from_json) assert ray.get(deserialized_dag_node.execute(2)) == ray.get(ray_dag.execute(2))
def test_single_class_with_invalid_deployment_options(serve_instance): with InputNode() as dag_input: model = Model.options(name="my_deployment").bind(2, ratio=0.3) ray_dag = model.forward.bind(dag_input) serve_root_dag = ray_dag.apply_recursive(transform_ray_dag_to_serve_dag) deployments = extract_deployments_from_serve_dag(serve_root_dag) assert len(deployments) == 1 with pytest.raises( ValueError, match="Specifying name in ray_actor_options is not allowed"): deployments[0].deploy()
def test_single_class_with_valid_ray_options(serve_instance): with InputNode() as dag_input: model = Model.options(num_cpus=1, memory=1000).bind(2, ratio=0.3) ray_dag = model.forward.bind(dag_input) serve_root_dag = ray_dag.apply_recursive(transform_ray_dag_to_serve_dag) deployments = extract_deployments_from_serve_dag(serve_root_dag) assert len(deployments) == 1 deployments[0].deploy() _validate_consistent_python_output(deployments[0], ray_dag, deployments[0].name, input=1, output=0.6) deployment = serve.get_deployment(deployments[0].name) assert deployment.ray_actor_options.get("num_cpus") == 1 assert deployment.ray_actor_options.get("memory") == 1000 assert deployment.ray_actor_options.get("runtime_env") == {}
def get_simple_class_with_class_method_dag(): with PipelineInputNode(preprocessor=request_to_data_int) as dag_input: model = Model.bind(2, ratio=0.3) ray_dag = model.forward.bind(dag_input) return ray_dag, dag_input
def get_simple_class_with_class_method_dag(): with InputNode() as dag_input: model = Model.bind(2, ratio=0.3) ray_dag = model.forward.bind(dag_input) return ray_dag, dag_input