code: def _process_node(node, aliases, duplicates):
      """
      Takes a node from the tree and searchs for any previously processed
      duplicates.
      If not a duplicate, returns a stage based from that node.
      If a duplicate, the node is replaced with an alias to the dup stage.
      In both cases the tree is removed below this node (and the alias remains).
      """
  
      # generate a unique key from the stack of everything below this reduction
      stack = _post_order(node)
      key = list()
      for item in stack:
          # for operations, just append the name
          # aliases require the id as well since they encapsulate specific
          # tensors and constants
          if type(item[0]) is str and item not in aliases:
              key.append(item[0])
          # For tensor or constant or alias, append type and id.
          else:
              key.append(item[0:2])
      key = tuple(key)
  
      # use the generated key to look for duplicates
      dup_node = duplicates.get(key, False)
      if dup_node:
          # if this is a duplicate, replace the stack with the op node of the
          # original reduction
          node[0] = dup_node
          # no new stage is returned in this case, the node is just converted
          # into an alias
          stack = None
      else:
          # first time seeing this reduction, record it in the dict
          # the last item in the stack will be the reduction op
          duplicates[key] = stack[-1]
          # record which nodes can be aliased
          aliases.add(stack[-1])
  
      # drop any children (children start at position 3)
      while len(node) > 3:
          node.pop()
  
      return stack
  
imports: from __future__ import division
  from future.utils import native_str
  import os.path
  import re
  import traceback
  import numpy
  from pycuda.tools import context_dependent_memoize
  from pytools import memoize
  from neon import logger
  import neon.backends.nervanagpu
  from neon.backends.util.source_module import SourceModule
  from neon.backends.cuda_templates import _ew_template, _stage_template, _fin_template, _init_rand_func, _init_rand_round_func, _finish_rand_func, _common_kepler, _common_urand_gen, _common_frand, _common_round, _common_fp16_to_fp32, _ew_types, _ew_strings, _is_finite, _float_ops, _reduction_ops
  from neon.backends.cuda_batchnorm import _get_bn_fprop_kernel, _get_bn_bprop_kernel
  from neon.backends.kernels.cuda.lookuptable import _get_lut_bprop_kernel, _get_sorting_kernel
label_desc: Use image node_id 4 for calling a global function with example usage: _process_node(node, aliases, duplicates) and returns: stack