code: def apply(self, graph):
      # Copy the graph. Don't change the original.
      graph = copy.deepcopy(graph)
  
      matches = True
      while matches:
          for node in graph.nodes.values():
              pattern = ge.SerialPattern(
                  [ge.NodePattern(node.op), ge.NodePattern(node.op)]
              )
              matches, _ = pattern.match(graph, node)
              if matches:
                  # Use op and name from the first node, and output_shape from the last
                  combo = Node(
                      uid=graph.sequence_id(matches),
                      name=node.name,
                      op=node.op,
                      output_shape=matches[-1].output_shape,
                  )
                  combo._caption = node.caption
                  combo.repeat = sum([n.repeat for n in matches])
                  graph.replace(matches, combo)
                  break
      return graph
  
imports: import re
  import copy
  from .graph import Node
  from .None import ge
label_desc: Use image node_id 1 for calling the FoldDuplicates obj's underlying member method code with example usage: obj.apply(graph) and returns: graph