code: def fuse_gelu_tanh_approximation(prog):
      """
      Identify the pattern that corresponds to the tanh approximate version of gelu, and replace it with a single
      gelu layer with mode=TANH_APPROXIMATION
  
      y = ( tanh((.0447)x^3 + x ) * (sqrt(2/pi)) + 1 ) * 0.5 * x
  
      [...] -----> pow (3) ----> mul (.044715) ---> add -----> mul (sqrt(2/pi)) ---> tanh ----> add (1) ----> mul (0.5) -----> mul ---> [...]
        |                                            ^                                                                          ^
        |                                            |                                                                          |
        |------------------------------------------------------------------------------------------------------------------------
  
  
      """
      for f_name, f in prog.functions.items():
          block_changed = True
          while block_changed:
              block_changed = fuse_gelu_tanh_block(f)
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/mil/passes/gelu_tanh_approximation_fusion.py
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  from coremltools.converters.mil.mil.passes.pass_registry import register_pass
  from coremltools.converters.mil.mil import Builder
  import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: fuse_gelu_tanh_approximation(prog) without return types