Esempio n. 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
    """
    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(),
        },
    )
Esempio n. 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
    """
    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,
    )
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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))
Esempio n. 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
Esempio n. 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))
Esempio n. 9
0
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)

    with DAGNodeNameGenerator() as node_name_generator:
        serve_root_dag = ray_dag.apply_recursive(
            lambda node: transform_ray_dag_to_serve_dag(
                node, node_name_generator))
    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()
Esempio n. 10
0
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)

    with _DAGNodeNameGenerator() as node_name_generator:
        serve_root_dag = ray_dag.apply_recursive(
            lambda node: transform_ray_dag_to_serve_dag(node, node_name_generator)
        )
    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") == {}
Esempio n. 11
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
Esempio n. 12
0
def test_single_class_with_invalid_deployment_options(serve_instance):
    with pytest.raises(TypeError, match="name must be a string"):
        with InputNode() as dag_input:
            model = Model.options(name=123).bind(2, ratio=0.3)
            _ = model.forward.bind(dag_input)