示例#1
0
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
    """
    hello_actor = ClassHello.bind()
    original_dag_node = hello_actor.hello.bind()
    _test_deployment_json_serde_helper(
        original_dag_node,
        expected_num_deployments=1,
    )

    model_actor = Model.bind(1)
    original_dag_node = model_actor.forward.bind(1)
    _test_deployment_json_serde_helper(
        original_dag_node,
        expected_num_deployments=1,
    )

    model_actor = Model.bind(1, ratio=0.5)
    original_dag_node = model_actor.forward.bind(1)
    _test_deployment_json_serde_helper(
        original_dag_node,
        expected_num_deployments=1,
    )
示例#2
0
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.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.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.tests.resources.test_modules.Model",
            "args": [1],
            "kwargs": {
                "ratio": 0.5
            },
            "options": {},
            "other_args_to_resolve": {},
            "uuid": original_dag_node.get_stable_uuid(),
        },
    )
示例#3
0
def get_multi_instantiation_class_nested_deployment_arg_dag():
    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)

    return ray_dag, dag_input
示例#4
0
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
示例#5
0
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
示例#6
0
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))
示例#7
0
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
示例#8
0
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))
示例#9
0
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