def refine_graph(sorted_graph: List[Tensor]):
    """Graph pass to dedup operators with same signatures.

    Parameters
    ----------
    sorted_graph : List[Tensor]
        Input graph
    """
    sorted_ops = get_sorted_ops(sorted_graph)

    exist_func = []
    refined_ops = 0
    total_ops = len(sorted_ops)

    refined_ops_set = set()

    for func in sorted_ops:
        found = False
        for f in reversed(exist_func):
            if same_function_type(f, func):
                func._attrs["name"] = f._attrs["name"]
                found = True
                refined_ops += 1
                break
        if not found:
            exist_func.append(func)
        if found:
            refined_ops_set.add(func._attrs["op"])

    _LOGGER.debug(f"refined ops: {refined_ops_set}")
    _LOGGER.info(f"reduced unique ops from {total_ops} to {total_ops - refined_ops}")
Graph pass to dedup operators with same signatures.

Parameters
----------
sorted_graph : List[Tensor]
Input graph
python/aitemplate/compiler/transform/refine_graph.py