def dump_program(
    sorted_graph: Union[Tensor, List[Tensor]],
    file_path: str,
    indent: str = "    ",
    random_constants: bool = False,
):
    """This function dumps out an AIT sorted graph to an executable python code.

    Parameters
    ----------
    sorted_graph : Union[Tensor, List[Tensor]]
        Final tensor(s) that are associated to the AIT graph.
    file_path: str
        Location for the python file to be dumped.
    indent: str, optional
        The indentation to be used in python code, default is 4 spaces.
    random_constants: bool, optional
        Assign random values for constants, default is False.
    """
    if isinstance(sorted_graph, Tensor):
        sorted_graph = [sorted_graph]
    try:
        sorted_graph = copy.deepcopy(sorted_graph)
    except RecursionError:
        default = sys.getrecursionlimit()
        new_recursion_limit = default * 10
        _LOGGER.info(
            f"Recursion error when copying graph with default recursion limit {default}. Will try again with {new_recursion_limit}"
        )
        sys.setrecursionlimit(new_recursion_limit)
        sorted_graph = copy.deepcopy(sorted_graph)

    # Make sure the graph is in correct order and has names and param set correctly.
    sorted_graph = toposort(sorted_graph)
    mark_param_tensor(sorted_graph)
    name_graph(sorted_graph)

    params_set = set()
    inputs_str = []
    consts_str = []
    default_const_vals = []
    op_str = []
    inputs_info = {}
    consts_info = {}
    outputs = []
    visited_ops = set()
    for tensor in sorted_graph:
        if tensor._attrs["is_input"]:
            inputs_str.append(convert_to_param_str(tensor))
            inputs_info[tensor._attrs["name"]] = convert_to_info_str(tensor.shape())
            params_set.add(tensor._attrs["name"])
            continue
        if tensor._attrs["is_param"]:
            # This is the case that the tensor is some constant.
            consts_str.append(convert_to_param_str(tensor))
            consts_info[tensor._attrs["name"]] = convert_to_info_str(
                tensor.shape(), is_constant=True
            )
            if tensor._attrs["data"] is not None and not random_constants:
                default_const_vals.append(convert_to_default_const_val_str(tensor))
            params_set.add(tensor._attrs["name"])
            continue

        if tensor._attrs["is_output"]:
            outputs.append(tensor._attrs["name"])

        src_ops = tensor.src_ops()
        for src_op in src_ops:
            if src_op in visited_ops:
                continue
            visited_ops.add(src_op)
            op_str.append(convert_to_op_str(src_op, params_set))

    program = PROGRAM_TEMPLATE.render(
        indent=indent,
        inputs=inputs_str,
        inputs_info=inputs_info,
        consts_info=consts_info,
        consts=consts_str,
        default_const_vals=default_const_vals,
        ops=op_str,
        outputs=outputs,
    )

    if file_path != "":
        dirs = os.path.dirname(file_path)
        if dirs != "":
            os.makedirs(dirs, exist_ok=True)
        with open(file_path, "w") as f:
            f.write(program)

    return program
This function dumps out an AIT sorted graph to an executable python code.

    Parameters
    ----------
    sorted_graph : Union[Tensor, List[Tensor]]
        Final tensor(s) that are associated to the AIT graph.
    file_path: str
        Location for the python file to be dumped.
    indent: str, optional
        The indentation to be used in python code, default is 4 spaces.
    random_constants: bool, optional
        Assign random values for constants, default is False.
    
python/aitemplate/utils/serialization/serdes_code.py