def sanitize_sorted_graph(sorted_graph: List[Tensor]) -> List[Tensor]:
    """
    Removes tensors whose src_op and dst_ops are empty.
    Inputs and outputs are always kept in the graph.
    Names unnamed tensors.
    """

    if len(sorted_graph) == 1:
        return sorted_graph

    new_sorted_graph = [
        tensor
        for tensor in sorted_graph
        if (len(tensor._attrs["src_ops"]) > 0)
        or (len(tensor._attrs["dst_ops"]) > 0)
        or tensor._attrs["is_input"]
        or tensor._attrs["is_output"]
    ]
    name_graph(new_sorted_graph)
    mark_param_tensor(new_sorted_graph)
    remove_unused_ops(new_sorted_graph)
    check_graph_validity(new_sorted_graph, raiseError=True)
    return new_sorted_graph

    Removes tensors whose src_op and dst_ops are empty.
    Inputs and outputs are always kept in the graph.
    Names unnamed tensors.
    
python/aitemplate/compiler/transform/transform_utils.py