class_docstr: A graph optimization pass on PyMIL to detect and fuse several variants of ``layer_norm`` or
  ``instance_norm``. Pattern 1 corresponds to either ``layer_norm`` or ``instance_norm``. Patterns 2-4
  are ``instance_norm``. Pattern 5 is ``layer_norm``. You can find these patterns in the methods for
  this class in the source code. To quickly view the source code, click the **[source]** button at
  the end of the class definition.
docstr: Check whether or not the ``reduction`` op satisfies following conditions:
  
          - Mode is expected.
          - Does not change rank (``keep_dims`` is ``True``).
          - The ``axes`` is known at compile time.
  
  Parameters
  ----------
  
  param reduce_op : ``reduce_op`` to check on.
  
  param mode : ``reduce`` mode
docstr_tok: ["Check","whether","or","not","the","``","reduction","``","op","satisfies","following","conditions",":","-","Mode","is","expected",".","-","Does","not","change","rank","(","``","keep_dims","``","is","``","True","``",")",".","-","The","``","axes","``","is","known","at","compile","time",".","Parameters","--","--","--","--","--","param","reduce_op",":","``","reduce_op","``","to","check","on",".","param","mode",":","``","reduce","``","mode"]
code: def _check_reduce_op(
      reduce_op: Operation, mode: str = "reduce_mean"
  ) -> bool:
      """
      Check whether or not the ``reduction`` op satisfies following conditions:
  
              - Mode is expected.
              - Does not change rank (``keep_dims`` is ``True``).
              - The ``axes`` is known at compile time.
  
      Parameters
      ----------
  
      param reduce_op : ``reduce_op`` to check on.
  
      param mode : ``reduce`` mode
  
      """
      if reduce_op is None:
          return False
      if reduce_op.op_type != mode:
          return False
      if reduce_op.keep_dims is None or reduce_op.keep_dims.val is None:
          return False
      if reduce_op.keep_dims.val is False:
          return False
      if reduce_op.axes is None or reduce_op.axes.val is None:
          return False
      return True
  
imports: from typing import List, Optional
  import numpy
  from coremltools import _logger
  from coremltools.converters.mil.mil import Block
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import Operation, Program, Var
  from coremltools.converters.mil.mil.passes.graph_pass import AbstractGraphPass
  from coremltools.converters.mil.mil.passes.helper import _check_no_output_connection, block_context_manager
  from coremltools.converters.mil.mil.passes.pass_registry import register_pass
label_desc: Use image node_id 2 for calling the fuse_layernorm_or_instancenorm obj's underlying member method code with example usage: obj._check_reduce_op(reduce_op, mode) and returns: True, False, False, False, False, False