def convert_constant_nodes_to_const_ops(tfssa):
    """
    Convert nodes with known constant value to Const nodes
    """
    for fn_key in list(tfssa.functions.keys()):
        f = tfssa.functions[fn_key]
        for k in list(f.graph.keys()):
            v = f.graph.get(k, None)
            if v is None:
                continue
            if v.value is not None:
                v.op = "Const"
                # delete all upstream edges now that this is constant
                inv = v.inputs[:]
                for i in inv:
                    curnode = i
                    nextnode = v.name
                    disconnect_edge(f.graph, curnode, nextnode)

                    # keep deleting upwards as long as it is a chain
                    while curnode is not None:
                        prevnode = None
                        if len(f.graph[curnode].outputs) == 0:
                            if len(f.graph[curnode].inputs) == 1:
                                prevnode = f.graph[curnode].inputs[0]
                            delete_node(f.graph, curnode)
                        curnode = prevnode

    Convert nodes with known constant value to Const nodes
    
coremltools/converters/mil/frontend/tensorflow/tf_graph_pass/delete_constant.py