def mark_special_views(sorted_graph: List[Tensor]):
    """
    Associate each tensor with an external tensor if any of the conditions are true:
    1. The tensor is a view-of-a-view of an external tensor.
    2. The tensor is a view of an input, constant or output tensor (i.e. external tensor).

    Parameters
    ----------
    sorted_graph : List[Tensor]
        The graph to mutate.
    """
    for node in sorted_graph:
        view = node._attrs["is_view_of"]
        if view is None:
            continue

        view_orig = view._attrs["external_tensor"]
        if view_orig is not None:
            node._attrs["external_tensor"] = view_orig
            continue

        view_is_input_or_constant = not view.src_ops()
        view_is_output = view._attrs["is_output"]
        if view_is_input_or_constant or view_is_output:
            node._attrs["external_tensor"] = view

    Associate each tensor with an external tensor if any of the conditions are true:
    1. The tensor is a view-of-a-view of an external tensor.
    2. The tensor is a view of an input, constant or output tensor (i.e. external tensor).

    Parameters
    ----------
    sorted_graph : List[Tensor]
        The graph to mutate.
    
python/aitemplate/compiler/transform/mark_param_tensor.py