python/ray/serve/pipeline/generate.py
def transform_ray_dag_to_serve_dag(
    dag_node: DAGNode, deployment_name_generator: DeploymentNameGenerator
):
    """
    Transform a Ray DAG to a Serve DAG. Map ClassNode to DeploymentNode with
    ray decorated body passed in, and ClassMethodNode to DeploymentMethodNode.
    """
    if isinstance(dag_node, ClassNode):
        deployment_name = deployment_name_generator.get_deployment_name(dag_node)
        return DeploymentNode(
            dag_node._body,
            deployment_name,
            dag_node.get_args(),
            dag_node.get_kwargs(),
            dag_node.get_options(),
            # TODO: (jiaodong) Support .options(metadata=xxx) for deployment
            other_args_to_resolve=dag_node.get_other_args_to_resolve(),
        )

    elif isinstance(dag_node, ClassMethodNode):
        other_args_to_resolve = dag_node.get_other_args_to_resolve()
        # TODO: (jiaodong) Need to capture DAGNodes in the parent node
        parent_deployment_node = other_args_to_resolve[PARENT_CLASS_NODE_KEY]

        return DeploymentMethodNode(
            parent_deployment_node._deployment,
            dag_node._method_name,
            dag_node.get_args(),
            dag_node.get_kwargs(),
            dag_node.get_options(),
            other_args_to_resolve=dag_node.get_other_args_to_resolve(),
        )
    elif isinstance(
        dag_node,
        FunctionNode
        # TODO (jiaodong): We do not convert ray function to deployment function
        # yet, revisit this later
    ) and dag_node.get_other_args_to_resolve().get("is_from_serve_deployment"):
        deployment_name = deployment_name_generator.get_deployment_name(dag_node)
        return DeploymentFunctionNode(
            dag_node._body,
            deployment_name,
            dag_node.get_args(),
            dag_node.get_kwargs(),
            dag_node.get_options(),
            other_args_to_resolve=dag_node.get_other_args_to_resolve(),
        )
    else:
        # TODO: (jiaodong) Support FunctionNode or leave it as ray task
        return dag_node

    Transform a Ray DAG to a Serve DAG. Map ClassNode to DeploymentNode with
    ray decorated body passed in, and ClassMethodNode to DeploymentMethodNode.
    
Transform a Ray DAG to a Serve DAG. Map ClassNode to DeploymentNode with
ray decorated body passed in, and ClassMethodNode to DeploymentMethodNode.
Transform a Ray DAG to a Serve DAG . Map ClassNode to DeploymentNode with ray decorated body passed in and ClassMethodNode to DeploymentMethodNode .
def transform_ray_dag_to_serve_dag(
    dag_node: DAGNode, deployment_name_generator: DeploymentNameGenerator
):
    if isinstance(dag_node, ClassNode):
        deployment_name = deployment_name_generator.get_deployment_name(dag_node)
        return DeploymentNode(
            dag_node._body,
            deployment_name,
            dag_node.get_args(),
            dag_node.get_kwargs(),
            dag_node.get_options(),
            other_args_to_resolve=dag_node.get_other_args_to_resolve(),
        )
    elif isinstance(dag_node, ClassMethodNode):
        other_args_to_resolve = dag_node.get_other_args_to_resolve()
        parent_deployment_node = other_args_to_resolve[PARENT_CLASS_NODE_KEY]
        return DeploymentMethodNode(
            parent_deployment_node._deployment,
            dag_node._method_name,
            dag_node.get_args(),
            dag_node.get_kwargs(),
            dag_node.get_options(),
            other_args_to_resolve=dag_node.get_other_args_to_resolve(),
        )
    elif isinstance(
        dag_node,
        FunctionNode
    ) and dag_node.get_other_args_to_resolve().get("is_from_serve_deployment"):
        deployment_name = deployment_name_generator.get_deployment_name(dag_node)
        return DeploymentFunctionNode(
            dag_node._body,
            deployment_name,
            dag_node.get_args(),
            dag_node.get_kwargs(),
            dag_node.get_options(),
            other_args_to_resolve=dag_node.get_other_args_to_resolve(),
        )
    else:
        return dag_node
def transform_ray_dag_to_serve_dag ( dag_node : DAGNode , deployment_name_generator : DeploymentNameGenerator ) : if isinstance ( dag_node , ClassNode ) : deployment_name = deployment_name_generator . get_deployment_name ( dag_node ) return DeploymentNode ( dag_node . _body , deployment_name , dag_node . get_args ( ) , dag_node . get_kwargs ( ) , dag_node . get_options ( ) , other_args_to_resolve = dag_node . get_other_args_to_resolve ( ) , ) elif isinstance ( dag_node , ClassMethodNode ) : other_args_to_resolve = dag_node . get_other_args_to_resolve ( ) parent_deployment_node = other_args_to_resolve [ PARENT_CLASS_NODE_KEY ] return DeploymentMethodNode ( parent_deployment_node . _deployment , dag_node . _method_name , dag_node . get_args ( ) , dag_node . get_kwargs ( ) , dag_node . get_options ( ) , other_args_to_resolve = dag_node . get_other_args_to_resolve ( ) , ) elif isinstance ( dag_node , FunctionNode ) and dag_node . get_other_args_to_resolve ( ) . get ( "is_from_serve_deployment" ) : deployment_name = deployment_name_generator . get_deployment_name ( dag_node ) return DeploymentFunctionNode ( dag_node . _body , deployment_name , dag_node . get_args ( ) , dag_node . get_kwargs ( ) , dag_node . get_options ( ) , other_args_to_resolve = dag_node . get_other_args_to_resolve ( ) , ) else : return dag_node
Transform a Ray DAG to a Serve DAG.
Transform a Ray DAG to a Serve DAG .
"""
    Transform a Ray DAG to a Serve DAG. Map ClassNode to DeploymentNode with
    ray decorated body passed in, and ClassMethodNode to DeploymentMethodNode.
    """ # TODO: (jiaodong) Support .options(metadata=xxx) for deployment # TODO: (jiaodong) Need to capture DAGNodes in the parent node # TODO (jiaodong): We do not convert ray function to deployment function # yet, revisit this later # TODO: (jiaodong) Support FunctionNode or leave it as ray task
dag_node
DAGNode
deployment_name_generator
DeploymentNameGenerator