def is_ancestor(op1: Operator, op2: Operator) -> bool:
    """
    Returns whether op1 is an ancestor of op2.
    """

    src_ops = deque([op2])
    visited = set()
    while len(src_ops) > 0:
        src_op = src_ops.popleft()
        if src_op in visited:
            continue
        visited.add(src_op)
        for tensor in src_op._attrs["inputs"]:
            if op1 in tensor._attrs["src_ops"]:
                return True
            src_ops.extend(tensor._attrs["src_ops"])
    return False

    Returns whether op1 is an ancestor of op2.
    
python/aitemplate/compiler/transform/transform_utils.py