class_docstr: Identify the pattern that corresponds to the ``tanh`` approximate version of ``gelu``, and replace it
  with a single ``gelu`` layer with ``mode=TANH_APPROXIMATION``.
  
  The implementation of this pass uses the generic graph pattern matching and transform algorithm
  implemented in ``coremltools.converters.mil.experimental.passes.generic_pass_infrastructure`` and
  documented in ``coremltools/converters/mil/experimental/passes/readme.md``.
  
  `Graph for` ``get_gelu_pattern1()``
  
  ``y = x * (0.5 * (tanh(((.0447)x^3 + x ) * sqrt(2/pi)) + 1))``
  
  .. code-block::
  
          [...] -----> pow (3) ----> mul (.044715) ---> add -----> mul (sqrt(2/pi)) ---> tanh ----> add (1) ----> mul (0.5) -----> mul ---> [...]
            |                                            ^                                                                          ^
            |                                            |                                                                          |
            |------------------------------------------------------------------------------------------------------------------------
  
  
  `Graph for` ``get_gelu_pattern2()``
  
  ``y = (0.5 * x) * (tanh(((.0447)x^3 + x ) * sqrt(2/pi)) + 1)``
  
  .. code-block::
  
                     --------------------------------------------------------------------------------------------------------
                     ^                                                                                                      |
                     |                                                                                                      V
      [...] -----> mul(0.5)    pow (3) ----> mul (.044715) ---> add -----> mul (sqrt(2/pi)) ---> tanh ----> add (1) -----> mul ---> [...]
        |                        ^                               ^
        |                        |                               |
        |---------------------------------------------------------
class_docstr_tok: ["Identify","the","pattern","that","corresponds","to","the","``","tanh","``","approximate","version","of","``","gelu","``",",","and","replace","it","with","a","single","``","gelu","``","layer","with","``","mode=TANH_APPROXIMATION","``",".","The","implementation","of","this","pass","uses","the","generic","graph","pattern","matching","and","transform","algorithm","implemented","in","``","coremltools.converters.mil.experimental.passes.generic_pass_infrastructure","``","and","documented","in","``","coremltools\/converters\/mil\/experimental\/passes\/readme.md","``",".","`","Graph","for","`","``","get_gelu_pattern1","(",")","``","``","y","=","x","*","(","0.5","*","(","tanh","(","(","(",".0447",")","x^3","+","x",")","*","sqrt","(","2\/pi",")",")","+","1",")",")","``","..","code-block",":",":","[","...","]","--","--","-",">","pow","(","3",")","--","--",">","mul","(",".044715",")","--","-",">","add","--","--","-",">","mul","(","sqrt","(","2\/pi",")",")","--","-",">","tanh","--","--",">","add","(","1",")","--","--",">","mul","(","0.5",")","--","--","-",">","mul","--","-",">","[","...","]","|","^","^","|","|","|","|","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","`","Graph","for","`","``","get_gelu_pattern2","(",")","``","``","y","=","(","0.5","*","x",")","*","(","tanh","(","(","(",".0447",")","x^3","+","x",")","*","sqrt","(","2\/pi",")",")","+","1",")","``","..","code-block",":",":","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","^","|","|","V","[","...","]","--","--","-",">","mul","(","0.5",")","pow","(","3",")","--","--",">","mul","(",".044715",")","--","-",">","add","--","--","-",">","mul","(","sqrt","(","2\/pi",")",")","--","-",">","tanh","--","--",">","add","(","1",")","--","--","-",">","mul","--","-",">","[","...","]","|","^","^","|","|","|","|","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","-"]
docstr: ``y = x * (0.5 * (tanh(((.0447)x^3 + x ) * sqrt(2/pi)) + 1))``
  
  .. code-block::
  
                  [...] -----> pow (3) ----> mul (.044715) ---> add -----> mul (sqrt(2/pi)) ---> tanh ----> add (1) ----> mul (0.5) -----> mul ---> [...]
                    |                                            ^                                                                          ^
                    |                                            |                                                                          |
                    |------------------------------------------------------------------------------------------------------------------------
docstr_tok: ["``","y","=","x","*","(","0.5","*","(","tanh","(","(","(",".0447",")","x^3","+","x",")","*","sqrt","(","2\/pi",")",")","+","1",")",")","``","..","code-block",":",":","[","...","]","--","--","-",">","pow","(","3",")","--","--",">","mul","(",".044715",")","--","-",">","add","--","--","-",">","mul","(","sqrt","(","2\/pi",")",")","--","-",">","tanh","--","--",">","add","(","1",")","--","--",">","mul","(","0.5",")","--","--","-",">","mul","--","-",">","[","...","]","|","^","^","|","|","|","|","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--"]
code: def get_gelu_pattern1():
      """
      ``y = x * (0.5 * (tanh(((.0447)x^3 + x ) * sqrt(2/pi)) + 1))``
  
      .. code-block::
  
                      [...] -----> pow (3) ----> mul (.044715) ---> add -----> mul (sqrt(2/pi)) ---> tanh ----> add (1) ----> mul (0.5) -----> mul ---> [...]
                        |                                            ^                                                                          ^
                        |                                            |                                                                          |
                        |------------------------------------------------------------------------------------------------------------------------
  
      """
  
      @mb.program(
          input_specs=[
              mb.TensorSpec(
                  shape=(
                      [
                          get_new_symbol(),
                          get_new_symbol(),
                          get_new_symbol(),
                      ]
                  )
              ),
          ]
      )
      def gelu_to_detect_1(x):
          # MIL operation takes named inputs (instead of positional inputs).
          # Here `name` argument is MANDATORY.
          pow = mb.pow(x=x, y=3.0, name="pow")
          mul_1 = mb.mul(x=0.044714998453855515, y=pow, name="mul_1")
          add = mb.add(x=x, y=mul_1, name="add")
          mul_2 = mb.mul(x=0.7978845834732056, y=add, name="mul_2")
          tanh = mb.tanh(x=mul_2, name="tanh")
          add_1 = mb.add(x=1.0, y=tanh, name="add_1")
          mul = mb.mul(x=0.5, y=add_1, name="mul")
          mul_3 = mb.mul(x=mul, y=x, name="mul_3")
          return mul_3
  
      return gelu_to_detect_1
  
imports: import numpy
  from coremltools.converters.mil.experimental.passes.generic_pass_infrastructure import fuse_all_blocks
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import get_new_symbol
  from coremltools.converters.mil.mil.passes.graph_pass import AbstractGraphPass
  from coremltools.converters.mil.mil.passes.helper import _check_child_op_type, _check_var_scalar_value, _check_var_scalar_value_in_interval, block_context_manager
  from coremltools.converters.mil.mil.passes.pass_registry import register_pass
label_desc: Use image node_id 4 for calling the fuse_gelu_tanh_approximation obj's underlying member method code with example usage: obj.get_gelu_pattern1() and returns: gelu_to_detect_1, mul_3