class_docstr: A callback to rewrite the following operators into a single layer normalization operator.
  
  Pattern #1:
  1   %4 = mean(%3, axis=[-1], keepdims=True) /* ty=Tensor[(1, 3136, 1), float32] */;
  2   %5 = subtract(%3, %4) /* ty=Tensor[(1, 3136, 64), float32] */;
  3   %6 = cast(%5, dtype="float32") /* ty=Tensor[(1, 3136, 64), float32] */;
  4   %7 = power(%6, 2f /* ty=float32 */) /* ty=Tensor[(1, 3136, 64), float32] */;
  5   %8 = mean(%7, axis=[-1], keepdims=True) /* ty=Tensor[(1, 3136, 1), float32] */;
  6   %9 = add(%8, 1e-05f /* ty=float32 */) /* ty=Tensor[(1, 3136, 1), float32] */;
  7   %10 = sqrt(%9) /* ty=Tensor[(1, 3136, 1), float32] */;
  8   %11 = divide(%5, %10) /* ty=Tensor[(1, 3136, 64), float32] */;
  9   %12 = multiply(%11, meta[relay.Constant][2] /* ty=Tensor[(64), float32] */)
          /* ty=Tensor[(1, 3136, 64), float32] */;
  10   %13 = add(%12, meta[relay.Constant][3] /* ty=Tensor[(64), float32] */)
          /* ty=Tensor[(1, 3136, 64), float32] */;
  
  Pattern #2:
  1   %0 = mean(%input, axis=[-1], keepdims=True);
  2   %1 = variance(%input, %0, axis=[-1], keepdims=True);
  3   %2 = add(%1, 1e-05f /* ty=float32 */) /* ty=Tensor[(1, 49, 1), float32] */;
  4   %3 = subtract(%input, %0);
  5   %4 = sqrt(%2) /* ty=Tensor[(1, 49, 1), float32] */;
  6   %5 = divide(%3, %4);
  7   %6 = multiply(%5, meta[relay.Constant][0] /* ty=Tensor[(64), float32] */)
          /* ty=Tensor[(1, 49, 64), float32] */;
  8   %7 = add(%6, meta[relay.Constant][1] /* ty=Tensor[(64), float32] */)
          /* ty=Tensor[(1, 49, 64), float32] */
class_docstr_tok: ["A","callback","to","rewrite","the","following","operators","into","a","single","layer","normalization","operator",".","Pattern","#","1",":","1","%","4","=","mean","(","%","3",",","axis=","[","-1","]",",","keepdims=True",")","\/","*","ty=Tensor","[","(","1",",","3136",",","1",")",",","float32","]","*","\/",";","2","%","5","=","subtract","(","%","3",",","%","4",")","\/","*","ty=Tensor","[","(","1",",","3136",",","64",")",",","float32","]","*","\/",";","3","%","6","=","cast","(","%","5",",","dtype=","''","float32","''",")","\/","*","ty=Tensor","[","(","1",",","3136",",","64",")",",","float32","]","*","\/",";","4","%","7","=","power","(","%","6",",","2f","\/","*","ty=float32","*","\/",")","\/","*","ty=Tensor","[","(","1",",","3136",",","64",")",",","float32","]","*","\/",";","5","%","8","=","mean","(","%","7",",","axis=","[","-1","]",",","keepdims=True",")","\/","*","ty=Tensor","[","(","1",",","3136",",","1",")",",","float32","]","*","\/",";","6","%","9","=","add","(","%","8",",","1e-05f","\/","*","ty=float32","*","\/",")","\/","*","ty=Tensor","[","(","1",",","3136",",","1",")",",","float32","]","*","\/",";","7","%","10","=","sqrt","(","%","9",")","\/","*","ty=Tensor","[","(","1",",","3136",",","1",")",",","float32","]","*","\/",";","8","%","11","=","divide","(","%","5",",","%","10",")","\/","*","ty=Tensor","[","(","1",",","3136",",","64",")",",","float32","]","*","\/",";","9","%","12","=","multiply","(","%","11",",","meta","[","relay.Constant","]","[","2","]","\/","*","ty=Tensor","[","(","64",")",",","float32","]","*","\/",")","\/","*","ty=Tensor","[","(","1",",","3136",",","64",")",",","float32","]","*","\/",";","10","%","13","=","add","(","%","12",",","meta","[","relay.Constant","]","[","3","]","\/","*","ty=Tensor","[","(","64",")",",","float32","]","*","\/",")","\/","*","ty=Tensor","[","(","1",",","3136",",","64",")",",","float32","]","*","\/",";","Pattern","#","2",":","1","%","0","=","mean","(","%","input",",","axis=","[","-1","]",",","keepdims=True",")",";","2","%","1","=","variance","(","%","input",",","%","0",",","axis=","[","-1","]",",","keepdims=True",")",";","3","%","2","=","add","(","%","1",",","1e-05f","\/","*","ty=float32","*","\/",")","\/","*","ty=Tensor","[","(","1",",","49",",","1",")",",","float32","]","*","\/",";","4","%","3","=","subtract","(","%","input",",","%","0",")",";","5","%","4","=","sqrt","(","%","2",")","\/","*","ty=Tensor","[","(","1",",","49",",","1",")",",","float32","]","*","\/",";","6","%","5","=","divide","(","%","3",",","%","4",")",";","7","%","6","=","multiply","(","%","5",",","meta","[","relay.Constant","]","[","0","]","\/","*","ty=Tensor","[","(","64",")",",","float32","]","*","\/",")","\/","*","ty=Tensor","[","(","1",",","49",",","64",")",",","float32","]","*","\/",";","8","%","7","=","add","(","%","6",",","meta","[","relay.Constant","]","[","1","]","\/","*","ty=Tensor","[","(","64",")",",","float32","]","*","\/",")","\/","*","ty=Tensor","[","(","1",",","49",",","64",")",",","float32","]","*","\/"]
code: def __init__(self):
      super(LayerNormRewrite, self).__init__()
      self.data = wildcard()
      self.gamma = wildcard()
      self.beta = wildcard()
      mu = is_op("mean")(self.data)
      diff = is_op("subtract")(self.data, mu)
      cdiff = diff | is_op("cast")(diff)
      const_two = is_expr(relay.const(2)) | is_expr(relay.const(2.0))
      p1 = is_op("power")(cdiff, const_two)
      mp1 = is_op("mean")(p1) | is_op("variance")(self.data, mu)
      eps = is_expr(relay.const(1e-5)) | is_expr(relay.const(1e-6))
      added_eps = is_op("add")(mp1, eps)
      deno = is_op("sqrt")(added_eps)
      div_out = is_op("divide")(diff, deno)
      div_out2 = diff * is_op("rsqrt")(added_eps)
      weighted = is_op("multiply")(div_out | div_out2, self.gamma)
      added_bias = is_op("add")(weighted, self.beta)
      self.pattern = added_bias
  
imports: import logging
  from functools import reduce
  import tvm.ir
  from tvm import relay
  from tvm.ir import Op
  from tvm.relay import expr
  from tvm.relay import transform
  from tvm.relay.analysis import analysis
  from tvm.relay.expr import Call, GlobalVar, TupleGetItem, const
  from tvm.relay.expr_functor import ExprMutator, ExprVisitor
  from ...None import _ffi_api
  from ...dataflow_pattern import DFPatternCallback, is_constant, is_expr, is_op, rewrite, wildcard
  from .register import register_pattern_table
label_desc: Use image node_id 1 to create a new LayerNormRewrite object from inherited base classes: DFPatternCallback with example: obj = LayerNormRewrite()