code: def collapse_sequence(graph, sequence):
      exclude_nodes = []
  
      for node in graph.nodes:
          remainder = sequence[:]
          matches = []
          while remainder:
              if node.op == remainder[0]:
                  matches.append(node.name)
                  remainder = remainder[1:]
              else:
                  break
  
              if len(remainder):
                  if len(node.consumers) != 1:
                      break
                  node = list(node.consumers)[0]
  
          if len(remainder) == 0:
              exclude_nodes += matches[:-1]
  
      include_nodes = [
          node.name
          for node in graph.nodes
          if node.name not in exclude_nodes
      ]
  
      return graph.filter(include_nodes)
  
label_desc: Use image node_id 4 for calling a global function with example usage: collapse_sequence(graph, sequence) and returns: graph