code: def test_fused_ln_quantize(
      self, seed, batch_size, size, epsilon, elementwise_affine
  ):
      np.random.seed(seed)
  
      # Reset the workspace
      workspace.ResetWorkspace()
      axis = 1
  
      dims = np.array(([batch_size, size]))
      X = np.random.uniform(size=dims).astype(np.float32) - 0.5
      gamma = np.random.randn(*X.shape[axis:]).astype(np.float32)
      beta = np.random.randn(*X.shape[axis:]).astype(np.float32)
  
      Y = self._layernorm_transform(X)
      scale, zp = self._get_scale_zp(Y)
  
      pred_net = caffe2_pb2.NetDef()
      pred_net.name = "pred"
      pred_net.external_input.extend(["X", "gamma", "beta"])
      pred_net.external_output.extend(["Y_q"])
      pred_net.op.add().CopyFrom(
          core.CreateOperator(
              "LayerNorm",
              ["X", "gamma", "beta"] if elementwise_affine else ["X"],
              ["Y", "mean", "rstd"],
              axis=axis,
              epsilon=epsilon,
              elementwise_affine=elementwise_affine,
          )
      )
      pred_net.op.add().CopyFrom(
          core.CreateOperator(
              "Int8Quantize",
              ["Y"],
              ["Y_q"],
              Y_scale=scale,
              Y_zero_point=zp,
          )
      )
  
      print(pred_net)
      pred_net_ref = caffe2_pb2.NetDef()
      pred_net_ref.name = "pred_ref"
      pred_net_ref.external_input.extend(["X", "gamma", "beta"])
      pred_net_ref.external_output.extend(["Y_q"])
      pred_net_ref.op.add().CopyFrom(
          core.CreateOperator(
              "LayerNormInt8QuantizeFakeNNPI",
              ["X", "gamma", "beta"] if elementwise_affine else ["X"],
              ["Y_q", "mean", "rstd"],
              axis=axis,
              epsilon=epsilon,
              elementwise_affine=elementwise_affine,
              Y_scale=scale,
              Y_zero_point=zp,
          )
      )
      shape_hits = {
          "X": X.shape,
          "gamma": gamma.shape,
          "beta": beta.shape,
      }
      pred_net_onnxified = onnxifi_caffe2_net(
          pred_net,
          shape_hits,
          debug=True,
          adjust_batch=True,
          use_onnx=False,
      )
      num_onnxified_ops = sum(
          1 if o.type == "Onnxifi" else 0 for o in pred_net_onnxified.op
      )
      np.testing.assert_equal(num_onnxified_ops, 1)
  
      workspace.FeedBlob("X", X)
      workspace.FeedBlob("gamma", gamma)
      workspace.FeedBlob("beta", beta)
  
      workspace.CreateNet(pred_net_ref)
      workspace.CreateNet(pred_net_onnxified)
  
      workspace.RunNet(pred_net_ref.name)
      Y_c2 = workspace.FetchInt8Blob("Y_q")
  
      workspace.RunNet(pred_net_onnxified.name)
      Y_glow = workspace.FetchInt8Blob("Y_q")
  
      if (
          not np.allclose(Y_glow.data, Y_c2.data)
          or Y_glow.scale != Y_c2.scale
          or Y_glow.zero_point != Y_c2.zero_point
      ):
          diff_Y = np.abs(
              Y_glow.data.astype(np.float32)
              - Y_c2.data.astype(np.float32)
          )
          print_test_debug_info(
              "layernorm",
              {
                  "seed": seed,
                  "size": size,
                  "batch_size": batch_size,
                  "epsilon": epsilon,
                  "gamma": gamma,
                  "beta": beta,
                  "elementwise_affine": elementwise_affine,
                  "X": X,
                  "Y_glow": Y_glow,
                  "Y_c2": Y_c2,
                  "diff_Y": diff_Y,
              },
          )
          assert 0
  
file_path: pytorch/caffe2/contrib/fakelowp/test/test_layernorm_nnpi_fp16.py
imports: import numpy
  import caffe2.python.fakelowp.init_shared_libs
  from caffe2.proto import caffe2_pb2
  from caffe2.python import core
  from caffe2.python import workspace
  from caffe2.python.onnx.onnxifi import onnxifi_caffe2_net
  from caffe2.python.fakelowp.test_utils import print_test_debug_info
  from hypothesis import given, settings
  from hypothesis import strategies
  import caffe2.python.serialized_test.serialized_test_util
  import datetime
label_desc: Use image node_id 4 for calling the LayerNorm obj's underlying member method code with example usage: obj.test_fused_ln_quantize(seed, batch_size, size, epsilon, elementwise_affine) without return types