code: def testNBit(self, bit_rate):
      # uncomment for debugging
      # np.random.seed(0)
      net = core.Net("bench")
      batchsize = np.random.randint(2, 1000)
      assert 8 % bit_rate == 0
      num_elem_per_byte = 8 // bit_rate
      blocksize = np.random.randint(2, 500) * num_elem_per_byte
      input_data = np.random.rand(batchsize, blocksize).astype(
          np.float32
      )
  
      op = core.CreateOperator(
          "FloatToFused" + str(bit_rate) + "BitRowwiseQuantized",
          "input_data",
          "minmax_quantized_data",
      )
      net.Proto().op.extend([op])
      op = core.CreateOperator(
          "Fused" + str(bit_rate) + "BitRowwiseQuantizedToFloat",
          "minmax_quantized_data",
          "minmax_dequantized_data",
      )
      net.Proto().op.extend([op])
      op = core.CreateOperator(
          "FloatToFused" + str(bit_rate) + "BitRowwiseQuantized",
          "input_data",
          "greedy_quantized_data",
          engine="GREEDY",
      )
      net.Proto().op.extend([op])
      op = core.CreateOperator(
          "Fused" + str(bit_rate) + "BitRowwiseQuantizedToFloat",
          "greedy_quantized_data",
          "greedy_dequantized_data",
      )
      net.Proto().op.extend([op])
      workspace.FeedBlob("input_data", input_data)
  
      workspace.GlobalInit(["caffe2", "--caffe2_log_level=0"])
      workspace.RunNetOnce(net)
  
      minmax_dequantized_data = workspace.FetchBlob(
          "minmax_dequantized_data"
      )
      greedy_dequantized_data = workspace.FetchBlob(
          "greedy_dequantized_data"
      )
  
      diff_minmax = np.abs(input_data - minmax_dequantized_data)
      l2_minmax = np.linalg.norm(
          input_data - minmax_dequantized_data, axis=1
      )
      diff_greedy = np.abs(input_data - greedy_dequantized_data)
      l2_greedy = np.linalg.norm(
          input_data - greedy_dequantized_data, axis=1
      )
  
      for i in range(input_data.shape[0]):
          # Compare with Python reference greedy search implementation
          xmin, xmax = param_search_greedy(
              input_data[i, :], bit_rate, n_bins=200, ratio=0.16
          )
          X_q_ref, l2_greedy_ref = _compress_uniform_simplified(
              input_data[i, :],
              bit_rate,
              xmin,
              xmax,
              fp16_scale_bias=True,
          )
          l2_discrepancy = (
              np.abs(l2_greedy[i] - l2_greedy_ref) / input_data.shape[1]
          )
          # C++ implementation has a different accumulation order when
          # computing norm in compress_uniform_simplified_ so we shouldn't
          # use too small tolerance.
          assert (
              l2_discrepancy < 1e-5
          ), "l2_discrepancy between C++ and Python greedy algorithm {} at row {} is too high (actual l2 err {} ref l2 err {} actual {} ref {})".format(  # noqa
              l2_discrepancy,
              i,
              l2_greedy[i],
              l2_greedy_ref,
              greedy_dequantized_data[i, :],
              X_q_ref,
          )
  
          # Check error from greedy quantization is smaller than minmax quantization
          # Multiply by a margin 1.03 to consider inexactness of
          # floating-point operations and from binning (in exact math,
          # l2_greedy should be no less than l2_minmax).
          assert (
              l2_greedy[i] <= l2_minmax[i] * 1.03
          ), "L2 quantization error using greedy algorithm {} at row {} is bigger than error using minmax {}".format(
              l2_greedy[i], i, l2_minmax[i]
          )
  
imports: import math
  import struct
  import caffe2.python.hypothesis_test_util
  import hypothesis.strategies
  import numpy
  from caffe2.python import core, workspace
  from caffe2.python.operator_test.fused_nbit_rowwise_test_helper import _compress_uniform_simplified, param_search_greedy
  from hypothesis import assume, given, settings
label_desc: Use image node_id 1 for calling the TestNBitGreedyFused obj's underlying member method code with example usage: obj.testNBit(bit_rate) without return types