def _flatten_sub_graph_namespaces(tf_ssa, fn_name):
    """
    A pass to flatten namespaces for sub-graphs of the control flow while_loop
    op. For example, the while_loop's has two sub-graphs, "cond" and "body",
    all the nodes in the graph will be prefixing the sub-graph's name. This
    pass is required for converting control flow v2 ops (enabled by default in
    TensorFlow 2.0+) as the original sub-graphs will contain duplicated names.

    Parameters
    ----------
    tf_ssa: NetworkEnsemble
        An object that contains multiple functions / sub-graphs.
    fn_name: str
        Name of the function / sub-graph to operate on.
    """
    count = 0
    fn = tf_ssa.functions.get(fn_name)
    for name, node in fn.graph.copy().items():
        if node.op not in {"StatelessWhile", "While", "StatelessIf", "If"}:
            continue

        if node.op in {"StatelessWhile", "While"}:
            sub_fn_names = [node.attr.get("cond"), node.attr.get("body")]
        else:
            sub_fn_names = [node.attr.get("then_branch"), node.attr.get("else_branch")]

        for sf_name in sub_fn_names:
            sf = tf_ssa.functions.get(sf_name)
            prefix = "{}/{}".format(node.name, sf_name)

            for old_name, n in sf.graph.copy().items():
                _rename_node_in_fn(n, "{}/{}".format(prefix, old_name), sf)
                count += 1

            ios = set(sf.inputs + sf.outputs)
            io_name_mappings = {n: "{}/{}".format(prefix, n) for n in ios}
            sf.inputs = [io_name_mappings[n] for n in sf.inputs]
            sf.outputs = [io_name_mappings[n] for n in sf.outputs]
            _flatten_sub_graph_namespaces(tf_ssa, sf_name)

            msg = "flatten_sub_graph_namespaces: {} nodes renamed in '{}'"
            logger.info(msg.format(count, sf_name))

    A pass to flatten namespaces for sub-graphs of the control flow while_loop
    op. For example, the while_loop's has two sub-graphs, "cond" and "body",
    all the nodes in the graph will be prefixing the sub-graph's name. This
    pass is required for converting control flow v2 ops (enabled by default in
    TensorFlow 2.0+) as the original sub-graphs will contain duplicated names.

    Parameters
    ----------
    tf_ssa: NetworkEnsemble
        An object that contains multiple functions / sub-graphs.
    fn_name: str
        Name of the function / sub-graph to operate on.
    
coremltools/converters/mil/frontend/tensorflow2/tf_graph_pass/rewrite_control_flow_functions.py