def remove_identity_nodes(self):
        """Remove identity nodes from the graph."""
        nodes_to_remove = set()
        for node_name in self.get_node_names():
            if self.get_node_op_type(node_name) != "Identity" or self.is_output_producer(node_name):
                continue

            # change the input of consumers to the input of the identity node
            for consumer in self.get_consumers(node_name):
                self.replace_node_input(
                    consumer, self.get_node_outputs(node_name)[0], self.get_node_inputs(node_name)[0]
                )

            # remove the identity node
            nodes_to_remove.add(node_name)

        for node_name in nodes_to_remove:
            self.remove_node(node_name)
        logger.debug("Removed %d Identity nodes", len(nodes_to_remove))
Remove identity nodes from the graph.
olive/passes/onnx/onnx_dag.py