def update(self):
        """Update the graph proto with the latest inputs, outputs, initializers, and nodes."""
        node_order = self.topological_sort()

        for idx, graph in enumerate(self.graphs):
            # update the nodes in the graph proto
            nodes = [
                self.nodes[name].proto
                for name in node_order
                if self.nodes[name].graph_idx == idx
                and (len(self.get_consumers(name)) > 0 or self.is_output_producer(name))
            ]

            # update the inputs, outputs, and initializers in the graph proto
            inputs = []
            outputs = []
            initializers = []
            value_infos = []
            for i, io in self.ios.items():
                if io.graph_idx != idx:
                    # not in the current graph
                    continue
                if self.is_output(i):
                    # outputs are handled separately
                    outputs.append(io.proto[0])
                    continue

                if not io.destination:
                    # no consumers, so don't add it to the graph proto
                    continue

                if not (self.is_input(i) or self.is_initializer(i)) and io.proto:
                    # intermediate connections
                    value_infos.append(io.proto[0])
                    continue

                # inputs, initializers
                if self.is_input(i):
                    inputs.append(io.proto[0])
                if self.is_initializer(i):
                    initializers.append(io.proto[-1])

            # update the graph proto
            graph.ClearField("node")
            graph.node.extend(nodes)
            graph.ClearField("input")
            graph.input.extend(inputs)
            graph.ClearField("initializer")
            graph.initializer.extend(initializers)
            graph.ClearField("output")
            graph.output.extend(outputs)
            graph.ClearField("value_info")
            graph.value_info.extend(value_infos)
Update the graph proto with the latest inputs, outputs, initializers, and nodes.
olive/passes/onnx/onnx_dag.py